Skip to content

Fix big-endian byte order for 64-bit argument comparisons#44

Merged
robertswiecki merged 1 commit intogoogle:masterfrom
mohammadmseet-hue:fix-big-endian-arg-order
Apr 4, 2026
Merged

Fix big-endian byte order for 64-bit argument comparisons#44
robertswiecki merged 1 commit intogoogle:masterfrom
mohammadmseet-hue:fix-big-endian-arg-order

Conversation

@mohammadmseet-hue
Copy link
Copy Markdown
Contributor

Summary

The ARG_LOW and ARG_HIGH macros in codegen.c assume little-endian byte order when loading 32-bit words from 64-bit seccomp_data.args[] entries. On big-endian targets (MIPS, MIPS64, M68K), the high and low 32-bit words within a 64-bit value are stored in the opposite order, causing the generated BPF to compare the wrong halves.

This means seccomp policies using 64-bit argument comparisons produce incorrect BPF filters on big-endian architectures, where a filter intended to match arg == 0x0000000100000000 would instead match arg == 0x00000001.

Fix

Use the __AUDIT_ARCH_LE flag (0x40000000) from the audit architecture value to detect big-endian targets at compile time and swap the word offsets in ARG_LOW/ARG_HIGH accordingly.

Testing

All 32 core tests pass (3 include-file test failures are pre-existing and unrelated).

The ARG_LOW and ARG_HIGH macros in codegen.c assumed little-endian byte
order, placing the low 32-bit word of a 64-bit syscall argument at the
base offset and the high word at base + 4.  On big-endian architectures
(MIPS, MIPS64, M68K), the word order is reversed: the high word is at
the base offset and the low word is at base + 4.

This caused seccomp BPF filters with 64-bit argument comparisons to
check the wrong word halves on big-endian targets, potentially allowing
syscalls through that should have been blocked.

The fix detects big-endian targets at compile time using the
__AUDIT_ARCH_LE flag (0x40000000) from the audit architecture value and
swaps the word offsets accordingly.
@robertswiecki
Copy link
Copy Markdown
Collaborator

Thank you! BE ftw! :)

@robertswiecki robertswiecki merged commit 18f2074 into google:master Apr 4, 2026
1 check passed
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