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
[BOLT] Add validation for direct call/branch targets (#165406)
In some edge cases, a binary may contain direct `branch` or `call`
instructions whose target do not point to a valid executable
instruction. This can occur due to compiler bugs, hand-written assembly,
obfuscation technique, **or when control flow targets a data by
mistake.**
We also encountered the problems as described in this
[issue](#149382), where "data
in code" within OpenSSL's hand-written assembly was misidentified as
instructions(island identification seems fail due to the absence of a
corresponding data symbol). The problem occurred because a data sequence
was incorrectly disassembled as a "jb" instruction.
The point here is that the data should not be pointed to by any edge, so
this patch tries to address this by validating the destination address
for **direct branches and calls**. If the target instruction is
invalid(implies a corrupted control flow), this function will be set
ignored.
Although this approach appears helpful for addressing the 'data in code'
problem, its validation might be compromised if the data can be
disassembled as normal instruction.
# CHECK-TARGETS: BOLT-WARNING: corrupted control flow detected in function external_corrupt: an external branch/call targets an invalid instruction in function external_func at address 0x{{[0-9a-f]+}}; ignoring both functions
11
+
# CHECK-TARGETS: BOLT-WARNING: corrupted control flow detected in function internal_corrupt: an internal branch/call targets an invalid instruction at address 0x{{[0-9a-f]+}}; ignoring this function
12
+
13
+
14
+
.globl internal_corrupt
15
+
.type internal_corrupt,@function
16
+
internal_corrupt:
17
+
b constant_island_0 // targeting the data in code
18
+
constant_island_0:
19
+
.word0xffffffff
20
+
.size internal_corrupt,.-internal_corrupt
21
+
22
+
23
+
.globl external_corrupt
24
+
.type external_corrupt,@function
25
+
external_corrupt:
26
+
b constant_island_1 // targeting the data in code externally
# CHECK-TARGETS: BOLT-WARNING: corrupted control flow detected in function external_corrupt: an external branch/call targets an invalid instruction in function external_func at address 0x{{[0-9a-f]+}}; ignoring both functions
11
+
# CHECK-TARGETS: BOLT-WARNING: corrupted control flow detected in function internal_corrupt: an internal branch/call targets an invalid instruction at address 0x{{[0-9a-f]+}}; ignoring this function
12
+
13
+
14
+
.globl internal_corrupt
15
+
.type internal_corrupt,@function
16
+
internal_corrupt:
17
+
jb data_in_code + 1# targeting the data in code, and jump into the middle of 'xorb' instruction
18
+
data_in_code:
19
+
.byte0x34, 0x01# data in code, will be disassembled as 'xorb 0x1, %al'
20
+
.size internal_corrupt,.-internal_corrupt
21
+
22
+
23
+
.globl external_corrupt
24
+
.type external_corrupt,@function
25
+
external_corrupt:
26
+
jb external_func + 1# targeting the middle of normal instruction externally
0 commit comments