WSL: Inserting seccomp notify filter in WSL kernel 5.15.83.1 fails with EBUSY

Version

Microsoft Windows [Version 10.0.22621.1245]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

5.15.83.1-microsoft-standard-WSL2

Distro Version

Ubuntu 22.04

Other Software

No response

Repro Steps

Starting with WSL kernel 5.15.83.1, there is an issue inserting seccomp filters that have the “notify” action (see SECCOMP_FILTER_FLAG_NEW_LISTENER in the Linux seccomp man page). Inserting such filters returns EBUSY from the kernel.

Possible cause is that PID 1 in the WSL distro appears to have a seccomp filter attached to it by default:

wsl -d Ubuntu-22.04

$ grep -i seccomp /proc/1/status
Seccomp:        2
Seccomp_filters:        1        <<< HERE

I believe the presence of this filter on PID 1 is causing the problem: the filter is inherited by all child processes in the distro, and therefore a child process that tries to insert a seccomp notify filter (SECCOMP_FILTER_FLAG_NEW_LISTENER) gets an EBUSY response from the kernel since only one such filter per process is allowed.

The problem does NOT occur in WSL kernel 5.15.79.1. In that kernel, PID 1 has no seccomp filter on it (as expected):

$ grep -i seccomp /proc/1/status
Seccomp:        0
Seccomp_filters:        0      

Expected Behavior

A process running in a WSL Linux distro should be able to insert a seccomp notify filter (SECCOMP_FILTER_FLAG_NEW_LISTENER) without problem.

In addition, PID 1 in the WSL Linux distro should not have a seccomp filter attached to it by default.

Actual Behavior

Starting with WSL kernel 5.15.83.1, inserting seccomp filters that have the “notify” action (SECCOMP_FILTER_FLAG_NEW_LISTENER) returns EBUSY from the kernel.

PID 1 in the WSL distro has an unexpected seccomp filter attached to it by default:

wsl -d Ubuntu-22.04

$ grep -i seccomp /proc/1/status
Seccomp:        2
Seccomp_filters:        1        <<< HERE

Diagnostic Logs

No response

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 32 (1 by maintainers)

Most upvoted comments

Issue still happens with WSL 2.5.1 (Linux 6.6.75).

Hi @CatalinFetoiu thanks for the response.

can you please share more details about the Docker scenario/s affected by this

Sure; Docker (and possibly other runtimes too) sometimes use a seccomp notify filter to trap system calls inside a container.

The Linux kernel only allows one such filter per process. And filters are inherited by child processes.

Turns out that when networkingMode=mirrored is active, apparently WSL inserts a seccomp notify filter on PID 1 of the WSL distro. That filter is inherited by all processes in the distro (since they are all descendants of PID 1), and therefore it’s not possible to insert seccomp notify filters from within the distro (doing son returns EBUSY).

Ideally, we are hoping a WSL distro behaves much like a VM, where there are no seccomp filters on PID 1.

FYI we had this same problem in the past with WSL (original description of this PR), but the WSL developers were able to fix it and remove the seccomp notify filter from PID 1. However it appears to still be occurring when the mirrored networking mode is enabled unfortunately.

Hi @MrElectronics,

I am not able to repro on WSL (same version as yours). However, a user commented in this Sysbox issue that having networkingMode=mirrored in their %USERPROFILE%\.wslconfig was causing the problem for him.

When the user removed networkingMode=mirrored, then Sysbox was able to insert the seccomp-notify filter into the WSL kernel.

Thanks @kelsey-steele! Let me try that tomorrow and get back to you.

Hi @kelsey-steele, thanks for the detailed instructions to upgrade the WSL kernel, super clear and easy to follow.

I updated my WSL kernel to 5.15.90.1, but unfortunately still hit the same issue:

C:\Users\Cesar> wsl -d Ubuntu-22.04

cesar@xps15:/mnt/c/Users/Cesar$ uname -a
Linux xps15 5.15.90.1-microsoft-standard-WSL2+ #1 SMP Tue Feb 7 10:58:54 PST 2023 x86_64 x86_64 x86_64 GNU/Linux

cesar@xps15:/mnt/c/Users/Cesar$ grep -i seccomp /proc/1/status
Seccomp:     2
Seccomp_filters: 1        <<< HERE: why does the init process have a seccomp filter on it?

As a result, when I try to run a container with Docker Desktop on WSL, using this new runtime that uses seccomp-notify, it fails with:

$ docker run -it --rm alpine
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: container_linux.go:429: starting container process caused: init_linux.go:631: loading seccomp notification rules caused: error loading seccomp filter into kernel: device or resource busy: unknown.

Could you double check on your side if /proc/1/status on your WSL kernel 5.15.90.1 shows a seccomp filter on it?

Thanks!

@ctalledo thank you for the additional info!

The WSL2 kernel gets released on the WSL2 kernel repo first and then will be included in the next WSL release. Currently we’re in that stage where the new kernel is so far only released on the WSL2 kernel repo. Here’s the steps you can follow to boot with the 5.15.90 WSL kernel:

  1. Clone the WSL2 Kernel Repo

  2. Make sure you’re on the ‘linux-msft-wsl-5.15.y’ branch or checkout the ‘linux-msft-wsl-5.15.90.1’ tag

  3. Follow the build instructions in the WSL2 kernel README

  4. After building, you will find your new kernel image inside the WSL2 tree at ‘arch/x86/boot/bzImage’

  5. copy this to your windows files for easy access. i.e. $ cp arch/x86/boot/bzImage /mnt/c/Users/$USERNAME/5.15.90.1-wsl

  6. Add the new kernel to your .wslconfig file:

     [wsl2]
     kernel=C:\\Users\\$USERNAME\\5.15.90.1-wsl
    
  7. Run ‘wsl --shutdown’ inside powershell

  8. Restart your WSL instance and verify new kernel is being used: $ uname -r

These are the same steps you’d use to boot with a custom or upstream kernel on x86 machines. Just make sure to build any kernel you want to use with the config file from WSL2 (can be found in the WSL2 tree under Microsoft/config-wsl).

Let me know if you have any questions or unable to take these steps. Hoping I’ll be able to reproduce on my side today so I can poke at things.