Repository navigation
seccomp: fix socket() rule argument count and restrict AF_UNIX to SOCK_STREAM - #708
Open
ricardobranco777 wants to merge 2 commits into
Open
ricardobranco777 wants to merge 2 commits into
ricardobranco777 wants to merge 2 commits into
Conversation
Both socket() rules passed two comparators but set arg_cnt to 1, so libseccomp ignored the second one. As a result any AF_UNIX socket type and any AF_NETLINK protocol were allowed, instead of only SOCK_STREAM UNIX sockets and NETLINK_KOBJECT_UEVENT netlink sockets. Set arg_cnt to 2 so both comparators are applied. Fixes: USBGuard#707 Signed-off-by: Ricardo Branco <rbranco@suse.de>
The previous mask of SOCK_STREAM (1) only tested bit 0 of the type argument, so SOCK_SEQPACKET (5) and SOCK_RAW (3) also matched. Mask out SOCK_CLOEXEC and SOCK_NONBLOCK and require the remaining type to be exactly SOCK_STREAM. The mask is 32-bit since the kernel only looks at the lower 32 bits of the int argument. Signed-off-by: Ricardo Branco <rbranco@suse.de>
This branch has not been deployed
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.
Fixes #707
Both
socket()allow rules insetupSeccompWhitelist()passed two comparators but setarg_cntto1. libseccomp only reads the firstarg_cntcomparators, so the second one was silently ignored:AF_UNIX: theSOCK_STREAMcheck had no effect, so any socket type was allowed.AF_NETLINK: theNETLINK_KOBJECT_UEVENTcheck had no effect, so any netlink protocol was allowed.Changes
arg_cntto2so both comparators are applied.SOCK_STREAM, i.e. bit 0) would also matchSOCK_SEQPACKET(5) andSOCK_RAW(3) once enforced. Mask outSOCK_CLOEXECandSOCK_NONBLOCKand require the remaining type to be exactlySOCK_STREAM. The mask is 32-bit because the kernel only uses the lower 32 bits of theintargument.