Skip to content

seccomp: Explicitly block socketcall to prevent AF_ALG filter bypass - #21

Merged
vvoland merged 1 commit into
moby:mainfrom
vvoland:fix-socketcall
May 1, 2026
Merged

vvoland merged 1 commit into
moby:mainfrom
vvoland:fix-socketcall

Conversation

@vvoland

@vvoland vvoland commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

The socket arg filters that block AF_ALG and AF_VSOCK only apply to the direct socket(2) syscall. On architectures with the legacy socketcall(2) multiplexer (i386, s390, MIPS o32), libseccomp auto-generates a socketcall(SYS_SOCKET) -> ALLOW companion for each socket ALLOW rule. This companion only checks the socketcall sub-command number, not the address family (behind a pointer BPF cannot dereference), bypassing the AF_ALG block for 32-bit binaries.

Add an explicit socketcall -> ERRNO(ENOSYS) deny rule placed before the socket allow rules. ENOSYS must be used instead of EPERM because the deny errno must differ from DefaultErrnoRet (EPERM): runc skips calling seccomp_rule_add() entirely when a rule's action matches the default action, so an EPERM deny is never passed to libseccomp and the auto-generated socketcall ALLOW path survives unchallenged. With ENOSYS, runc passes the rule through, and libseccomp replaces the auto-generated ALLOW path with ERRNO(ENOSYS) in the BPF.

Since Linux 4.3, all affected architectures provide direct socket syscalls and modern glibc/musl already use them. Only very old statically-linked 32-bit binaries compiled against pre-4.3 glibc would be affected.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the default seccomp profile against AF_ALG socket filtering bypasses on architectures that still support the legacy socketcall(2) multiplexer, by explicitly denying socketcall rather than implicitly relying on it not being in the allow-list.

Changes:

  • Remove socketcall from the unconditional allow-list in the default seccomp profile.
  • Add an explicit SCMP_ACT_ERRNO rule denying socketcall to prevent bypassing the socket(2) address-family arg filters.
  • Regenerate seccomp/default.json to reflect the updated Go profile.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
seccomp/default_linux.go Removes socketcall from the allow-list and adds an explicit deny rule with rationale comments.
seccomp/default.json Updates the generated default profile JSON to include an explicit deny rule for socketcall.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread seccomp/default_linux.go Resolved
Comment thread seccomp/default.json Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vvoland
vvoland requested review from thaJeztah and tianon April 30, 2026 22:35
@vvoland
vvoland force-pushed the fix-socketcall branch 2 times, most recently from 7e5db0e to 962afae Compare April 30, 2026 23:39
@tianon

tianon commented Apr 30, 2026

Copy link
Copy Markdown
Member

notes from "claude my eyes right out":


PR #21 (updated) — complete analysis

What the PR does: Removes socketcall from the unconditional allowlist and adds an explicit deny rule:

errnoRet := uint(unix.EPERM)   // = 1
// ...
{
    LinuxSyscall: specs.LinuxSyscall{
        Names:  []string{"socketcall"},
        Action: specs.ActErrno,
        ErrnoRet: &errnoRet,   // EPERM = 1
    },
},
// ... three-range socket ALLOW rules follow

The update moved the socketcall deny rule to before the socket ALLOW rules in the Go slice. The errnoRet value is unchanged: still unix.EPERM = 1.

The ordering change makes no difference. The BPF for both orderings is byte-for-byte identical (confirmed empirically). libseccomp sorts rules internally and generates the same BPF regardless of insertion order for this case.

Why the bypass still works — the two-layer failure:

Layer 1 — runc silently drops the deny rule. runc's matchCall checks if callAct == defAct { return nil }. Here callAct = ActErrno(EPERM=1) and defAct = ActErrno(EPERM=1) (the profile's DefaultErrnoRet uses the same errnoRet variable). They are equal, so the rule is silently discarded before it ever reaches libseccomp.

Layer 2 — even if runc didn't discard it, libseccomp ignores it too. When a rule's action equals the filter default action, libseccomp's BPF generator produces identical output with or without the rule — confirmed: cases A and B generate byte-identical BPF.

The surviving auto-generated bypass path. libseccomp automatically adds a socketcall(SYS_SOCKET=1) → ALLOW entry to the i386 section of the BPF whenever socket ALLOW rules are present on a filter that includes the i386 sub-arch. This is because on i386, socket() is implemented via socketcall(SYS_SOCKET, args). The auto-generated BPF checks only the call number (SYS_SOCKET=1), not the family pointer (which seccomp cannot dereference). The i386 section for cases A and B:

[17] jeq socketcall(102) → [18]
[18] ld args[0].lo             ← loads call# (SYS_SOCKET=1), not family
[19] jeq SYS_SOCKET(1) → ALLOW   ← socketcall(SYS_SOCKET,[AF_ALG,...]) → ALLOWED

socketcall(SYS_SOCKET, [AF_ALG=38, SOCK_SEQPACKET, 0]) from a 32-bit i386 binary hits [19] → ALLOW. The bypass is intact.

What actually fixes it: Use any errno value other than EPERM. The profile already has nosys := uint(unix.ENOSYS) in scope (used for other deny rules like clone3). Changing ErrnoRet: &errnoRet to ErrnoRet: &nosys would:

  1. Make callAct = ERRNO(ENOSYS=38) ≠ defAct = ERRNO(EPERM=1) → runc does not skip it
  2. libseccomp generates [17] jeq socketcall → [18] ret ERRNO(38) — the auto-generated ALLOW path is replaced entirely (case C above)
  3. All socketcall operations are blocked for old 32-bit static binaries — unavoidable, since seccomp cannot inspect the pointer argument to filter selectively by address family

@vvoland
vvoland force-pushed the fix-socketcall branch 2 times, most recently from a3e5276 to 29d0500 Compare April 30, 2026 23:53
The socket arg filters that block AF_ALG and AF_VSOCK only apply to the
direct socket(2) syscall. On architectures with the legacy socketcall(2)
multiplexer (i386, s390, MIPS o32), libseccomp auto-generates a
socketcall(SYS_SOCKET) -> ALLOW companion for each socket ALLOW rule.
This companion only checks the socketcall sub-command number, not the
address family (behind a pointer BPF cannot dereference), bypassing the
AF_ALG block for 32-bit binaries.

Add an explicit socketcall -> ERRNO(ENOSYS) deny rule placed before the
socket allow rules. ENOSYS must be used instead of EPERM because the
deny errno must differ from DefaultErrnoRet (EPERM): runc skips calling
seccomp_rule_add() entirely when a rule's action matches the default
action, so an EPERM deny is never passed to libseccomp and the
auto-generated socketcall ALLOW path survives unchallenged. With ENOSYS,
runc passes the rule through, and libseccomp replaces the auto-generated
ALLOW path with ERRNO(ENOSYS) in the BPF.

Since Linux 4.3, all affected architectures provide direct socket
syscalls and modern glibc/musl already use them. Only very old
statically-linked 32-bit binaries compiled against pre-4.3 glibc would
be affected.

Co-authored-by: Tianon Gravi <admwiggin@gmail.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
@vvoland
vvoland merged commit d62da27 into moby:main May 1, 2026
10 checks passed
chrisd8088 added a commit to git-lfs/git-lfs that referenced this pull request Oct 20, 2026
Our Linux CI and release jobs execute on GitHub Actions runners, and
in our "build-docker" job we use Docker containers to build a set of
release binaries for multiple Linux distributions and versions.

