Skip to content

Commit 411c733

Browse files
authored
turns x86 endbr instructions into nops by default (#1530)
They could be enabled with the `--x86-cet-enabled` command-line option, but by default there's no need to have them as calls everythere.
1 parent 02c953b commit 411c733

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

plugins/x86/x86_endbr.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
open Core_kernel[@@warning "-D"]
2+
open Bap_main
23
open Bap.Std
34
open X86_asm.Reg
45

@@ -7,10 +8,18 @@ module AMD64 = X86_backend.AMD64
78

89
type endbr = [ `ENDBR32 | `ENDBR64 ] [@@deriving bin_io, sexp, compare, enumerate]
910

10-
let lift _mem _insn = Ok [ Bil.(encode intrinsic "endbr")]
11+
let lift enabled _mem _insn =
12+
if enabled then Ok [Bil.(encode intrinsic "endbr") ]
13+
else Ok []
14+
15+
let enabled = Extension.Configuration.flag "cet-enabled"
16+
~aliases:["endbr-enabled"]
17+
~doc:"When enabled, translate all endbr instruction into \
18+
intrinsic calls. Otherwise treat them as nops"
1119

1220
let () =
13-
Bap_main.Extension.declare @@ fun _ctxt ->
21+
Extension.declare @@ fun ctxt ->
22+
let lift = lift @@ Extension.Configuration.get ctxt enabled in
1423
let name op = sexp_of_endbr op |> Sexp.to_string in
1524
List.iter all_of_endbr ~f:(fun op -> IA32.register (name op) lift);
1625
List.iter all_of_endbr ~f:(fun op -> AMD64.register (name op) lift);

0 commit comments

Comments
 (0)