Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

turns x86 endbr instructions into nops by default #1530

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions plugins/x86/x86_endbr.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
open Core_kernel[@@warning "-D"]
open Bap_main
open Bap.Std
open X86_asm.Reg

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

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

let lift _mem _insn = Ok [ Bil.(encode intrinsic "endbr")]
let lift enabled _mem _insn =
if enabled then Ok [Bil.(encode intrinsic "endbr") ]
else Ok []

let enabled = Extension.Configuration.flag "cet-enabled"
~aliases:["endbr-enabled"]
~doc:"When enabled, translate all endbr instruction into \
intrinsic calls. Otherwise treat them as nops"

let () =
Bap_main.Extension.declare @@ fun _ctxt ->
Extension.declare @@ fun ctxt ->
let lift = lift @@ Extension.Configuration.get ctxt enabled in
let name op = sexp_of_endbr op |> Sexp.to_string in
List.iter all_of_endbr ~f:(fun op -> IA32.register (name op) lift);
List.iter all_of_endbr ~f:(fun op -> AMD64.register (name op) lift);
Expand Down