arch-syscall-check: verify #ifdef __NR_ guards match __SNR_ define names#491
Open
rawrmonster17 wants to merge 1 commit into
Open
arch-syscall-check: verify #ifdef __NR_ guards match __SNR_ define names#491rawrmonster17 wants to merge 1 commit into
rawrmonster17 wants to merge 1 commit into
Conversation
The arch-syscall-check script already verifies that the set of syscall names in syscalls.csv matches the set of __SNR_ defines in seccomp-syscalls.h. However it does not verify that each '#ifdef __NR_<name>' guard immediately preceding a '#define __SNR_<name>' uses the same syscall name as the define it guards. A mismatch -- e.g. '#ifdef __NR_foo' guarding '#define __SNR_bar' -- means the define will silently resolve to __PNR_bar (not present) even when __NR_foo is defined by the kernel headers, rendering the syscall unreachable through libseccomp on any arch that has it. Add check_snr_ifdef() which reads seccomp-syscalls.h line by line and reports any '#ifdef __NR_<X>' / '#define __SNR_<Y>' pairing where X and Y differ. Any other preprocessor directive between the #ifdef and the matching #define resets the pending guard name (handles the unconditional '#define __SNR_x __NR_x' form, which carries no #ifdef and needs no cross-check). The exit code from check_snr_ifdef() is accumulated into the script's overall return code alongside the existing check_snr() and check_pnr() checks, so a guard mismatch will fail the 'arch-syscall-check' test that runs as part of 'make check'. Fixes: Github Issue seccomp#315 Signed-off-by: rawrmonster17 <rawrmonster17@users.noreply.github.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.
Problem
src/arch-syscall-checkalready verifies that the set of syscall names insyscalls.csvmatches the set of__SNR_defines inseccomp-syscalls.h.However it does not verify that each
#ifdef __NR_<name>guard immediatelypreceding a
#define __SNR_<name>uses the same syscall name as thedefine it guards.
A mismatch — e.g.
#ifdef __NR_fooguarding#define __SNR_bar— means thedefine will silently resolve to
__PNR_bar(not present) even when__NR_foois defined by the kernel headers. The existing name-set diff (using
sort -u)would not catch this because both names appear in the header; only the pairing
is wrong.
Fixes: Github Issue #315
Fix
Add
check_snr_ifdef()tosrc/arch-syscall-check. The function readsseccomp-syscalls.hline by line and reports any#ifdef __NR_<X>/#define __SNR_<Y>pairing where X ≠ Y, along with the file and line number.Any other preprocessor directive between an
#ifdefand the expected#define(including unconditional defines that carry no#ifdefguard)resets the pending guard name so only genuine guarded pairs are checked.
The exit code from
check_snr_ifdef()is accumulated into the script'soverall return value alongside the existing
check_snr()andcheck_pnr()checks, so a guard mismatch fails the
arch-syscall-checktest that runsas part of
make check.Testing
seccomp-syscalls.h(all guards match).#ifdef __NR_accept_TYPOin place of#ifdef __NR_acceptproduces:
MISMATCH at …seccomp-syscalls.h:313: #ifdef __NR_accept_TYPO but #define __SNR_acceptand exits 1.
make checkpasses (PASS: arch-syscall-check, PASS: regression).