Per actions/runner-images#14748, GitHub Actions are now migrating
their "ubuntu-latest" runners from the Ubuntu 24.04 ("Noble Numbat")
Long-Term Support (LTS) release to the Ubuntu 26.04 ("Resolute
Raccoon") LTS release.  At present, the former release provides
version 28.0.4 of Docker by default, while the latter provides
Docker version 29.4.2:

  https://github.com/actions/runner-images/blob/releases/ubuntu24/20261012/images/ubuntu/Ubuntu2404-Readme.md#tools
  https://github.com/actions/runner-images/blob/releases/ubuntu26/20261012/images/ubuntu/Ubuntu2604-Readme.md#tools

However, as described in actions/runner-images#14790, Docker v29.4.2
effectively disables network access in older 32-bit Linux containers
such as the ones we build using Debian 11 and Debian 12.  As a
result, our CI and release workflows' "build-docker" jobs will fail
on "ubuntu-26.04" runners until the version of Docker provided in
those runners has been updated to at least 29.4.3.

To ensure our CI and release workflows continue to pass, we therefore
temporarily pin our "build-docker" jobs to "ubuntu-24.04" runners.
(Note that this mirrors the explicit Ubuntu version already specified
for our "build-docker-arm" jobs.)

Once the issue reported in actions/runner-images#14790 has been
addressed, we can update our "build-docker" jobs to again use
"ubuntu-latest" runners.  At the same time, we expect to also update
our "build-docker-arm" jobs to use "ubuntu-26.04-arm" runners.

For reference, Debian 11 installs version 2.31 of the GNU C library
(glibc), and Debian 12 installs glibc v2.36.  Both of those versions
of glibc set a default minimum Linux kernel version of 3.2.0:

  https://github.com/gnutools/glibc/blob/glibc-2.31/sysdeps/unix/sysv/linux/configure.ac#L4
  https://github.com/gnutools/glibc/blob/glibc-2.36/sysdeps/unix/sysv/linux/configure.ac#L4

Prior to Linux kernel version 4.3.0, socket API system calls on
32-bit systems were implemented via the socketcall(2) system call:

  https://man7.org/linux/man-pages/man2/socketcall.2.html#VERSIONS
  https://man7.org/linux/man-pages/man2/socketcall.2.html#STANDARDS

Hence on i386 systems the glibc library implements system calls such
as socket(2) using socketcall(2):

  https://github.com/gnutools/glibc/blob/glibc-2.31/sysdeps/unix/sysv/linux/i386/kernel-features.h#L35-L44
  https://github.com/gnutools/glibc/blob/glibc-2.31/sysdeps/unix/sysv/linux/socket.c#L29-L33

  https://github.com/gnutools/glibc/blob/glibc-2.36/sysdeps/unix/sysv/linux/i386/kernel-features.h#L33-L44
  https://github.com/gnutools/glibc/blob/glibc-2.36/sysdeps/unix/sysv/linux/socket.c#L29-L33

However, this hinders the use of seccomp(2) filters for these
socket API system calls.  Version 29.4.2 of the Moby project
(the open-source portion of the Docker project) imports version
0.2.2 of the "seccomp" package from the "moby/profiles" Go module,
and that version of the "seccomp" package includes a change which
disables all access to the socketcall(2) system call:

  https://github.com/moby/moby/blob/docker-v29.4.2/go.mod#L68
  https://github.com/moby/profiles/blob/seccomp/v0.2.2/seccomp/default_linux.go#L444-L463

Commit moby/profiles@7158007 of
PR moby/profiles#21 implemented this change, noting:

  Since Linux 4.3, all affected architectures provide direct socket
  syscalls and modern glibc/musl already use them.  Only very old
  statically-linked 32-bit binaries compiled against pre-4.3 glibc
  would be affected.

This explains why all network activity is disabled in the 32-bit
Docker containers our workflow jobs build using Debian 11 and 12.

Fortunately, v0.2.3 of the "seccomp" package has been updated in
commit moby/profiles@3c28324 of
PR moby/profiles#23 to restore socketcall(2) calls, and version
29.4.3 of the Moby project imports the updated "seccomp" package:

  https://github.com/moby/moby/blob/docker-v29.4.3/go.mod#L68
  https://github.com/moby/profiles/blob/seccomp/v0.2.3/seccomp/default_linux.go#L445-L463
ramazansancar added a commit to ramazansancar/schematrix_HAS_Prepper_Disk that referenced this pull request Nov 29, 2026
… test on ubuntu-24.04, test.sh fixes

ubuntu-latest (26.04) Docker 29.4.2 ile geliyor; o sürümün seccomp profili socketcall'u
kapatıyor (moby/profiles#21, 29.4.3'te geri alındı; actions/runner-images#14790) ve 32 bit
x86'da Go ile kiwix-serve ağa çıkamıyor. 386 işi Docker 28.0.4'lü ubuntu-24.04'e alındı;
test.sh bu sürüm + 386'da güvenliği gevşetmeden nedeni yazıp duruyor. README'ye not.

test.sh: reset-password kontrolü çıkış koduna bakıyor (pipefail + grep -q yüzünden
arm/v6'da yanlış hata veriyordu); panel kapatılınca ana sayfa ve Kiwix açık kalıyor mu,
panel geri geliyor mu kontrolü eklendi.

ubuntu-latest (26.04) ships Docker 29.4.2, whose seccomp profile blocks socketcall
(moby/profiles#21, reverted in 29.4.3; actions/runner-images#14790), so Go and kiwix-serve
have no network on 32-bit x86. The 386 job moves to ubuntu-24.04 (Docker 28.0.4); on that
version + 386 test.sh states the cause and stops instead of weakening the hardening.
README note added.

test.sh: the reset-password check uses the exit code (pipefail + grep -q gave a false
failure on arm/v6); new checks that the homepage and Kiwix stay up while the panel is
stopped and that the panel comes back.
ramazansancar added a commit to ramazansancar/schematrix_HAS_Prepper_Disk that referenced this pull request Nov 29, 2026
ubuntu-latest (26.04) ships Docker 29.4.2, whose seccomp profile blocks socketcall
(moby/profiles#21, reverted in 29.4.3; actions/runner-images#14790), so Go and kiwix-serve
have no network on 32-bit x86. The 386 job moves to ubuntu-24.04 (Docker 28.0.4); on that
version + 386 test.sh states the cause and stops instead of weakening the hardening.
README note added.

test.sh: the reset-password check uses the exit code (pipefail + grep -q gave a false
failure on arm/v6); new checks that the homepage and Kiwix stay up while the panel is
stopped and that the panel comes back.

ubuntu-latest (26.04) Docker 29.4.2 ile geliyor; o sürümün seccomp profili socketcall'u
kapatıyor (moby/profiles#21, 29.4.3'te geri alındı; actions/runner-images#14790) ve 32 bit
x86'da Go ile kiwix-serve ağa çıkamıyor. 386 işi Docker 28.0.4'lü ubuntu-24.04'e alındı;
test.sh bu sürüm + 386'da güvenliği gevşetmeden nedeni yazıp duruyor. README'ye not.

test.sh: reset-password kontrolü çıkış koduna bakıyor (pipefail + grep -q yüzünden
arm/v6'da yanlış hata veriyordu); panel kapatılınca ana sayfa ve Kiwix açık kalıyor mu,
panel geri geliyor mu kontrolü eklendi.
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.

3 participants