Skip to content

seccomp: document 64-bit argument comparisons and fix masked-equal doc - #133

Open
ricardobranco777 wants to merge 1 commit into
seccomp:mainfrom
ricardobranco777:doc-cmp-upper-bits
Open

ricardobranco777 wants to merge 1 commit into
seccomp:mainfrom
ricardobranco777:doc-cmp-upper-bits

Conversation

@ricardobranco777

@ricardobranco777 ricardobranco777 commented Oct 12, 2026 •

Copy link
Copy Markdown

The kernel's seccomp filter compares the raw 64-bit argument registers, while syscalls with 32-bit argument types (e.g. the socket(2) domain) ignore the upper 32 bits. A condition such as

MakeCondition(0, CompareEqual, unix.AF_NETLINK)

is therefore bypassed by socket(0x100000000|AF_NETLINK, ...).

Document this in MakeCondition and CompareEqual, and recommend CompareMaskedEqual with a 0xffffffff mask for 32-bit arguments.

Also fix the MakeCondition comment on masked equals, which had the operand order reversed: the first value is the mask and the second is the datum.

See seccomp/libseccomp#504

@kolyshkin kolyshkin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM overall, thank you @ricardobranco777. Left some nits

Comment thread seccomp.go Outdated
Comment thread seccomp.go
Comment thread seccomp.go Outdated
Comment thread seccomp.go
@kolyshkin

Copy link
Copy Markdown
Contributor

@ricardobranco777 also makes sense to add a link to the same PR for the main libseccomp repo

The kernel's seccomp filter compares the raw 64-bit argument registers,
while syscalls with 32-bit argument types (e.g. the socket(2) domain)
ignore the upper 32 bits. A condition such as

  MakeCondition(0, CompareEqual, unix.AF_NETLINK)

is therefore bypassed by socket(0x100000000|AF_NETLINK, ...).

Document this in MakeCondition and CompareEqual, and recommend
CompareMaskedEqual with a 0xffffffff mask for 32-bit arguments.

Also fix the MakeCondition comment on masked equals, which had the
operand order reversed: the first value is the mask and the second is
the datum.

Signed-off-by: Ricardo Branco <rbranco@suse.de>
@ricardobranco777

Copy link
Copy Markdown
Author

@ricardobranco777 also makes sense to add a link to the same PR for the main libseccomp repo

Hopefully fixed now.

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