Skip to contentSkip to conversation

seccomp: do not reject initial filter using TSYNC

PATCH In review Kees Cook 2 participants 5 messages Jul 17, 2014 Secure computing

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 seccomp: do not reject initial filter using TSYNC

There was an unneeded sanity check in the TSYNC code that was causing the first filter applied to not allow the TSYNC flag. Additionally, this optimizes the thread loops to skip "current". It was harmless, but better to not cause problems in the future.

---
This goes on top of the v11 seccomp-tsync series. If I should respin as v12, please let me know.

Thanks!

---
 kernel/seccomp.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
kernel/seccomp.c +8 -3
index 2125b83ccfd4..0e0c6905b81d 100644
@@ -255,14 +255,15 @@ static inline pid_t seccomp_can_sync_threads(void)
 	BUG_ON(!mutex_is_locked(&current->signal->cred_guard_mutex));
 	BUG_ON(!spin_is_locked(&current->sighand->siglock));
 
-	if (current->seccomp.mode != SECCOMP_MODE_FILTER)
-		return -EACCES;
-
 	/* Validate all threads being eligible for synchronization. */
 	caller = current;
 	for_each_thread(caller, thread) {
 		pid_t failed;
 
+		/* Skip current, since it is initiating the sync. */
+		if (thread == current)
+			continue;
+
 		if (thread->seccomp.mode == SECCOMP_MODE_DISABLED ||
 		    (thread->seccomp.mode == SECCOMP_MODE_FILTER &&
 		     is_ancestor(thread->seccomp.filter,
@@ -298,6 +299,10 @@ static inline void seccomp_sync_threads(void)
 	/* Synchronize all threads. */
 	caller = current;
 	for_each_thread(caller, thread) {
+		/* Skip current, since it needs no changes. */
+		if (thread == current)
+			continue;
+
 		/* Get a task reference for the new leaf node. */
 		get_seccomp_filter(caller);
 		/*
Signature · 6 lines
1.7.9.5


-- 
Kees Cook
Chrome OS Security
#1 lore raw
Quoted 26 lines · Kees Cook

There was an unneeded sanity check in the TSYNC code that was causing the first filter applied to not allow the TSYNC flag. Additionally, this optimizes the thread loops to skip "current". It was harmless, but better to not cause problems in the future.

---
This goes on top of the v11 seccomp-tsync series. If I should respin as v12, please let me know.

Thanks!

---
 kernel/seccomp.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
kernel/seccomp.c +0 -2
index 2125b83ccfd4..0e0c6905b81d 100644
@@ -255,14 +255,15 @@ static inline pid_t seccomp_can_sync_threads(void)
        BUG_ON(!mutex_is_locked(&current->signal->cred_guard_mutex));
        BUG_ON(!spin_is_locked(&current->sighand->siglock));
 
-       if (current->seccomp.mode != SECCOMP_MODE_FILTER)
-               return -EACCES;

kernel/seccomp.c static inline pid_t seccomp_can_sync_threads(void) · line 266

Quoted 10 lines
kernel/seccomp.c +4 -1
-
        /* Validate all threads being eligible for synchronization. */
        caller = current;
        for_each_thread(caller, thread) {
                pid_t failed;
 
+               /* Skip current, since it is initiating the sync. */
+               if (thread == current)
+                       continue;
+

Should that be "thread == caller"?

--Andy

author
#2 lore raw
Quoted 33 lines · Andy Lutomirski
Quoted 32 lines · Kees Cook

There was an unneeded sanity check in the TSYNC code that was causing the first filter applied to not allow the TSYNC flag. Additionally, this optimizes the thread loops to skip "current". It was harmless, but better to not cause problems in the future.

---
This goes on top of the v11 seccomp-tsync series. If I should respin as v12, please let me know.

Thanks!

---
 kernel/seccomp.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
kernel/seccomp.c +0 -3
index 2125b83ccfd4..0e0c6905b81d 100644
@@ -255,14 +255,15 @@ static inline pid_t seccomp_can_sync_threads(void)
        BUG_ON(!mutex_is_locked(&current->signal->cred_guard_mutex));
        BUG_ON(!spin_is_locked(&current->sighand->siglock));
 
-       if (current->seccomp.mode != SECCOMP_MODE_FILTER)
-               return -EACCES;
-
        /* Validate all threads being eligible for synchronization. */
        caller = current;
        for_each_thread(caller, thread) {
                pid_t failed;
 
Quoted 6 lines

kernel/seccomp.c static inline pid_t seccomp_can_sync_threads(void) · line 266

Quoted 4 lines
kernel/seccomp.c +4 -0
+               /* Skip current, since it is initiating the sync. */
+               if (thread == current)
+                       continue;
+

Should that be "thread == caller"?

caller shouldn't be changing, correct? Won't it be the same?

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security
#3 lore raw
Quoted 34 lines · Kees Cook
Quoted 33 lines · Andy Lutomirski
Quoted 32 lines · Kees Cook

There was an unneeded sanity check in the TSYNC code that was causing the first filter applied to not allow the TSYNC flag. Additionally, this optimizes the thread loops to skip "current". It was harmless, but better to not cause problems in the future.

---
This goes on top of the v11 seccomp-tsync series. If I should respin as v12, please let me know.

Thanks!

---
 kernel/seccomp.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
kernel/seccomp.c +0 -3
index 2125b83ccfd4..0e0c6905b81d 100644
@@ -255,14 +255,15 @@ static inline pid_t seccomp_can_sync_threads(void)
        BUG_ON(!mutex_is_locked(&current->signal->cred_guard_mutex));
        BUG_ON(!spin_is_locked(&current->sighand->siglock));
 
-       if (current->seccomp.mode != SECCOMP_MODE_FILTER)
-               return -EACCES;
-
        /* Validate all threads being eligible for synchronization. */
        caller = current;
        for_each_thread(caller, thread) {
                pid_t failed;
 
Quoted 9 lines
Quoted 6 lines

kernel/seccomp.c static inline pid_t seccomp_can_sync_threads(void) · line 266

Quoted 4 lines
kernel/seccomp.c +4 -0
+               /* Skip current, since it is initiating the sync. */
+               if (thread == current)
+                       continue;
+

Should that be "thread == caller"?

caller shouldn't be changing, correct? Won't it be the same?

I assumed that you loaded caller once as an optimization -- ISTR that, at least at some point, accessing current was a slightly expensive. Maybe this is moot now.

Anyway, the rest of the code in there is comparing thread to caller, using caller seems a bit more consistent.

--Andy

Quoted 5 lines

-Kees

--
Kees Cook
Chrome OS Security

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
author
#4 lore raw
Quoted 45 lines · Andy Lutomirski
Quoted 34 lines · Kees Cook
Quoted 33 lines · Andy Lutomirski
Quoted 32 lines · Kees Cook

There was an unneeded sanity check in the TSYNC code that was causing the first filter applied to not allow the TSYNC flag. Additionally, this optimizes the thread loops to skip "current". It was harmless, but better to not cause problems in the future.

---
This goes on top of the v11 seccomp-tsync series. If I should respin as v12, please let me know.

Thanks!

---
 kernel/seccomp.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
kernel/seccomp.c +0 -3
index 2125b83ccfd4..0e0c6905b81d 100644
@@ -255,14 +255,15 @@ static inline pid_t seccomp_can_sync_threads(void)
        BUG_ON(!mutex_is_locked(&current->signal->cred_guard_mutex));
        BUG_ON(!spin_is_locked(&current->sighand->siglock));
 
-       if (current->seccomp.mode != SECCOMP_MODE_FILTER)
-               return -EACCES;
-
        /* Validate all threads being eligible for synchronization. */
        caller = current;
        for_each_thread(caller, thread) {
                pid_t failed;
 
Quoted 9 lines
Quoted 6 lines

kernel/seccomp.c static inline pid_t seccomp_can_sync_threads(void) · line 266

Quoted 4 lines
kernel/seccomp.c +4 -0
+               /* Skip current, since it is initiating the sync. */
+               if (thread == current)
+                       continue;
+

Should that be "thread == caller"?

caller shouldn't be changing, correct? Won't it be the same?

Quoted 6 lines

I assumed that you loaded caller once as an optimization -- ISTR that, at least at some point, accessing current was a slightly expensive. Maybe this is moot now.

Anyway, the rest of the code in there is comparing thread to caller, using caller seems a bit more consistent.

Fair enough. :)

I'll resend with this folded in for a v12.

Thanks!

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security