Skip to content

Commit 9972ffc

Browse files
committed
Fix eBPF compare-and-exchange instruction
Linux kernel's documentation tells in https://www.kernel.org/doc/html/v6.0/bpf/instruction-set.html#atomic-operations > The BPF_CMPXCHG operation atomically compares the value addressed by > dst_reg + off with R0. If they match, the value addressed by > dst_reg + off is replaced with src_reg. In either case, the value that > was at dst_reg + off before the operation is zero-extended and loaded > back to R0. If the values don't match, *(dst_reg + off) is not supposed to be modified. Fix the semantic of the compare-and-exchange instruction accordingly.
1 parent fbd2641 commit 9972ffc

File tree

1 file changed

+2
-0
lines changed
  • Ghidra/Processors/eBPF/data/languages

1 file changed

+2
-0
lines changed

Ghidra/Processors/eBPF/data/languages/eBPF.sinc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ DST4: dst is dst { local tmp:4 = dst:4; export tmp; }
371371
local tmp:4 = *:4 (dst + off);
372372
if (R0:4 == tmp) goto <equal>;
373373
R0 = zext(tmp);
374+
goto inst_next;
374375
<equal>
375376
*:4 (dst + off) = src:4;
376377
}
@@ -379,6 +380,7 @@ DST4: dst is dst { local tmp:4 = dst:4; export tmp; }
379380
local tmp:8 = *:8 (dst + off);
380381
if (R0 == tmp) goto <equal>;
381382
R0 = tmp;
383+
goto inst_next;
382384
<equal>
383385
*:8 (dst + off) = src;
384386
}

0 commit comments

Comments
 (0)