[PATCH] D158425: [BPF] Check jump and memory offsets to avoid truncation

Eduard Zingerman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 21 07:59:59 PDT 2023


eddyz87 created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
eddyz87 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The following assembly code should issue two errors specifying that
both jump and load offsets are out of range:

  if r1 > r2 goto +100500
  r1 = *(u64 *)(r1 - 100500)

This commit updates BPFAsmParser to check that:

- offset specified for jump is either identifier (label) or a 16-bit signed constant;
- offset specified for memory operations is a signed 16-bit constant.

(Which matches expectations in the BPFELFObjectWriter and
 BPFMCCodeEmitter).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158425

Files:
  llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
  llvm/lib/Target/BPF/BPFInstrInfo.td
  llvm/test/MC/BPF/bad-offsets.s
  llvm/test/MC/BPF/expr-offset.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158425.552019.patch
Type: text/x-patch
Size: 4587 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230821/34d63c68/attachment.bin>


More information about the llvm-commits mailing list