Skip to content

[1.1] seccomp: enosys: always return -ENOSYS for setup(2) on s390(x)#3478

Merged
AkihiroSuda merged 1 commit intoopencontainers:release-1.1from
cyphar:1.1-seccomp-enosys-setup
May 25, 2022
Merged

[1.1] seccomp: enosys: always return -ENOSYS for setup(2) on s390(x)#3478
AkihiroSuda merged 1 commit intoopencontainers:release-1.1from
cyphar:1.1-seccomp-enosys-setup

Conversation

@cyphar
Copy link
Copy Markdown
Member

@cyphar cyphar commented May 23, 2022

On s390x, syscalls above 255 are multiplexed using the (now otherwise
unused) setup(2) syscall (syscall number 0). If the kernel supports the
syscall then it will correctly translate the syscall number such that
seccomp will correctly detect it -- however, for unknown syscalls the
syscall number remains unchanged. This can be verified by running the
following program under strace:

int main(void)
{
	scmp_filter_ctx ctx = seccomp_init(SCMP_ACT_TRAP);
	seccomp_load(ctx);

	return syscall(439, AT_FDCWD, "asdf", X_OK, 0);
}

Which will then die with the following signal (on pre-5.8 kernels):

--- SIGSYS {si_signo=SIGSYS, si_code=SYS_SECCOMP,
            si_call_addr=0x3ffb3006c22, si_syscall=__NR_setup,
            si_arch=AUDIT_ARCH_S390X} ---

(Note that the si_syscall is __NR_setup, not __NR_faccessat2.)

As a result, the -ENOSYS handling we had previously did not work
completely correctly on s390x because any syscall not supported by the
kernel would be treated as syscall number 0 rather than the actual
syscall number.

Always returning -ENOSYS will not cause any issues because in all of the
cases where this multiplexing occurs, seccomp will see the remapped
syscall number -- and no userspace program will call setup(2)
intentionally (the syscall has not existed in Linux for decades and was
originally a hack used early in Linux init prior to spawning pid1 -- so
you will get -ENOSYS from the kernel anyway).

Backport of #3474
Signed-off-by: Aleksa Sarai cyphar@cyphar.com

@cyphar cyphar added the backport/1.1-pr A backport PR to release-1.1 label May 23, 2022
@cyphar cyphar added this to the 1.1.3 milestone May 23, 2022
@cyphar cyphar marked this pull request as ready for review May 24, 2022 02:51
On s390x, syscalls above 255 are multiplexed using the (now otherwise
unused) setup(2) syscall (syscall number 0). If the kernel supports the
syscall then it will correctly translate the syscall number such that
seccomp will correctly detect it -- however, for unknown syscalls the
syscall number remains unchanged. This can be verified by running the
following program under strace:

	int main(void)
	{
		scmp_filter_ctx ctx = seccomp_init(SCMP_ACT_TRAP);
		seccomp_load(ctx);

		return syscall(439, AT_FDCWD, "asdf", X_OK, 0);
	}

Which will then die with the following signal (on pre-5.8 kernels):

	--- SIGSYS {si_signo=SIGSYS, si_code=SYS_SECCOMP,
	            si_call_addr=0x3ffb3006c22, si_syscall=__NR_setup,
	            si_arch=AUDIT_ARCH_S390X} ---

(Note that the si_syscall is __NR_setup, not __NR_faccessat2.)

As a result, the -ENOSYS handling we had previously did not work
completely correctly on s390x because any syscall not supported by the
kernel would be treated as syscall number 0 rather than the actual
syscall number.

Always returning -ENOSYS will not cause any issues because in all of the
cases where this multiplexing occurs, seccomp will see the remapped
syscall number -- and no userspace program will call setup(2)
intentionally (the syscall has not existed in Linux for decades and was
originally a hack used early in Linux init prior to spawning pid1 -- so
you will get -ENOSYS from the kernel anyway).

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Copy link
Copy Markdown
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

LGTM

@AkihiroSuda AkihiroSuda merged commit fa7cca9 into opencontainers:release-1.1 May 25, 2022
@cyphar cyphar deleted the 1.1-seccomp-enosys-setup branch May 27, 2022 11:08
@kolyshkin kolyshkin mentioned this pull request Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/seccomp backport/1.1-pr A backport PR to release-1.1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants