Skip to contentSkip to conversation

seccomp: Only dump core when single-threaded

PATCH In review Kees Cook 3 participants 6 messages Feb 7, 2017 – Feb 23, 2017 Secure computing

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 seccomp: Only dump core when single-threaded

The SECCOMP_RET_KILL filter return code has always killed the current thread, not the entire process. Changing this as a side-effect of dumping core isn't a safe thing to do (a few test suites have already flagged this behavioral change). Instead, restore the RET_KILL semantics, but still dump core when a RET_KILL delivers SIGSYS to a single-threaded process.

Fixes b25e67161c29 ("seccomp: dump core when using SECCOMP_RET_KILL")
---
 kernel/seccomp.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
kernel/seccomp.c +8 -5
index f8f88ebcb3ba..e15185c28de5 100644
@@ -643,11 +643,14 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,
 	default: {
 		siginfo_t info;
 		audit_seccomp(this_syscall, SIGSYS, action);
-		/* Show the original registers in the dump. */
-		syscall_rollback(current, task_pt_regs(current));
-		/* Trigger a manual coredump since do_exit skips it. */
-		seccomp_init_siginfo(&info, this_syscall, data);
-		do_coredump(&info);
+		/* Dump core only if this is the last remaining thread. */
+		if (get_nr_threads(current) == 1) {
+			/* Show the original registers in the dump. */
+			syscall_rollback(current, task_pt_regs(current));
+			/* Trigger a manual coredump since do_exit skips it. */
+			seccomp_init_siginfo(&info, this_syscall, data);
+			do_coredump(&info);
+		}
 		do_exit(SIGSYS);
 	}
 	}
Signature · 6 lines
2.7.4


-- 
Kees Cook
Pixel Security
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Kees Cook

The SECCOMP_RET_KILL filter return code has always killed the current thread, not the entire process. Changing this as a side-effect of dumping core isn't a safe thing to do (a few test suites have already flagged this behavioral change). Instead, restore the RET_KILL semantics, but still dump core when a RET_KILL delivers SIGSYS to a single-threaded process.

Fixes b25e67161c29 ("seccomp: dump core when using SECCOMP_RET_KILL")

All CRIU tests passed with this patch. Thanks!

Quoted 35 lines
---
 kernel/seccomp.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
kernel/seccomp.c +8 -5
index f8f88ebcb3ba..e15185c28de5 100644
@@ -643,11 +643,14 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,
 	default: {
 		siginfo_t info;
 		audit_seccomp(this_syscall, SIGSYS, action);
-		/* Show the original registers in the dump. */
-		syscall_rollback(current, task_pt_regs(current));
-		/* Trigger a manual coredump since do_exit skips it. */
-		seccomp_init_siginfo(&info, this_syscall, data);
-		do_coredump(&info);
+		/* Dump core only if this is the last remaining thread. */
+		if (get_nr_threads(current) == 1) {
+			/* Show the original registers in the dump. */
+			syscall_rollback(current, task_pt_regs(current));
+			/* Trigger a manual coredump since do_exit skips it. */
+			seccomp_init_siginfo(&info, this_syscall, data);
+			do_coredump(&info);
+		}
 		do_exit(SIGSYS);
 	}
 	}
Signature · 6 lines
2.7.4


-- 
Kees Cook
Pixel Security
author
#2 lore raw
Quoted 7 lines · Andrei Vagin
Quoted 6 lines · Kees Cook

The SECCOMP_RET_KILL filter return code has always killed the current thread, not the entire process. Changing this as a side-effect of dumping core isn't a safe thing to do (a few test suites have already flagged this behavioral change). Instead, restore the RET_KILL semantics, but still dump core when a RET_KILL delivers SIGSYS to a single-threaded process.

Quoted 6 lines
Quoted 2 lines
Fixes b25e67161c29 ("seccomp: dump core when using SECCOMP_RET_KILL")

All CRIU tests passed with this patch. Thanks!

Thanks for testing!

James, can you make sure this makes it into your -next tree for v4.11?

Thanks!

-Kees

Quoted 36 lines
Quoted 36 lines
---
 kernel/seccomp.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
kernel/seccomp.c +8 -6
index f8f88ebcb3ba..e15185c28de5 100644
@@ -643,11 +643,14 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,
      default: {
              siginfo_t info;
              audit_seccomp(this_syscall, SIGSYS, action);
-             /* Show the original registers in the dump. */
-             syscall_rollback(current, task_pt_regs(current));
-             /* Trigger a manual coredump since do_exit skips it. */
-             seccomp_init_siginfo(&info, this_syscall, data);
-             do_coredump(&info);
+             /* Dump core only if this is the last remaining thread. */
+             if (get_nr_threads(current) == 1) {
+                     /* Show the original registers in the dump. */
+                     syscall_rollback(current, task_pt_regs(current));
+                     /* Trigger a manual coredump since do_exit skips it. */
+                     seccomp_init_siginfo(&info, this_syscall, data);
+                     do_coredump(&info);
+             }
              do_exit(SIGSYS);
      }
      }
--

2.7.4

--
Kees Cook
Pixel Security

Signature · 2 lines
Kees Cook
Pixel Security
#3 lore raw
Quoted 1 line · Kees Cook

James, can you make sure this makes it into your -next tree for v4.11?

Queued for next at:

git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security.git#next-queue

Signature · 2 lines
James Morris
<[email protected]>
#4 lore raw
Quoted 7 lines · James Morris
Quoted 1 line · Kees Cook

James, can you make sure this makes it into your -next tree for v4.11?

Queued for next at:

git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security.git#next-queue

The b25e67161c29 ("seccomp: dump core when using SECCOMP_RET_KILL") is in the Linus' tree, but this patch isn't there yet. And I don't see it event in linux-next.

Do you have any plan to push it into the linus' tree?

https://travis-ci.org/avagin/criu/builds/204341051

Thanks,
Andrei

Quoted 5 lines
Signature · 3 lines
-- 
James Morris
<[email protected]>
author
#5 lore raw
Quoted 9 lines · Andrei Vagin
Quoted 7 lines · James Morris
Quoted 1 line · Kees Cook

James, can you make sure this makes it into your -next tree for v4.11?

Queued for next at:

git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security.git#next-queue

Quoted 7 lines

The b25e67161c29 ("seccomp: dump core when using SECCOMP_RET_KILL") is in the Linus' tree, but this patch isn't there yet. And I don't see it event in linux-next.

Do you have any plan to push it into the linus' tree?

https://travis-ci.org/avagin/criu/builds/204341051

Yup, I already called James's attention to this. He just sent a pull request with the fix.

-Kees

Signature · 2 lines
Kees Cook
Pixel Security