mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH] Return EPERM not ECHILD on security_task_wait failure
@ 2007-04-23 23:43 James Morris
  2007-04-24  0:26 ` Roland McGrath
  0 siblings, 1 reply; 6+ messages in thread
From: James Morris @ 2007-04-23 23:43 UTC (permalink / raw)
  To: Roland McGrath; +Cc: linux-kernel, Stephen Smalley, Andrew Morton

On Thu, 15 Mar 2007, Roland McGrath wrote:

> This patch makes do_wait return -EPERM instead of -ECHILD if some
> children were ruled out solely because security_task_wait failed.

What about using the return value from the security_task_wait hook (which 
should be -EACCES) ?


- James
-- 
James Morris
<jmorris@namei.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Return EPERM not ECHILD on security_task_wait failure
  2007-04-23 23:43 [PATCH] Return EPERM not ECHILD on security_task_wait failure James Morris
@ 2007-04-24  0:26 ` Roland McGrath
  2007-04-24  0:38   ` James Morris
  2007-04-24  1:19   ` [PATCH try #2] Return access error " James Morris
  0 siblings, 2 replies; 6+ messages in thread
From: Roland McGrath @ 2007-04-24  0:26 UTC (permalink / raw)
  To: James Morris; +Cc: linux-kernel, Stephen Smalley, Andrew Morton

> On Thu, 15 Mar 2007, Roland McGrath wrote:
> 
> > This patch makes do_wait return -EPERM instead of -ECHILD if some
> > children were ruled out solely because security_task_wait failed.
> 
> What about using the return value from the security_task_wait hook (which 
> should be -EACCES) ?

As I said in some earlier discussion following my original patch, that
would be fine with me.  I haven't coded up that variant, but it's simple
enough.  Would you like to do it?


Thanks,
Roland

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Return EPERM not ECHILD on security_task_wait failure
  2007-04-24  0:26 ` Roland McGrath
@ 2007-04-24  0:38   ` James Morris
  2007-04-24  1:19   ` [PATCH try #2] Return access error " James Morris
  1 sibling, 0 replies; 6+ messages in thread
From: James Morris @ 2007-04-24  0:38 UTC (permalink / raw)
  To: Roland McGrath; +Cc: linux-kernel, Stephen Smalley, Andrew Morton

On Mon, 23 Apr 2007, Roland McGrath wrote:

> As I said in some earlier discussion following my original patch, that
> would be fine with me.  I haven't coded up that variant, but it's simple
> enough.  Would you like to do it?

Sure.


-- 
James Morris
<jmorris@namei.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH try #2] Return access error not ECHILD on security_task_wait failure
  2007-04-24  0:26 ` Roland McGrath
  2007-04-24  0:38   ` James Morris
@ 2007-04-24  1:19   ` James Morris
  2007-04-24  4:28     ` Roland McGrath
  1 sibling, 1 reply; 6+ messages in thread
From: James Morris @ 2007-04-24  1:19 UTC (permalink / raw)
  To: Roland McGrath; +Cc: linux-kernel, Stephen Smalley, Andrew Morton

From: Roland McGrath <roland@redhat.com>

wait* syscalls return -ECHILD even when an individual PID of a live child
was requested explicitly, when security_task_wait denies the operation.
This means that something like a broken SELinux policy can produce an
unexpected failure that looks just like a bug with wait or ptrace or
something.

This patch makes do_wait return -EACCES (or other appropriate
error returned from security_task_wait() instead of -ECHILD if some
children were ruled out solely because security_task_wait failed.

Signed-off-by: James Morris <jmorris@namei.org>
---

Updated version, returns value from security_task_wait().


 kernel/exit.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/kernel/exit.c b/kernel/exit.c
index b55ed4c..9236924 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -1033,6 +1033,8 @@ asmlinkage void sys_exit_group(int error_code)
 
 static int eligible_child(pid_t pid, int options, struct task_struct *p)
 {
+	int err;
+
 	if (pid > 0) {
 		if (p->pid != pid)
 			return 0;
@@ -1066,8 +1068,9 @@ static int eligible_child(pid_t pid, int options, struct task_struct *p)
 	if (delay_group_leader(p))
 		return 2;
 
-	if (security_task_wait(p))
-		return 0;
+	err = security_task_wait(p);
+	if (err)
+		return err;
 
 	return 1;
 }
@@ -1449,6 +1452,7 @@ static long do_wait(pid_t pid, int options, struct siginfo __user *infop,
 	DECLARE_WAITQUEUE(wait, current);
 	struct task_struct *tsk;
 	int flag, retval;
+	int allowed, denied;
 
 	add_wait_queue(&current->signal->wait_chldexit,&wait);
 repeat:
@@ -1457,6 +1461,7 @@ repeat:
 	 * match our criteria, even if we are not able to reap it yet.
 	 */
 	flag = 0;
+	allowed = denied = 0;
 	current->state = TASK_INTERRUPTIBLE;
 	read_lock(&tasklist_lock);
 	tsk = current;
@@ -1472,6 +1477,12 @@ repeat:
 			if (!ret)
 				continue;
 
+			if (unlikely(ret < 0)) {
+				denied = ret;
+				continue;
+			}
+			allowed = 1;
+
 			switch (p->state) {
 			case TASK_TRACED:
 				/*
@@ -1570,6 +1581,8 @@ check_continued:
 		goto repeat;
 	}
 	retval = -ECHILD;
+	if (unlikely(denied) && !allowed)
+		retval = denied;
 end:
 	current->state = TASK_RUNNING;
 	remove_wait_queue(&current->signal->wait_chldexit,&wait);
-- 
1.5.0.6


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH try #2] Return access error not ECHILD on security_task_wait failure
  2007-04-24  1:19   ` [PATCH try #2] Return access error " James Morris
@ 2007-04-24  4:28     ` Roland McGrath
  0 siblings, 0 replies; 6+ messages in thread
From: Roland McGrath @ 2007-04-24  4:28 UTC (permalink / raw)
  To: James Morris; +Cc: linux-kernel, Stephen Smalley, Andrew Morton

Not having tested it or anything, that looks good to me.


Thanks,
Roland

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] Return EPERM not ECHILD on security_task_wait failure
@ 2007-03-16  1:17 Roland McGrath
  0 siblings, 0 replies; 6+ messages in thread
From: Roland McGrath @ 2007-03-16  1:17 UTC (permalink / raw)
  To: Linus Torvalds, Andrew Morton; +Cc: linux-kernel

wait* syscalls return -ECHILD even when an individual PID of a live
child was requested explicitly, when security_task_wait denies the
operation.  This means that something like a broken SELinux policy
can produce an unexpected failure that looks just like a bug with
wait or ptrace or something.

This patch makes do_wait return -EPERM instead of -ECHILD if some
children were ruled out solely because security_task_wait failed.

Signed-off-by: Roland McGrath <roland@redhat.com>
---
 kernel/exit.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/kernel/exit.c b/kernel/exit.c
index f132349..a41052f 100644  
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -1067,7 +1067,7 @@ static int eligible_child(pid_t pid, int
 		return 2;
 
 	if (security_task_wait(p))
-		return 0;
+		return -1;
 
 	return 1;
 }
@@ -1449,6 +1449,7 @@ static long do_wait(pid_t pid, int optio
 	DECLARE_WAITQUEUE(wait, current);
 	struct task_struct *tsk;
 	int flag, retval;
+	int allowed, denied;
 
 	add_wait_queue(&current->signal->wait_chldexit,&wait);
 repeat:
@@ -1457,6 +1458,7 @@ repeat:
 	 * match our criteria, even if we are not able to reap it yet.
 	 */
 	flag = 0;
+	allowed = denied = 0;
 	current->state = TASK_INTERRUPTIBLE;
 	read_lock(&tasklist_lock);
 	tsk = current;
@@ -1472,6 +1474,12 @@ repeat:
 			if (!ret)
 				continue;
 
+			if (unlikely(ret < 0)) {
+				denied = 1;
+				continue;
+			}
+			allowed = 1;
+
 			switch (p->state) {
 			case TASK_TRACED:
 				/*
@@ -1570,6 +1578,8 @@ check_continued:
 		goto repeat;
 	}
 	retval = -ECHILD;
+	if (unlikely(denied) && !allowed)
+		retval = -EPERM;
 end:
 	current->state = TASK_RUNNING;
 	remove_wait_queue(&current->signal->wait_chldexit,&wait);

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-04-24  4:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-23 23:43 [PATCH] Return EPERM not ECHILD on security_task_wait failure James Morris
2007-04-24  0:26 ` Roland McGrath
2007-04-24  0:38   ` James Morris
2007-04-24  1:19   ` [PATCH try #2] Return access error " James Morris
2007-04-24  4:28     ` Roland McGrath
  -- strict thread matches above, loose matches on Subject: below --
2007-03-16  1:17 [PATCH] Return EPERM " Roland McGrath

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®