Skip to contentSkip to conversation

seccomp: remove unused arg from secure_computing()

PATCH In review Christian Brauner 4 participants 12 messages Sep 20, 2019 – Oct 11, 2019

Subsystems (9)
Arm (32-bit) x86 arm64 s390 +5 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 seccomp: remove unused arg from secure_computing()

While touching seccomp code I realized that the struct seccomp_data argument to secure_computing() seems to be unused by all current callers. So let's remove it unless there is some subtlety I missed. Note, I only tested this on x86.

---
 arch/arm/kernel/ptrace.c              | 2 +-
 arch/arm64/kernel/ptrace.c            | 2 +-
 arch/parisc/kernel/ptrace.c           | 2 +-
 arch/s390/kernel/ptrace.c             | 4 ++--
 arch/um/kernel/skas/syscall.c         | 2 +-
 arch/x86/entry/vsyscall/vsyscall_64.c | 2 +-
 include/linux/seccomp.h               | 6 +++---
 7 files changed, 10 insertions(+), 10 deletions(-)
arch/arm/kernel/ptrace.c +1 -1
index 324352787aea..b606cded90cd 100644
@@ -923,7 +923,7 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
 
 	/* Do seccomp after ptrace; syscall may have changed. */
 #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
-	if (secure_computing(NULL) == -1)
+	if (secure_computing() == -1)
 		return -1;
 #else
 	/* XXX: remove this once OABI gets fixed */
arch/arm64/kernel/ptrace.c +1 -1
index 3cf3b135027e..010a835302d3 100644
@@ -1816,7 +1816,7 @@ int syscall_trace_enter(struct pt_regs *regs)
 	}
 
 	/* Do the secure computing after ptrace; failures should be fast. */
-	if (secure_computing(NULL) == -1)
+	if (secure_computing() == -1)
 		return -1;
 
 	if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
arch/parisc/kernel/ptrace.c +1 -1
index 9f6ff7bc06f9..f8c07dcbfb49 100644
@@ -342,7 +342,7 @@ long do_syscall_trace_enter(struct pt_regs *regs)
 	}
 
 	/* Do the secure computing check after ptrace. */
-	if (secure_computing(NULL) == -1)
+	if (secure_computing() == -1)
 		return -1;
 
 #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
