8000 capstone 5.0.9: SH, M68K and MCInst security backports by bryan-minimal · Pull Request #1637 · gominimal/pkgs · GitHub
[go: up one dir, main page]

Skip to content

capstone 5.0.9: SH, M68K and MCInst security backports - #1637

Merged
bryan-minimal merged 1 commit into
mainfrom
capstone-509-security
Nov 23, 2026
Merged

bryan-minimal merged 1 commit into
mainfrom
capstone-509-security

Conversation

@bryan-minimal
Copy link
Copy Markdown
Member

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 v5 branch or on next, so this PR carries them as patches. build.sh applies them with patch -Np1, which fails the build if a hunk is rejected.

Advisory What Patch
CVE-2026-55893 (GHSA-3hpv-wr3j-rxwh) SH set_reg_n heap write past the 3-entry operands[] e17ee44a (v5 backport, PR #2969), verbatim
CVE-2026-55894 (GHSA-gf2c-xwcp-hvf4) SH decode[] table read out of bounds same commit
GHSA-5q63-4654-94v6 (no CVE) a failed SH2A decode_long() falls through and SH_printInst reads operands[3] port of next's de4b58b2: only its two-line else return MCDisassembler_Fail;
CVE-2026-49282 (GHSA-jrw4-wj52-2vw8), M68K half M68K_insn_name checks id > ARR_SIZE where it should check >= next's 7441aee2, library hunk only
GHSA-8qp8-2vg2-8mr4 (no CVE), TMS320C64x half DecodeCrosspathX3 reads Operands[2].Kind before anything initialises it v5's cc6f8e07 ("memset MCInst on init"), verbatim

Notes for review

  • e17ee44a must not ship without the decode_long port. e17ee44a changes opFMOVm's op_count = 2 into two op_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's v5 branch HEAD is in exactly that state today.
  • How the bugs are reached on 5.0.9. Both CVE-2026-55893/55894 sinks are reached through the same 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.
  • The rest of de4b58b2 is not carried. The remainder is CS_ASSERT_RET hardening (v5 doesn't have that macro), a clang-format of the opRR() list, and edits to test_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.
  • 7441aee2 is a git format-patch limited to arch/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.
  • GHSA-8qp8 / cc6f8e07: this is from reading the code, not from a test.
    • Stock MCInst_Init only initialises Operands[0]. DecodeCrosspathX3 reads Operands[2].Kind and swaps RegVal if it equals kRegister.
    • After the memset, an operand that was never written has Kind == kInvalid (0), so the branch is skipped.
    • The advisory's PoC isn't public (it's hosted on 4open.science), and the bug is an MSan-only uninitialised read with no observable output. Our toolchain is gcc, so there's no MSan. No regression test for this one.
    • The ARM half of that advisory (check_pop_return) is next-only code that v5 doesn't have.

Tests

  • Build time (build.sh): compiles a scratch static libcapstone with only SH, M68K and RISCV enabled, under -fsanitize=address. It links cve-regress.c against both that library and the shipped libcapstone.so, then runs seven cases.
    • Two cases use crafted SH2A inputs that hit each CVE sink through the fallthrough: 30 09 f1 20 for the operand write, 30 09 80 00 for the table read.
    • The other five are the reporters' and upstream's reproducers.
    • Nothing from the scratch build is installed.
  • Standalone security_backports: compiles a small program against the installed library. It checks that no instruction decoded from the 55893 and 5q63 reproducers reports op_count > 3, and that the M68K/RISCV instruction names one past the table are NULL.

Negative controls

Run locally with min package build --rebuild --verbose on a fresh min session activate each 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.

Variant Result
stock 5.0.9 (no patches) ASan: heap-buffer-overflow WRITE in set_reg_n (sh-fallthrough-oob-write, CVE-2026-55893 input), SEGV in sh_disassemble decode[] read (sh-fallthrough-table-read, CVE-2026-55894 input), global-buffer-overflow in M68K_insn_name. GHSA-5q63 passes, as expected on stock. Standalone security_backports Fail.
drop the decode_long port (keep e17ee44a) only GHSA-5q63 fails: heap-buffer-overflow READ in SH_printInst, shipped lib reports op_count 4 > 3
drop 7441aee2 only CVE-2026-49282-m68k fails (ASan global-buffer-overflow, M68KInstPrinter.c:368)
drop e17ee44a (keep the port) all cases pass: the port closes the only path to them
all patches all cases pass; min check --packages capstone passes on every check, including standalone tests

Not discriminating: without ASan, the one-past read of s_instruction_names returned 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

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>
@bryan-minimal
bryan-minimal requested a review from a team as a code owner November 23, 2026 01:47
@coderabbitai
coderabbitai Bot commented Nov 23, 2026
Copy link
Copy Markdown
Contributor

Warning

Review limit reached

  • Run on-demand review

This review includes 7 billable files and costs up to $1.75.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 63 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 06295b2 and d122a95.

Files selected for processing: 7

  • packages/capstone/CVE-2026-49282-m68k-insn-name.patch
  • packages/capstone/CVE-2026-55893-55894-sh-bounds.patch
  • packages/capstone/GHSA-5q63-4654-94v6-sh-decode-long.patch
  • packages/capstone/GHSA-8qp8-2vg2-8mr4-mcinst-memset.patch
  • packages/capstone/build.ncl
  • packages/capstone/build.sh
  • packages/capstone/cve-regress.c
  • Autofix · Keep fixing C 8000 odeRabbit findings and required CI, and resolving merge conflicts

@norrietaylor norrietaylor left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bryan-minimal
bryan-minimal added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit 0ed90d2 Nov 23, 2026
16 checks passed
@bryan-minimal
bryan-minimal deleted the capstone-509-security branch November 23, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0