Skip to content

seccomp: fix socket() rule argument count and restrict AF_UNIX to SOCK_STREAM - #708

Open
ricardobranco777 wants to merge 2 commits into
USBGuard:mainfrom
ricardobranco777:fix/seccomp-socket-arg-cnt
Open

ricardobranco777 wants to merge 2 commits into
USBGuard:mainfrom
ricardobranco777:fix/seccomp-socket-arg-cnt

Conversation

@ricardobranco777

Copy link
Copy Markdown

Fixes #707

Both socket() allow rules in setupSeccompWhitelist() passed two comparators but set arg_cnt to 1. libseccomp only reads the first arg_cnt comparators, so the second one was silently ignored:

  • AF_UNIX: the SOCK_STREAM check had no effect, so any socket type was allowed.
  • AF_NETLINK: the NETLINK_KOBJECT_UEVENT check had no effect, so any netlink protocol was allowed.

Changes

  1. seccomp: fix arg_cnt for socket() allow rules: set arg_cnt to 2 so both comparators are applied.
  2. seccomp: only allow SOCK_STREAM for AF_UNIX sockets: the existing mask (SOCK_STREAM, i.e. bit 0) would also match SOCK_SEQPACKET (5) and SOCK_RAW (3) once enforced. Mask out SOCK_CLOEXEC and SOCK_NONBLOCK and require the remaining type to be exactly SOCK_STREAM. The mask is 32-bit because the kernel only uses the lower 32 bits of the int argument.

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

No deployments
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.

seccomp: socket() allow rules pass 2 comparators with arg_cnt = 1, so the second check is ignored

1 participant