CWE

普遍的弱点

A Community-Developed List of Software & Hardware Weakness Types

2021 CWE最重要的硬件弱点
CWE前25个最危险的弱点
>CWE列表>CWE- Individual Dictionary Definition (4.10)
ID

CWE-831: Signal Handler Function Associated with Multiple Signals

弱点ID:831
抽象:根据
结构:简单的
查看自定义信息:
+描述
该产品定义一个用作多个信号处理程序的函数。
+扩展描述

While sometimes intentional and safe, when the same function is used to handle multiple signals, a race condition could occur if the function uses any state outside of its local declaration, such as global variables or non-reentrant functions, or has any side effects.

An attacker could send one signal that invokes the handler function; in many OSes, this will typically prevent the same signal from invoking the handler again, at least until the handler function has completed execution. However, the attacker could then send a different signal that is associated with the same handler function. This could interrupt the original handler function while it is still executing. If there is shared state, then the state could be corrupted. This can lead to a variety of potential consequences depending on context, including denial of service and code execution.

Another rarely-explored possibility arises when the signal handler is only designed to be executed once (if at all). By sending multiple signals, an attacker could invoke the function more than once. This may generate extra, unintended side effects. A race condition might not even be necessary; the attacker could send one signal, wait until it is handled, then send the other signal.

+关系
部分帮助该表显示了与该弱点相关的弱点和高级类别。这些关系定义为childof,parentof,ementof,并深入了解可能存在于较高和较低抽象水平的类似项目。此外,定义了诸如Peerof和Canalsobe之类的关系,以显示用户可能想要探索的类似弱点。
+与观点“研究概念”相关(CWE-1000)
自然 Type ID 姓名
Childof 根据根据- a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. 364 Signal Handler Race Condition
部分帮助该表显示了与该弱点相关的弱点和高级类别。这些关系定义为childof,parentof,ementof,并深入了解可能存在于较高和较低抽象水平的类似项目。此外,定义了诸如Peerof和Canalsobe之类的关系,以显示用户可能想要探索的类似弱点。
+Relevant to the view "Software Development" (CWE-699)
自然 Type ID 姓名
成员 CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 387 信号错误
+常见后果
部分帮助该表指定与弱点相关的不同个人后果。该范围确定了违反的应用程序安全区域,而影响描述了如果对手成功利用这一弱点,就会产生负面的技术影响。其可能性提供了有关预期相对于列表中其他后果的特定后果的可能性的信息。例如,可能会利用弱点来实现一定的影响,但很可能会利用它来实现不同的影响。
范围 Impact 可能性
Availability
Integrity
Confidentiality
访问控制
其他

技术影响:DOS:撞车,退出或重新启动;执行未经授权的代码或命令;阅读应用程序数据;获得特权或假定身份;旁路保护机制;随上下文而变化

最常见的后果将是产品状态的腐败,可能导致崩溃或退出。但是,如果信号处理程序正在以安全相关库或保护机制的状态变量进行操作,则后果可能会更加严重,包括保护机制绕过,特权升级或信息暴露。
+Demonstrative Examples

示例1

该代码用两个不同的信号注册相同的信号处理程序功能。

(不良代码)
示例语言:C
void处理程序(int signum){
...
}

int main(int argc,char* argv []){
信号(Sigusr1,处理程序)
信号(Sigusr2,处理程序)
}

示例2

该代码用两个不同的信号注册相同的信号处理程序功能(CWE-831)。如果将这些信号发送到该过程,则处理程序将创建一个日志消息(在第一个参数中指定为程序)并退出。

(不良代码)
示例语言:C
char *logmessage;

void处理程序(int signum){
syslog(log_notice,“%s \ n”,logmessage);
free(logMessage);
/* artificially increase the size of the timing window to make demonstration of this weakness easier. */

睡眠(10);
出口(0);
}

int main(int argc,char* argv []){
logMessage = strdup(argv [1]);
/* Register signal handlers. */

信号(叹气,处理程序);
signal(SIGTERM, handler);
/* artificially increase the size of the timing window to make demonstration of this weakness easier. */

睡眠(10);
}

处理程序函数使用全局状态(GlobalVar和LogMessage),并且可以通过Sighup和Sigment信号调用。攻击方案可能会遵循以下界限:

  • The program begins execution, initializes logMessage, and registers the signal handlers for SIGHUP and SIGTERM.
  • 该程序开始其“正常”功能,该功能被简化为Sleep(),但可能是任何会消耗一段时间的功能。
  • The attacker sends SIGHUP, which invokes handler (call this "SIGHUP-handler").
  • Sighup Handler开始执行,调用Syslog()。
  • syslog()呼叫malloc(),它是非诱饵的。malloc()开始修改元数据以管理堆。
  • The attacker then sends SIGTERM.
  • Sighup Handler被打断了,但是Syslog的Malloc电话仍在执行,尚未完成修改其元数据。
  • 调用Sigterm处理程序。
  • SIGTERM HANDLER使用Syslog()记录日志消息,然后释放LogMessage变量。

At this point, the state of the heap is uncertain, because malloc is still modifying the metadata for the heap; the metadata might be in an inconsistent state. The SIGTERM-handler call to free() is assuming that the metadata is inconsistent, possibly causing it to write data to the wrong location while managing the heap. The result is memory corruption, which could lead to a crash or even code execution, depending on the circumstances under which the code is running.

请注意,这是Michal Zalewski最初提出的经典示例的改编[Ref-360]; the original example was shown to be exploitable for code execution.

另请注意,strdup(argv [1])呼叫包含一个潜在的缓冲区过读(CWE-126) if the program is called without any arguments, because argc would be 0, and argv[1] would point outside the bounds of the array.

+References
[Ref-360] Michal Zalewski。“为了娱乐和利润提供信号”。<http://lcamt​​uf.coredump.cx/signals.txt>。
+内容历史记录
+Submissions
Submission Date 提交者 组织
2010-12-12 CWE内容团队 MITER
+修改
修改日期 Modifier 组织
2011-06-01 CWE内容团队 MITER
updated Common_Consequences
2011-06-27 CWE内容团队 MITER
updated Common_Consequences
2014-06-23 CWE内容团队 MITER
更新的示范_examples,参考
2020-02-24 CWE内容团队 MITER
更新的关系
2023-01-31 CWE内容团队 MITER
updated Common_Consequences, Description
More information is available — Please select a different filter.
页面最后更新:2023年1月31日