Repository navigation
capstone 5.0.9: SH, M68K and MCInst security backports - #1637
Conversation
No 5.0.10 is released; these fixes are on capstone's v5 branch or next only. - CVE-2026-55893 / CVE-2026-55894 (SH operand write / decode[] read out of bounds): verbatim v5 backport e17ee44a (#2969). - GHSA-5q63-4654-94v6 (SH failed 32-bit decode falls through, SH_printInst reads operands[3]): the two-line `else return MCDisassembler_Fail;` from next's de4b58b2, ported to v5. Required with e17ee44a: that backport alone turns opFMOVm's `op_count = 2` into increments and makes this read reachable on 5.0.9, which stock 5.0.9 is not. - CVE-2026-49282, M68K half (M68K_insn_name off-by-one): next's 7441aee2, library hunk only. v5's RISCV_insn_name is already correct. - GHSA-8qp8-2vg2-8mr4, TMS320C64x half: v5's cc6f8e07 (memset MCInst on init) makes DecodeCrosspathX3's unwritten Operands[2].Kind kInvalid. build.sh runs cve-regress.c against an ASan build of SH/M68K/RISCV and against the shipped .so; a standalone test checks the installed library. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reached
This review includes 7 billable files and costs up to $1.75.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 50 minutes for your next included review. View limit details
|
There was a problem hiding this comment.
Scope matches the title. Every hunk is a patch file, its Local entry, the patch build dependency, or a test for the backports. Clobber none: git log on packages/capstone shows only the test_deps change from #1404, and the diff keeps it for the existing tests. Correctness the packaging follows the packages/alsa-lib precedent line for line: patch -Np1 under set -e, a scratch ASan build, and ASAN_OPTIONS=detect_leaks=0:abort_on_error=0. The ASan scratch build and build/cve-regress are written after cmake --install and outside $OUTPUT_DIR, so the shipped outputs do not change. The Nickel multiline string in security_backports contains no %{ and no "% sequence. The two findings are nits. Not checked: the sandbox denied the download of upstream capstone, so I did not compare the four patches with commits e17ee44a, de4b58b2, 7441aee2 and cc6f8e07. I also did not read the 5.0.9 callers of MCInst_Init to confirm that no caller sets csh or flat_insn before the new memset. The existing disassembles test exercises x86, ARM, AArch64, RISCV and PPC through that path. GHSA-8qp8-2vg2-8mr4 has no regression test. The PR body states this and gives the reason (an uninitialised read that only MSan detects), and I accept it. No build was run.
| security_backports = | ||
| { | ||
| class = 'Standalone, | ||
| test_deps = [base, toolchain], |
There was a problem hiding this comment.
nit · The new test puts base back into test_deps. #1404 (a39e112) removed base from the other tests in this file, so that the test closure does not mask undeclared runtime libraries. The script calls only cat, gcc and grep. This file already imports bash-bootstrap, coreutils and grep, and most compile-in-test siblings use [bash-bootstrap, toolchain] (abseil-cpp, boost, cairo). I did not run the test with the smaller closure.
| // | ||
| // Two kinds of input. | ||
| // | ||
| // sh-fallthrough-*: crafted here, and the ones that fail on stock 5.0.9. On |
There was a problem hiding this comment.
nit · This header says that the sh-fallthrough-* cases are the ones that fail on stock 5.0.9. The comment at build.ncl:37-38 says that ASan confirms both sinks on the stock tree with the reporters' inputs also. The security_backports comment says that the SH checks, which use the reporter's CVE-2026-55893 input, fail on stock. State in one place which cases fail on stock 5.0.9, and make the other comments agree.
capstone 5.0.9 is still the latest v5 release (the only newer tags are 6.0.0 alphas). The fixes below are only on the
v5branch or onnext, so this PR carries them as patches. build.sh applies them withpatch -Np1, which fails the build if a hunk is rejected.set_reg_nheap write past the 3-entryoperands[]decode[]table read out of boundsdecode_long()falls through andSH_printInstreadsoperands[3]else return MCDisassembler_Fail;M68K_insn_namechecksid > ARR_SIZEwhere it should check>=DecodeCrosspathX3readsOperands[2].Kindbefore anything initialises itNotes for review
op_count = 2into twoop_count++. That change makes the GHSA-5q63 read reachable, and stock 5.0.9 is not vulnerable to it: the 4-byte PoC passes ASan on stock and fails on 5.0.9 + e17ee44a. capstone'sv5branch HEAD is in exactly that state today.decode_long()fallthrough that the port closes. With the port applied, e17ee44a's bounds checks are defence in depth. Dropping e17ee44a while keeping the port left every case passing.CS_ASSERT_REThardening (v5 doesn't have that macro), a clang-format of theopRR()list, and edits totest_poc.c, a test file v5 doesn't have. The two lines carried are byte-identical to de4b58b2's; only the hunk offset differs. The patch header explains this.git format-patchlimited toarch/M68K/M68KInstPrinter.c. Its other hunk edits a unit test that v5 doesn't have. On v5, the RISCV half of CVE-2026-49282 is already fixed (id >= RISCV_INS_ENDING), and cve-regress.c checks that too.MCInst_Initonly initialisesOperands[0].DecodeCrosspathX3readsOperands[2].Kindand swapsRegValif it equalskRegister.Kind == kInvalid(0), so the branch is skipped.check_pop_return) is next-only code that v5 doesn't have.Tests
-fsanitize=address. It linkscve-regress.cagainst both that library and the shippedlibcapstone.so, then runs seven cases.30 09 f1 20for the operand write,30 09 80 00for the table read.security_backports: compiles a small program against the installed library. It checks that no instruction decoded from the 55893 and 5q63 reproducers reportsop_count > 3, and that the M68K/RISCV instruction names one past the table are NULL.Negative controls
Run locally with
min package build --rebuild --verboseon a freshmin session activateeach time. For these runs only, the case loop was changed to report every case instead of stopping at the first failure; the cases themselves were unchanged.set_reg_n(sh-fallthrough-oob-write, CVE-2026-55893 input), SEGV insh_disassembledecode[] read (sh-fallthrough-table-read, CVE-2026-55894 input), global-buffer-overflow inM68K_insn_name. GHSA-5q63 passes, as expected on stock. Standalonesecurity_backportsFail.SH_printInst, shipped lib reportsop_count 4 > 3M68KInstPrinter.c:368)min check --packages capstonepasses on every check, including standalone testsNot discriminating: without ASan, the one-past read of
s_instruction_namesreturned NULL on the test host. So the M68K half of the standalone test is a contract check, and the ASan run is what catches that regression.The local runs were on an arm64 sandbox. build-bot will cover x86_64.
🤖 Generated with Claude Code