arch/s390/kernel/ptrace.c +2 -2
index ad71132374f0..ed80bdfbf5fe 100644
@@ -439,7 +439,7 @@ static int poke_user(struct task_struct *child, addr_t addr, addr_t data)
 long arch_ptrace(struct task_struct *child, long request,
 		 unsigned long addr, unsigned long data)
 {
-	ptrace_area parea; 
+	ptrace_area parea;
 	int copied, ret;
 
 	switch (request) {
@@ -856,7 +856,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
 	}
 
 	/* Do the secure computing check after ptrace. */
-	if (secure_computing(NULL)) {
+	if (secure_computing()) {
 		/* seccomp failures shouldn't expose any additional code. */
 		return -1;
 	}
arch/um/kernel/skas/syscall.c +1 -1
index 44bb10785075..fc37259d5971 100644
@@ -35,7 +35,7 @@ void handle_syscall(struct uml_pt_regs *r)
 		goto out;
 
 	/* Do the seccomp check after ptrace; failures should be fast. */
-	if (secure_computing(NULL) == -1)
+	if (secure_computing() == -1)
 		goto out;
 
 	syscall = UPT_SYSCALL_NR(r);
arch/x86/entry/vsyscall/vsyscall_64.c +1 -1
index e7c596dea947..b10cbf71a8cc 100644
@@ -222,7 +222,7 @@ bool emulate_vsyscall(unsigned long error_code,
 	 */
 	regs->orig_ax = syscall_nr;
 	regs->ax = -ENOSYS;
-	tmp = secure_computing(NULL);
+	tmp = secure_computing();
 	if ((!tmp && regs->orig_ax != syscall_nr) || regs->ip != address) {
 		warn_bad_vsyscall(KERN_DEBUG, regs,
 				  "seccomp tried to change syscall nr or ip");
include/linux/seccomp.h +3 -3
index 84868d37b35d..03583b6d1416 100644
@@ -33,10 +33,10 @@ struct seccomp {
 
 #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
 extern int __secure_computing(const struct seccomp_data *sd);
-static inline int secure_computing(const struct seccomp_data *sd)
+static inline int secure_computing(void)
 {
 	if (unlikely(test_thread_flag(TIF_SECCOMP)))
-		return  __secure_computing(sd);
+		return  __secure_computing(NULL);
 	return 0;
 }
 #else
@@ -59,7 +59,7 @@ struct seccomp { };
 struct seccomp_filter { };
 
 #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
-static inline int secure_computing(struct seccomp_data *sd) { return 0; }
+static inline int secure_computing(void) { return 0; }
 #else
 static inline void secure_computing_strict(int this_syscall) { return; }
 #endif
Signature · 7 lines
2.23.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer
#1 lore raw
Quoted 4 lines · Christian Brauner

While touching seccomp code I realized that the struct seccomp_data argument to secure_computing() seems to be unused by all current callers. So let's remove it unless there is some subtlety I missed. Note, I only tested this on x86.

What was amluto thinking in

2f275de5d1ed ("seccomp: Add a seccomp_data parameter secure_computing()")

?

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#2 lore raw
Quoted 10 lines · Borislav Petkov
Quoted 4 lines · Christian Brauner

While touching seccomp code I realized that the struct seccomp_data argument to secure_computing() seems to be unused by all current callers. So let's remove it unless there is some subtlety I missed. Note, I only tested this on x86.

What was amluto thinking in

2f275de5d1ed ("seccomp: Add a seccomp_data parameter secure_computing()")

IIRC there was a period of time in which x86 used secure_computing() for normal syscalls, and it was a good deal faster to have the arch code supply seccomp_data. x86 no longer works like this, and syscalls aren't fast anymore ayway :(

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#3 lore raw
Quoted 8 lines · Andy Lutomirski
Quoted 7 lines · Borislav Petkov
Quoted 4 lines · Christian Brauner

While touching seccomp code I realized that the struct seccomp_data argument to secure_computing() seems to be unused by all current callers. So let's remove it unless there is some subtlety I missed. Note, I only tested this on x86.

Quoted 8 lines
Quoted 3 lines

What was amluto thinking in

2f275de5d1ed ("seccomp: Add a seccomp_data parameter secure_computing()")

IIRC there was a period of time in which x86 used secure_computing() for normal syscalls, and it was a good deal faster to have the arch code supply seccomp_data. x86 no longer works like this, and syscalls aren't fast anymore ayway :(

Uhuh, thanks Andy.

Christian, pls add that piece of history to the commit message.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#4 lore raw
Quoted 13 lines · Borislav Petkov
Quoted 12 lines · Andy Lutomirski
Quoted 10 lines · Borislav Petkov
Quoted 4 lines · Christian Brauner

While touching seccomp code I realized that the struct seccomp_data argument to secure_computing() seems to be unused by all current callers. So let's remove it unless there is some subtlety I missed. Note, I only tested this on x86.

What was amluto thinking in

2f275de5d1ed ("seccomp: Add a seccomp_data parameter secure_computing()")

Quoted 8 lines
Quoted 4 lines

IIRC there was a period of time in which x86 used secure_computing() for normal syscalls, and it was a good deal faster to have the arch code supply seccomp_data. x86 no longer works like this, and syscalls aren't fast anymore ayway :(

Uhuh, thanks Andy.

Christian, pls add that piece of history to the commit message.

Yeah, this is just left-over from the "two phase" seccomp optimization that was removed a while back. I'll take this clean up into the seccomp tree. Thanks!

Signature · 6 lines
Kees Cook

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#5 lore raw
In reply to Borislav Petkov
Quoted 13 lines · Borislav Petkov
Quoted 12 lines · Andy Lutomirski
Quoted 10 lines · Borislav Petkov
Quoted 4 lines · Christian Brauner

While touching seccomp code I realized that the struct seccomp_data argument to secure_computing() seems to be unused by all current callers. So let's remove it unless there is some subtlety I missed. Note, I only tested this on x86.

What was amluto thinking in

2f275de5d1ed ("seccomp: Add a seccomp_data parameter secure_computing()")

Quoted 8 lines
Quoted 4 lines

IIRC there was a period of time in which x86 used secure_computing() for normal syscalls, and it was a good deal faster to have the arch code supply seccomp_data. x86 no longer works like this, and syscalls aren't fast anymore ayway :(

Uhuh, thanks Andy.

Christian, pls add that piece of history to the commit message.

Yip, will do. Thanks!

Christian

#6 lore raw
In reply to Andy Lutomirski
Quoted 8 lines · Andy Lutomirski
Quoted 7 lines · Borislav Petkov
Quoted 4 lines · Christian Brauner

While touching seccomp code I realized that the struct seccomp_data argument to secure_computing() seems to be unused by all current callers. So let's remove it unless there is some subtlety I missed. Note, I only tested this on x86.

Quoted 8 lines
Quoted 3 lines

What was amluto thinking in

2f275de5d1ed ("seccomp: Add a seccomp_data parameter secure_computing()")

IIRC there was a period of time in which x86 used secure_computing() for normal syscalls, and it was a good deal faster to have the arch code supply seccomp_data. x86 no longer works like this, and syscalls aren't fast anymore ayway :(

I started looking at this and actually had a slightly bigger cleanup in mind. It seems odd that we have secure_computing() and __secure_computing(). Especially in the mips and x86 case. From what I can tell they could both rely on secure_computing() and don't need __secure_computing().
If I can make those changes, we can make __secure_computing() static and have only a single function secure_computing() that is used by all arches which would make this code simpler.
Apparenly mips once switched from secure_computing() to __secure_computing() because of bpf and tracepoints. The last change to this was:

commit 3d729deaf287c43e415c5d791c9ac8414dbeff70

Author: James Hogan <[email protected]>
Date:   Fri Aug 11 21:56:50 2017 +0100

MIPS: seccomp: Fix indirect syscall args

which references a broken samples/bpf/tracex5 test. But in the thread to this last change Kees and others were less than sure that this makes sense. So I'm not sure. Maybe I should just try and send it out...

Christian

#7 lore raw

PATCH 1/1 seccomp: simplify secure_computing()

In reply to Christian Brauner

Afaict, the struct seccomp_data argument to secure_computing() is unused by all current callers. So let's remove it.
The argument was added in [1]. It was added because having the arch supply the syscall arguments used to be faster than having it done by secure_computing() (cf. Andy's comment in [2]). This is not true anymore though.

/* References */
[1]: 2f275de5d1ed ("seccomp: Add a seccomp_data parameter secure_computing()") [2]: https://lore.kernel.org/r/CALCETrU_fs_At-hTpr231kpaAd0z7xJN4ku-DvzhRU6cvcJA_w@mail.gmail.com

---
/* v1 */
- Borislav Petkov <[email protected]>:
- provide context for the arg addition to secure_computing() in the commit message

/* v0 */

---
 arch/arm/kernel/ptrace.c              | 2 +-
 arch/arm64/kernel/ptrace.c            | 2 +-
 arch/parisc/kernel/ptrace.c           | 2 +-
 arch/s390/kernel/ptrace.c             | 4 ++--
 arch/um/kernel/skas/syscall.c         | 2 +-
 arch/x86/entry/vsyscall/vsyscall_64.c | 2 +-
 include/linux/seccomp.h               | 6 +++---
 7 files changed, 10 insertions(+), 10 deletions(-)
arch/arm/kernel/ptrace.c +1 -1
index 324352787aea..b606cded90cd 100644
@@ -923,7 +923,7 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
 
 	/* Do seccomp after ptrace; syscall may have changed. */
 #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
-	if (secure_computing(NULL) == -1)
+	if (secure_computing() == -1)
 		return -1;
 #else
 	/* XXX: remove this once OABI gets fixed */
arch/arm64/kernel/ptrace.c +1 -1
index 3cf3b135027e..010a835302d3 100644
@@ -1816,7 +1816,7 @@ int syscall_trace_enter(struct pt_regs *regs)
 	}
 
 	/* Do the secure computing after ptrace; failures should be fast. */
-	if (secure_computing(NULL) == -1)
+	if (secure_computing() == -1)
 		return -1;
 
 	if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
arch/parisc/kernel/ptrace.c +1 -1
index 9f6ff7bc06f9..f8c07dcbfb49 100644
@@ -342,7 +342,7 @@ long do_syscall_trace_enter(struct pt_regs *regs)
 	}
 
 	/* Do the secure computing check after ptrace. */
-	if (secure_computing(NULL) == -1)
+	if (secure_computing() == -1)
 		return -1;
 
 #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
arch/s390/kernel/ptrace.c +2 -2
index ad71132374f0..ed80bdfbf5fe 100644
@@ -439,7 +439,7 @@ static int poke_user(struct task_struct *child, addr_t addr, addr_t data)
 long arch_ptrace(struct task_struct *child, long request,
 		 unsigned long addr, unsigned long data)
 {
-	ptrace_area parea; 
+	ptrace_area parea;
 	int copied, ret;
 
 	switch (request) {
@@ -856,7 +856,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
 	}
 
 	/* Do the secure computing check after ptrace. */
-	if (secure_computing(NULL)) {
+	if (secure_computing()) {
 		/* seccomp failures shouldn't expose any additional code. */
 		return -1;
 	}
arch/um/kernel/skas/syscall.c +1 -1
index 44bb10785075..fc37259d5971 100644
@@ -35,7 +35,7 @@ void handle_syscall(struct uml_pt_regs *r)
 		goto out;
 
 	/* Do the seccomp check after ptrace; failures should be fast. */
-	if (secure_computing(NULL) == -1)
+	if (secure_computing() == -1)
 		goto out;
 
 	syscall = UPT_SYSCALL_NR(r);
arch/x86/entry/vsyscall/vsyscall_64.c +1 -1
index e7c596dea947..b10cbf71a8cc 100644
@@ -222,7 +222,7 @@ bool emulate_vsyscall(unsigned long error_code,
 	 */
 	regs->orig_ax = syscall_nr;
 	regs->ax = -ENOSYS;
-	tmp = secure_computing(NULL);
+	tmp = secure_computing();
 	if ((!tmp && regs->orig_ax != syscall_nr) || regs->ip != address) {
 		warn_bad_vsyscall(KERN_DEBUG, regs,
 				  "seccomp tried to change syscall nr or ip");
include/linux/seccomp.h +3 -3
index 84868d37b35d..03583b6d1416 100644
@@ -33,10 +33,10 @@ struct seccomp {
 
 #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
 extern int __secure_computing(const struct seccomp_data *sd);
-static inline int secure_computing(const struct seccomp_data *sd)
+static inline int secure_computing(void)
 {
 	if (unlikely(test_thread_flag(TIF_SECCOMP)))
-		return  __secure_computing(sd);
+		return  __secure_computing(NULL);
 	return 0;
 }
 #else
@@ -59,7 +59,7 @@ struct seccomp { };
 struct seccomp_filter { };
 
 #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
-static inline int secure_computing(struct seccomp_data *sd) { return 0; }
+static inline int secure_computing(void) { return 0; }
 #else
 static inline void secure_computing_strict(int this_syscall) { return; }
 #endif
Signature · 7 lines
2.23.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Acked-by on v1 1/1
#8 lore raw

Re: [PATCH v1] seccomp: simplify secure_computing()

Quoted 31 lines · Christian Brauner

Afaict, the struct seccomp_data argument to secure_computing() is unused by all current callers. So let's remove it.
The argument was added in [1]. It was added because having the arch supply the syscall arguments used to be faster than having it done by secure_computing() (cf. Andy's comment in [2]). This is not true anymore though.

/* References */
[1]: 2f275de5d1ed ("seccomp: Add a seccomp_data parameter secure_computing()") [2]: https://lore.kernel.org/r/CALCETrU_fs_At-hTpr231kpaAd0z7xJN4ku-DvzhRU6cvcJA_w@mail.gmail.com

---
/* v1 */
- Borislav Petkov <[email protected]>:
- provide context for the arg addition to secure_computing() in the commit message

/* v0 */

Quoted 9 lines
---
 arch/arm/kernel/ptrace.c              | 2 +-
 arch/arm64/kernel/ptrace.c            | 2 +-
 arch/parisc/kernel/ptrace.c           | 2 +-
 arch/s390/kernel/ptrace.c             | 4 ++--
 arch/um/kernel/skas/syscall.c         | 2 +-
 arch/x86/entry/vsyscall/vsyscall_64.c | 2 +-
 include/linux/seccomp.h               | 6 +++---
 7 files changed, 10 insertions(+), 10 deletions(-)
Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer Acked-by on v1 1/1
#9 lore raw

Re: [PATCH v1] seccomp: simplify secure_computing()

In reply to Christian Brauner
Quoted 12 lines · Christian Brauner

Afaict, the struct seccomp_data argument to secure_computing() is unused by all current callers. So let's remove it.
The argument was added in [1]. It was added because having the arch supply the syscall arguments used to be faster than having it done by secure_computing() (cf. Andy's comment in [2]). This is not true anymore though.

/* References */
[1]: 2f275de5d1ed ("seccomp: Add a seccomp_data parameter secure_computing()") [2]: https://lore.kernel.org/r/CALCETrU_fs_At-hTpr231kpaAd0z7xJN4ku-DvzhRU6cvcJA_w@mail.gmail.com

Quoted 12 lines

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#10 lore raw

Re: [PATCH v1] seccomp: simplify secure_computing()

In reply to Christian Brauner
Quoted 6 lines · Christian Brauner

Afaict, the struct seccomp_data argument to secure_computing() is unused by all current callers. So let's remove it.
The argument was added in [1]. It was added because having the arch supply the syscall arguments used to be faster than having it done by secure_computing() (cf. Andy's comment in [2]). This is not true anymore though.

Yes; thanks for cleaning this up!

arch/s390/kernel/ptrace.c static int poke_user(struct task_struct *child, addr_t addr, addr_t data) · line 445

Quoted 13 lines
arch/s390/kernel/ptrace.c +1 -1
index ad71132374f0..ed80bdfbf5fe 100644
@@ -439,7 +439,7 @@ static int poke_user(struct task_struct *child, addr_t addr, addr_t data)
 long arch_ptrace(struct task_struct *child, long request,
 		 unsigned long addr, unsigned long data)
 {
-	ptrace_area parea; 
+	ptrace_area parea;
 	int copied, ret;
 
 	switch (request) {

If this were whitespace cleanup in kernel/seccomp.c, I'd take it without flinching. As this is only tangentially related and in an arch directory, I've dropped this hunk out of a cowardly fear of causing (a likely very unlikely) merge conflict.

I'd rather we globally clean up trailing whitespace at the end of -rc1 and ask Linus to run some crazy script. :)

So, with that hunk removed, I've applied this to for-next/seccomp. :)

Thanks!

Signature · 1 line
Kees Cook
#11 lore raw

Re: [PATCH v1] seccomp: simplify secure_computing()

Quoted 29 lines · Kees Cook
Quoted 6 lines · Christian Brauner

Afaict, the struct seccomp_data argument to secure_computing() is unused by all current callers. So let's remove it.
The argument was added in [1]. It was added because having the arch supply the syscall arguments used to be faster than having it done by secure_computing() (cf. Andy's comment in [2]). This is not true anymore though.

Yes; thanks for cleaning this up!

arch/s390/kernel/ptrace.c static int poke_user(struct task_struct *child, addr_t addr, addr_t data) · line 445

Quoted 13 lines
arch/s390/kernel/ptrace.c +1 -1
index ad71132374f0..ed80bdfbf5fe 100644
@@ -439,7 +439,7 @@ static int poke_user(struct task_struct *child, addr_t addr, addr_t data)
 long arch_ptrace(struct task_struct *child, long request,
 		 unsigned long addr, unsigned long data)
 {
-	ptrace_area parea; 
+	ptrace_area parea;
 	int copied, ret;
 
 	switch (request) {

If this were whitespace cleanup in kernel/seccomp.c, I'd take it without flinching. As this is only tangentially related and in an arch directory, I've dropped this hunk out of a cowardly fear of causing (a likely very unlikely) merge conflict.

Quoted 2 lines

I'd rather we globally clean up trailing whitespace at the end of -rc1 and ask Linus to run some crazy script. :)

Oh that was on accident probably. It usally happens because I have vim do whitespace fixups automatically and then they end up slipping in... Sorry. Thanks for removing it! :)

Christian

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel