Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nspawn: add "swapcontext()" to seccomp whitelist for user contexts on ppc32 #9485

Closed
LionNatsu opened this issue Jul 2, 2018 · 2 comments · Fixed by #9487
Closed

nspawn: add "swapcontext()" to seccomp whitelist for user contexts on ppc32 #9485

LionNatsu opened this issue Jul 2, 2018 · 2 comments · Fixed by #9487

Comments

@LionNatsu
Copy link
Contributor

LionNatsu commented Jul 2, 2018

systemd version the issue has been seen with

From 96bedbe nspawn: replace syscall blacklist with a whitelist

... v239 v238 v237 v236 v235.

Unexpected behaviour you saw

Function swapcontext is out of system call filter whitelist of nspawn. Anyone of {get,set,make,swap}context is not available on PowerPC 32-bit (i.e. PPC32) container by default.

Use case: Fibers of Ruby is not available in PPC32 container.
https://bugs.ruby-lang.org/issues/14883

Steps to reproduce the problem

Part. 1

nspawn a PPC32 container, run Ruby code:

fib = Enumerator.new do |y|
  y << "FOO"
  y << "BAR"
end
puts fib.next

It should print "FOO", but it segmentation fault.

Part. 2

#include <ucontext.h>
#include <errno.h>
int main() {
    ucontext_t c;
    if (getcontext(&c) < 0)
        return errno;
    return 0;
}

It should return 0, but it returned 1 (EPERM).

Notes

A fiber uses getcontext() function to get the current context, to construct a new context, and uses makecontext() to switch context, so we have a nice lightweight userspace "thread" (or coroutine, fiber etc.).

The underlying call of getcontext() depends on architectures.

I checked source code from glibc (/sysdeps/unix/sysv/linux):

aarch64: rt_sigprocmask
sparc64: trap 0x6e
sparc32: rt_sigprocmask
sh3: sigprocmask
sh4: sigprocmask
i386: sigprocmask
arm: sigprocmask
powerpc64: sigprocmask
powerpc32: swapcontext
alpha: osf_sigprocmask
s390-32: rt_sigprocmask
s390-64: rt_sigprocmask
nios2: rt_sigprocmask
ia64: rt_sigprocmask
hppa: sigprocmask
x86_64: rt_sigprocmask
m680x0: sigprocmask

We already have {,rt_}sigprocmask in whitelist now (@signal), but there is no swapcontext.

[SYSCALL_FILTER_SET_SIGNAL] = {
.name = "@signal",
.help = "Process signal handling",
.value =
"rt_sigaction\0"
"rt_sigpending\0"
"rt_sigprocmask\0"
"rt_sigsuspend\0"
"rt_sigtimedwait\0"
"sigaction\0"
"sigaltstack\0"
"signal\0"
"signalfd\0"
"signalfd4\0"
"sigpending\0"
"sigprocmask\0"
"sigsuspend\0"
},

The syscall swapcontext() is a kind of mixture of {get,set,make,swap}context. Semantically it may be not suitable for @signal, we can put it in here:

/* Plus a good set of additional syscalls which are not part of any of the groups above */
{ 0, "brk" },
{ 0, "capget" },
{ 0, "capset" },

@poettering
Copy link
Member

hmm, I'd probably add it to @process. after all a coroutine is a bit like a thread, and that's where we placed child process and thread creation syscalls... Could you prep a PR for this? We don't have access to ppc, hence rely on testing/submission for more exotic archs like this one.

LionNatsu added a commit to LionNatsu/systemd that referenced this issue Jul 2, 2018
There are some modern programming languages use userspace context switches
to implement coroutine features. PowerPC (32-bit) needs syscall "swapcontext" to get
contexts or switch between contexts, which is special.

Adding this rule should fix systemd#9485.
@LionNatsu
Copy link
Contributor Author

LionNatsu commented Jul 2, 2018

Could you prep a PR for this? We don't have access to ppc, hence rely on testing/submission for more exotic archs like this one.

Sure, and it works fine here now.

poettering pushed a commit that referenced this issue Jul 3, 2018
There are some modern programming languages use userspace context switches
to implement coroutine features. PowerPC (32-bit) needs syscall "swapcontext" to get
contexts or switch between contexts, which is special.

Adding this rule should fix #9485.
keszybz pushed a commit to keszybz/systemd that referenced this issue Oct 28, 2018
There are some modern programming languages use userspace context switches
to implement coroutine features. PowerPC (32-bit) needs syscall "swapcontext" to get
contexts or switch between contexts, which is special.

Adding this rule should fix systemd#9485.

(cherry picked from commit a9518dc)
fpletz pushed a commit to NixOS/systemd that referenced this issue Oct 31, 2018
There are some modern programming languages use userspace context switches
to implement coroutine features. PowerPC (32-bit) needs syscall "swapcontext" to get
contexts or switch between contexts, which is special.

Adding this rule should fix systemd#9485.

(cherry picked from commit a9518dc)
evol262 pushed a commit to evol262/moby that referenced this issue Jan 12, 2022
This system call is only available on the 32- and 64-bit PowerPC, it is
used by modern programming language implementations (such as gcc-go) to
implement coroutine features through userspace context switches.

Other container environment, such as Systemd nspawn already whitelist
this system call in their seccomp profile [1] [2]. As such, it would be
nice to also whitelist it in moby.

This issue was encountered on Alpine Linux GitLab CI system, which uses
moby, when attempting to execute gcc-go compiled software on ppc64le.

[1]: systemd/systemd#9487
[2]: systemd/systemd#9485

Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
thaJeztah pushed a commit to thaJeztah/docker that referenced this issue Dec 1, 2022
This system call is only available on the 32- and 64-bit PowerPC, it is
used by modern programming language implementations (such as gcc-go) to
implement coroutine features through userspace context switches.

Other container environment, such as Systemd nspawn already whitelist
this system call in their seccomp profile [1] [2]. As such, it would be
nice to also whitelist it in moby.

This issue was encountered on Alpine Linux GitLab CI system, which uses
moby, when attempting to execute gcc-go compiled software on ppc64le.

[1]: systemd/systemd#9487
[2]: systemd/systemd#9485

Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
(cherry picked from commit 85eaf23)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants