This is an archive of the discontinued LLVM Phabricator instance.

[BPF] Return fail if disassembled insn registers out of range
ClosedPublic

Authored by yonghong-song on May 18 2020, 1:41 PM.

Details

Reviewers
ast
Summary

Daniel reported a llvm-objdump segfault like below:

$ llvm-objdump -D bpf_xdp.o
...
0000000000000000 <.strtab>:
     0:       00 63 69 6c 69 75 6d 5f <unknown>
     1:       6c 62 36 5f 61 66 66 69 w2 <<= w6
...
(llvm-objdump: lib/Target/BPF/BPFGenAsmWriter.inc:1087: static const char*
 llvm::BPFInstPrinter::getRegisterName(unsigned int): Assertion
 `RegNo && RegNo < 25 && "Invalid register number!"' failed.
 Stack dump:
 0.      Program arguments: llvm-objdump -D bpf_xdp.o
  ...
  abort
  ...
  llvm::BPFInstPrinter::getRegisterName(unsigned int)
  llvm::BPFInstPrinter::printMemOperand(llvm::MCInst const*,
                        int, llvm::raw_ostream&, char const*)
  llvm::BPFInstPrinter::printInstruction(llvm::MCInst const*,
                        unsigned long, llvm::raw_ostream&)
  llvm::BPFInstPrinter::printInst(llvm::MCInst const*,
                        unsigned long, llvm::StringRef, llvm::MCSubtargetInfo const&,
                        llvm::raw_ostream&)
 ...

Basically, since -D enables disassembly for all sections, .strtab is also disassembled,
but some strings are decoded as legal instructions but with illegal register numbers.
When llvm-objdump tries to print register name for these illegal register numbers,
assertion and segfault happens.

The patch fixed the issue by returning fail for a disassembled insn if
that insn contain a reg operand with illegal reg number.
The insn will be printed as "<unknown>" instead of causing an assertion.

Diff Detail

Event Timeline

yonghong-song created this revision.May 18 2020, 1:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 18 2020, 1:41 PM
ast accepted this revision.May 18 2020, 2:26 PM
This revision is now accepted and ready to land.May 18 2020, 2:26 PM
yonghong-song closed this revision.May 22 2020, 5:07 PM