You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: cpp/src/security/AsyncUnsafeSignalHandler/AsyncUnsafeSignalHandler.qhelp
+23-2Lines changed: 23 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -7,27 +7,48 @@
7
7
This is a CodeQL query constructed to find signal handlers that are performing async unsafe operations.
8
8
</p>
9
9
10
+
<p>
11
+
Because a signal may be delivered at any moment, e.g., in the middle of a malloc, the handler shouldn't touch
12
+
the program's internal state.
13
+
</p>
14
+
10
15
<p>
11
16
The kernel defines a list of async-safe signal functions in its <ahref="https://man7.org/linux/man-pages/man7/signal-safety.7.html">man page</a>.
12
-
Any signal handler that performs operations that are not safe asynchronously may be vulnerable.
17
+
Any signal handler that performs operations that are not safe for asynchronous execution may be vulnerable.
18
+
</p>
19
+
20
+
<p>
21
+
Moreover, signal handlers may be re-entered. Handlers' logic should take that possibility into account.
22
+
</p>
23
+
24
+
<p>
25
+
If the issue is exploitable depends on attacker's ability to deliver the signal.
26
+
Remote attacks may be limitted to some signals (like SIGALRM and SIGURG), while local attacks could use all signals.
13
27
</p>
14
28
</overview>
15
29
16
30
<recommendation>
17
31
<p>
18
32
Attempt to keep signal handlers as simple as possible. Only call async-safe functions from signal handlers.
19
33
</p>
34
+
<p>
35
+
Block delivery of new signals inside signal handlers to prevent handler re-entrancy issues.
36
+
</p>
20
37
</recommendation>
21
38
22
39
<example>
23
40
<samplesrc="AsyncUnsafeSignalHandler.c" />
24
41
25
42
<p>
26
-
In this example, while both syntatically valid, a correct handler is defined in the <code>correct_handler</code> function and sets a flag. The function calls <code>log_message</code>, a async unsafe function, within the main loop.
43
+
In this example, while both syntatically valid, a correct handler is defined in the <code>correct_handler</code> function and sets a flag.
44
+
The function calls <code>log_message</code>, a async unsafe function, within the main loop.
27
45
</p>
28
46
</example>
29
47
30
48
<references>
49
+
<li>
50
+
<ahref="https://lcamtuf.coredump.cx/signals.txt">Michal Zalewski, "Delivering Signals for Fun and Profit"</a>
51
+
</li>
31
52
<li>
32
53
<ahref="https://wiki.sei.cmu.edu/confluence/display/c/SIG30-C.+Call+only+asynchronous-safe+functions+within+signal+handlers">SEI CERT C Coding Standard "SIG30-C. Call only asynchronous-safe functions within signal handlers"</a>
0 commit comments