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
[GS/pacret] Also recognize traps as non-returning control flow.
A substantial amount of remaining false positives in the pacret gadget
list generated is due to the analyzer not recognizing that brk
instructions stop the regular control flow.
An example reported gadget false positive is as follows:
GS-PACRET: non-protected ret found in function __BOLT_FDE_FUNCate3bb4, basic block .Ltmp12963, at address e3ca8
The return instruction is 000e3ca8: ret # pacret-gadget: pac-ret-gadget<Ret:MCInstBBRef<BB:.Ltmp12963:6>, Overwriting:[MCInstBBRef<BB:.Ltmp12963:1> ]>
The 1 instructions that write to the return register after any authentication are:
1. 000e3c94: bl xmalloc@PLT
This happens in the following basic block:
000e3c90: mov x0, #0x20
000e3c94: bl xmalloc@PLT
000e3c98: mov x1, #0x0
000e3c9c: str xzr, [x0, #0x18]
000e3ca0: ldr x0, [x1, #0x128]
000e3ca4: brk #0x3e8
000e3ca8: ret # pacret-gadget: pac-ret-gadget<Ret:MCInstBBRef<BB:.Ltmp12963:6>, Overwriting:[MCInstBBRef<BB:.Ltmp12963:1> ]>
These brk instructions are typically generated from __builtin_trap();
but might also be generated otherwise. It seems that at least gcc
understands that control flow cannot reach the point after the brk
instruction, and therefore does not generate the pac-ret authentication
instructions. For some reason though, the `ret` instruction is still
generated.
In order to not generate these false positives, BOLT needs to understand
that these "traps" end control flow; similar to as if a non-returning
function is called.
This commit implements this.
Comparing a scan of a well-populated /usr/lib64 directory on Fedora 39,
this reduce the number of reported pac-ret gadgets from 46021 to 19776 a
reduction with a factor of 2.32!
Also, the number of libraries with reported pac-ret gadgets against them
reduces from 521 to 137, a reduction with a factor 3.8!
0 commit comments