Skip to contentSkip to conversation

Return EPERM not ECHILD on security_task_wait failure

PATCH In review James Morris 2 participants 5 messages Apr 23, 2007 – Apr 24, 2007

lore
Share & tools
lore
#0 lore raw
Quoted 2 lines · Roland McGrath

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

Signature · 2 lines
James Morris
<[email protected]>
#1 lore raw
Quoted 7 lines · Roland McGrath
Quoted 3 lines

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

#2 lore raw
Quoted 3 lines · Roland McGrath

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.

Signature · 2 lines
James Morris
<[email protected]>
#3 lore raw

PATCH 1/1 Return access error not ECHILD on security_task_wait failure

In reply to Roland McGrath

From: Roland McGrath <[email protected]>

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.

---

Updated version, returns value from security_task_wait().

 kernel/exit.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)
kernel/exit.c +15 -2
index b55ed4c..9236924 100644
@@ -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);
Signature · 1 line
1.5.0.6
#4 lore raw

Re: [PATCH try #2] Return access error not ECHILD on security_task_wait failure

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

Thanks,
Roland