Skip to content

Commit

Permalink
Add support for uninstrumented .text.trusted section
Browse files Browse the repository at this point in the history
  • Loading branch information
zyedidia committed Dec 12, 2024
1 parent d1f147a commit 3873bd2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lfi-leg/amd64/amd64.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,17 @@ amd64_rewrite(FILE* input, struct output* output)
if (passes[i].disabled)
continue;
struct op* op = ops;
bool trusted = false;
while (op) {
struct op* next = op->next;
passes[i].fn(op);
if (op->truststart)
trusted = true;
if (op->notruststart)
trusted = false;

if (!trusted)
passes[i].fn(op);

op = next;
}
}
Expand Down
13 changes: 13 additions & 0 deletions lfi-leg/amd64/parse.leg
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Top = Insn* !.

Insn = - Label? (
BundleDirective
| TrustedDirective
| UntrustedDirective
| Directive Comment?
| Comment
| AnyPrefix
Expand Down Expand Up @@ -46,6 +48,17 @@ FnDirective = < '.type' - ([^,])* ',' - [@%] 'function' - > {
mkdirective(bundle_align());
}

TrustedDirective = '.section' - '.text.trusted' rest:REMAINDER {
struct op* op = mkdirective(xasprintf(".section .text.trusted%s", rest.val));
op->truststart = true;
rfree(rest);
}

UntrustedDirective = < ('.text' | '.section') (!EOL .)* > {
struct op* op = mkdirective(strndup(yytext, yyleng));
op->notruststart = true;
}

PREFIX = < ('lock' | 'rep' | 'rex64' | 'rex') > [ \t\r\n;]+ {
$$ = (Result) { .val = strndup(yytext, yyleng) }
}
Expand Down
10 changes: 9 additions & 1 deletion lfi-leg/arm64/arm64.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,17 @@ arm64_rewrite(FILE* input, struct output* output)
if (passes[i].disabled)
continue;
struct op* op = ops;
bool trusted = false;
while (op) {
struct op* next = op->next;
passes[i].fn(op);
if (op->truststart)
trusted = true;
if (op->notruststart)
trusted = false;

if (!trusted)
passes[i].fn(op);

op = next;
}
}
Expand Down
13 changes: 13 additions & 0 deletions lfi-leg/arm64/parse.leg
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Top = Insn* !.
Insn = - Label? (
FnDirective Comment?
| BundleDirective Comment?
| TrustedDirective
| UntrustedDirective
| Directive Comment?
| Comment
| Any
Expand Down Expand Up @@ -44,6 +46,17 @@ FnDirective = < '.type' - ([^,])* ',' - [@%] 'function' - > {
// mkdirective(bundle_align());
}

TrustedDirective = '.section' - '.text.trusted' rest:REMAINDER {
struct op* op = mkdirective(xasprintf(".section .text.trusted%s", rest.val));
op->truststart = true;
rfree(rest);
}

UntrustedDirective = < ('.text' | '.section') (!EOL .)* > {
struct op* op = mkdirective(strndup(yytext, yyleng));
op->notruststart = true;
}

Directive = < '.' (!EOL .)* > - {
mkdirective(strndup(yytext, yyleng));
}
Expand Down
2 changes: 2 additions & 0 deletions lfi-leg/op.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ struct op {
char* replace;
char* target;
bool rmforward;
bool truststart;
bool notruststart;

struct op* next;
struct op* prev;
Expand Down

0 comments on commit 3873bd2

Please sign in to comment.