Skip to content

codeql: the kernel job passes results a patch suppresses in its source (#707) - #737

Merged
aledbf merged 2 commits into
mainfrom
ci/707-codeql-suppression
Nov 26, 2026
Merged

aledbf merged 2 commits into
mainfrom
ci/707-codeql-suppression

Conversation

@aledbf

@aledbf aledbf commented Nov 26, 2026

Copy link
Copy Markdown
Member

Why

CodeQL's daily run on main is red every day. This PR closes #707, the issue for that red run (#716 and #717 were its daily duplicates). spin-machine-dev patched scope kernel fails on two cpp/path-injection results. Both are on lines that kernel/patches/0015 adds to arch/x86/tools/relocs_common.c, the fopen(fname, "r+") and fopen(fname, "r") of the file named in argv. relocs is a host program that make runs on the vmlinux it just linked, so its argv comes from the build, never from an attacker. The alerts were dismissed in code scanning. The job reads the SARIF itself, so it stayed red anyway. Removing anything from the analysis was ruled out, and so was changing the code only to quiet the tool. What was chosen is an in-source suppression on the two lines, with the reason written in the comment, and a gate that honours suppressions, as patched severe already does for Go.

What

  • 0015. Each of the two fopen()s now has a /* codeql[cpp/path-injection] fname is the vmlinux make built, not input (#707) */ comment on the line before it. The two branches take braces. The patch header gets a [ spin-stack/machine: ... ] note that says why the comments are there.
    • The comment form comes from CodeQL's source. shared/util/codeql/util/suppression/AlertSuppression.qll (CodeQlSuppressionComment) matches codeql[...] only in a comment that is the first thing on its line. covers applies it to the line after the comment. cpp/ql/src/AlertSuppression.ql (SingleLineComment) accepts // and a one-line /* */. A comment at the end of the code line, or one that spans several lines, would not suppress anything.
    • The patch was remade with git format-patch -N from the pinned 7.4-rc4 tarball with the series applied (core.abbrev=9). The mbox From line is dropped. All 20 other patches come out byte for byte the same.
  • codeql.yml. The C/C++ analysis now also runs codeql/cpp-queries:AlertSuppression.ql, as the Go analysis in own already does. Without it the SARIF marks nothing suppressed. Nothing that was analysed before was removed.
  • patched scope. A result on an added line that the SARIF marks suppressed no longer fails the job. It is printed with (suppressed: <the comment>).
    • The SARIF suppression has no justification field ({"kind":"inSource"} in run 45724244695), so the reason is read from the line before the result in the patched source. That is the line CodeQL matched.
    • scoped.sarif keeps the suppressed result exactly as CodeQL wrote it, suppression included. Code scanning then shows it as closed, not open, the same way it shows own's suppressed Go results.
    • Unsuppressed results on added lines still fail the job. Upstream's results still go to upstream.txt.
    • Severe now reads the same suppressions field from result instead of its own struct.

Checked

  • CodeQL, dispatched on this branch at 84ebc41: https://github.com/spin-stack/machine/actions/runs/45726150538. Every job passes, the kernel job included. Its scope step prints:
    arch/x86/tools/relocs_common.c:74: cpp/path-injection: This argument to a file access function is derived from [user input (a command-line argument)](1) and then passed to fopen(__filename). (suppressed: /* codeql[cpp/path-injection] fname is the vmlinux make built, not input (#707) */)
    arch/x86/tools/relocs_common.c:77: cpp/path-injection: This argument to a file access function is derived from [user input (a command-line argument)](1) and then passed to fopen(__filename). (suppressed: /* codeql[cpp/path-injection] fname is the vmlinux make built, not input (#707) */)
    kernel: no unsuppressed result on a line the patches added
    
  • An earlier dispatch, with only the first commit (run 45724244695), had CodeQL mark both results "suppressions":[{"kind":"inSource"}] at relocs_common.c:74 and :77. The old scope still failed on them. That run settled the comment form before the gate change was written.
  • go tool task lint test mutate after git fetch origin: lint OK, tests OK, mutate reports 82 mutants refused and 0 survived.
  • spin-machine-dev build kernel locally: checkpatch for 0015 is clean, the build prints "kernel patches: each is in this vmlinux" and "sparse: the patches add no warning", and olddefconfig prints "No change to .config".
  • checkpatch.pl --strict on the new 0015, run outside a git tree: 0 errors, 0 warnings, 0 checks.

🤖 Generated with Claude Code

aledbf and others added 2 commits November 25, 2026 20:49
CodeQL's patched kernel analysis fails every day (#707) on two
cpp/path-injection results on 0015's fopen(fname, ...) in
arch/x86/tools/relocs_common.c. relocs is a host program make runs on
the vmlinux it just linked: its argv is the build's, never an
attacker's. A codeql[cpp/path-injection] comment on the line before
each says so.

CodeQL's alert suppression (shared/util/codeql/util/suppression/
AlertSuppression.qll, cpp/ql/src/AlertSuppression.ql) takes a
codeql[<rule>] comment that is the first thing on its line, a // or a
one-line /* */, and covers the line after it. So each comment is a
one-line /* */ on a line of its own, and the two branches take braces.
codeql.yml's C/C++ analysis now runs that query, as own's Go one does,
so the SARIF marks those results suppressed.

0015 is remade with git format-patch from the pinned tarball with the
series applied; every other patch is byte for byte what it was, and
0015 is checkpatch --strict clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With 0015's two comments, CodeQL marks its cpp/path-injection results
suppressed ("suppressions":[{"kind":"inSource"}], run 45724244695), and
scope still failed on them: it counted every result on an added line.
Now a suppressed one is printed with the comment that suppresses it, the
line before it, since the SARIF carries no justification, and does not
fail the job. scoped.sarif keeps it as CodeQL wrote it, suppression
included, so code scanning shows it closed and not open, as own's Go
results are.

Severe reads the same suppressions field off result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aledbf
aledbf merged commit 3c07424 into main Nov 26, 2026
22 checks passed
@aledbf
aledbf deleted the ci/707-codeql-suppression branch November 26, 2026 00:30
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.

codeql: cpp/path-injection on kernel 0015's relocs_common.c, a host build tool

1 participant