Repository navigation
codeql: the kernel job passes results a patch suppresses in its source (#707) - #737
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 kernelfails on twocpp/path-injectionresults. Both are on lines that kernel/patches/0015 adds toarch/x86/tools/relocs_common.c, thefopen(fname, "r+")andfopen(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, aspatched severealready does for Go.What
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.shared/util/codeql/util/suppression/AlertSuppression.qll(CodeQlSuppressionComment) matchescodeql[...]only in a comment that is the first thing on its line.coversapplies 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.git format-patch -Nfrom 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/cpp-queries:AlertSuppression.ql, as the Go analysis inownalready 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>).{"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.own's suppressed Go results.Severenow reads the samesuppressionsfield fromresultinstead of its own struct.Checked
"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 mutateaftergit fetch origin: lint OK, tests OK, mutate reports 82 mutants refused and 0 survived.spin-machine-dev build kernellocally: 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".🤖 Generated with Claude Code