]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
seccomp: fix the __secure_computing() stub for !HAVE_ARCH_SECCOMP_FILTER
authorOleg Nesterov <oleg@redhat.com>
Tue, 28 Jan 2025 15:03:07 +0000 (16:03 +0100)
committerKees Cook <kees@kernel.org>
Mon, 10 Feb 2025 17:26:22 +0000 (09:26 -0800)
Depending on CONFIG_HAVE_ARCH_SECCOMP_FILTER, __secure_computing(NULL)
will crash or not. This is not consistent/safe, especially considering
that after the previous change __secure_computing(sd) is always called
with sd == NULL.

Fortunately, if CONFIG_HAVE_ARCH_SECCOMP_FILTER=n, __secure_computing()
has no callers, these architectures use secure_computing_strict(). Yet
it make sense make __secure_computing(NULL) safe in this case.

Note also that with this change we can unexport secure_computing_strict()
and change the current callers to use __secure_computing(NULL).

Fixes: 8cf8dfceebda ("seccomp: Stub for !HAVE_ARCH_SECCOMP_FILTER")
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20250128150307.GA15325@redhat.com
Signed-off-by: Kees Cook <kees@kernel.org>
include/linux/seccomp.h
kernel/seccomp.c

index e45531455d3bbe4ea0ec9e873b73bc3f02bfa2e5..d55949071c30ec37e085ffa81bd3db3107c6924a 100644 (file)
@@ -22,8 +22,9 @@
 #include <linux/atomic.h>
 #include <asm/seccomp.h>
 
-#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
 extern int __secure_computing(const struct seccomp_data *sd);
+
+#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
 static inline int secure_computing(void)
 {
        if (unlikely(test_syscall_work(SECCOMP)))
@@ -32,11 +33,6 @@ static inline int secure_computing(void)
 }
 #else
 extern void secure_computing_strict(int this_syscall);
-static inline int __secure_computing(const struct seccomp_data *sd)
-{
-       secure_computing_strict(sd->nr);
-       return 0;
-}
 #endif
 
 extern long prctl_get_seccomp(void);
index 7bbb408431ebcfe8d055f8259f0150acb286f426..3231f63d93d89e5492a4ddad051f0f7e4d5e9c3c 100644 (file)
 #include <linux/syscalls.h>
 #include <linux/sysctl.h>
 
+#include <asm/syscall.h>
+
 /* Not exposed in headers: strictly internal use only. */
 #define SECCOMP_MODE_DEAD      (SECCOMP_MODE_FILTER + 1)
 
-#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
-#include <asm/syscall.h>
-#endif
-
 #ifdef CONFIG_SECCOMP_FILTER
 #include <linux/file.h>
 #include <linux/filter.h>
@@ -1074,6 +1072,14 @@ void secure_computing_strict(int this_syscall)
        else
                BUG();
 }
+int __secure_computing(const struct seccomp_data *sd)
+{
+       int this_syscall = sd ? sd->nr :
+               syscall_get_nr(current, current_pt_regs());
+
+       secure_computing_strict(this_syscall);
+       return 0;
+}
 #else
 
 #ifdef CONFIG_SECCOMP_FILTER