kill_pid_info_as_uid: don't use security_task_kill()
PATCH 2/3 kill_pid_info_as_uid: don't use security_task_kill()
kill_pid_info_as_uid() is solely used by drivers/usb/core/. The original "[PATCH] Fix signal sending in usbdevio on async URB completion" commit 46113830a18847cff8da73005e57bc49c2f95a56 was right, but nowadays we use struct pid and this solves most of the addressed problems.
It would be nice to use kill_pid_info() instead, but we can't because USB uses .si_code = SI_ASYNCIO which fools SI_FROMUSER() and thus security checks.
I think we should omit the permission checks completely, the task which does ioctl(USBDEVFS_SUBMITURB) explicitly asks to send the signal to it, we should not deny the signal even if the task changes its credentials in any way.
For now, we can remove security_task_kill(). It is bogus, the signal has come from kernel.
include/linux/sched.h | 2 +- kernel/signal.c | 5 +---- drivers/usb/core/usb.h | 1 - drivers/usb/core/devio.c | 7 ++----- drivers/usb/core/inode.c | 3 ++- 5 files changed, 6 insertions(+), 12 deletions(-)
include/linux/sched.h renamed from include/linux/sched.h~2_KPIAU_NO_LSM +1 -1
@@ -1690,7 +1690,7 @@ extern int force_sigsegv(int, struct tasextern int force_sig_info (int ,struct siginfo *,struct task_struct *);extern int __kill_pgrp_info (int sig,struct siginfo *info,struct pid *pgrp);extern int kill_pid_info (int sig,struct siginfo *info,struct pid *pid); -extern int kill_pid_info_as_uid (int ,struct siginfo *,struct pid *,uid_t ,uid_t ,u32 ); +extern int kill_pid_info_as_uid (int ,struct siginfo *,struct pid *,uid_t ,uid_t );extern int kill_pgrp (struct pid *pid,int sig,int priv);extern int kill_pid (struct pid *pid,int sig,int priv);extern int kill_proc_info (int ,struct siginfo *,pid_t );
kernel/signal.c renamed from kernel/signal.c~2_KPIAU_NO_LSM +1 -4
@@ -1078,7 +1078,7 @@ kill_proc_info(int sig, struct siginfo */* like kill_pid_info(), but doesn't use uid/euid of "current" */ int kill_pid_info_as_uid (int sig,struct siginfo *info,struct pid *pid, -uid_t uid,uid_t euid,u32 secid) +uid_t uid,uid_t euid) {int ret = -EINVAL ;struct task_struct *p;
@@ -1098,9 +1098,6 @@ int kill_pid_info_as_uid(int sig, struct ret = -EPERM ; goto out_unlock; } - ret =security_task_kill (p, info, sig, secid); -if (ret) - goto out_unlock;if (sig && p->sighand) {unsigned long flags;spin_lock_irqsave (&p->sighand->siglock, flags);
drivers/usb/core/usb.h renamed from drivers/usb/core/usb.h~2_KPIAU_NO_LSM +0 -1
@@ -155,7 +155,6 @@ struct dev_state {uid_t disc_uid, disc_euid;void __user *disccontext;unsigned long ifclaimed; -u32 secid; };/* internal notify stuff */
drivers/usb/core/devio.c renamed from drivers/usb/core/devio.c~2_KPIAU_NO_LSM +2 -5
@@ -72,7 +72,6 @@ struct async {void __user *userurb;struct urb *urb;int status; -u32 secid; };static int usbfs_snoop;
@@ -321,8 +320,8 @@ static void async_completed(struct urb * sinfo.si_errno = as->status; sinfo.si_code =SI_ASYNCIO ; sinfo.si_addr = as->userurb; -kill_pid_info_as_uid (as->signr, &sinfo, as->pid, as->uid, - as->euid, as->secid); +kill_pid_info_as_uid (as->signr, &sinfo, as->pid, + as->uid, as->euid); }snoop (&urb->dev->dev,"urb complete\n" );snoop_urb (urb, as->userurb);
@@ -603,7 +602,6 @@ static int usbdev_open(struct inode *ino ps->disc_euid = current->euid; ps->disccontext =NULL ; ps->ifclaimed =0 ; -security_task_getsecid (current, &ps->secid);smp_wmb ();list_add_tail (&ps->list, &dev->filelist); file->private_data = ps;
@@ -1132,7 +1130,6 @@ static int proc_do_submiturb(struct dev_ as->pid =get_pid (task_pid (current)); as->uid = current->uid; as->euid = current->euid; -security_task_getsecid (current, &as->secid);if (!is_in) {if (copy_from_user (as->urb->transfer_buffer, uurb->buffer, as->urb->transfer_buffer_length)) {
drivers/usb/core/inode.c renamed from drivers/usb/core/inode.c~2_KPIAU_NO_LSM +2 -1
@@ -728,7 +728,8 @@ static void usbfs_remove_device(struct u sinfo.si_errno =EPIPE ; sinfo.si_code =SI_ASYNCIO ; sinfo.si_addr = ds->disccontext; -kill_pid_info_as_uid (ds->discsignr, &sinfo, ds->disc_pid, ds->disc_uid, ds->disc_euid, ds->secid); +kill_pid_info_as_uid (ds->discsignr, &sinfo, ds->disc_pid, + ds->disc_uid, ds->disc_euid); } } }
Quoted 8 lines · Oleg Nesterov
kill_pid_info_as_uid()is solely used bydrivers/usb/core/. The original "[PATCH] Fix signal sending in usbdevio on async URB completion" commit46113830a18847cff8da73005e57bc49c2f95a56was right, but nowadays we use struct pid and this solves most of the addressed problems.It would be nice to use
kill_pid_info()instead, but we can't because USB uses .si_code =SI_ASYNCIOwhich foolsSI_FROMUSER()and thus security checks.
Quoted 6 lines
I think we should omit the permission checks completely, the task which does
ioctl(USBDEVFS_SUBMITURB)explicitly asks to send the signal to it, we should not deny the signal even if the task changes its credentials in any way.For now, we can remove
security_task_kill(). It is bogus, the signal has come from kernel.
Ok, could you augment the comment above kernel/signal.c:kill_pid_info_as_uid() to say that it is only called from within the usb subsystem?
It also would be nice if some sparse magic could check that that remains the case, but that's 'vali' territory and the comment should suffice.
thanks,
-serge
Quoted 100 lines
Signed-off-by Oleg Nesterov <[email protected]>include/linux/sched.h | 2 +- kernel/signal.c | 5 +---- drivers/usb/core/usb.h | 1 - drivers/usb/core/devio.c | 7 ++----- drivers/usb/core/inode.c | 3 ++- 5 files changed, 6 insertions(+), 12 deletions(-)include/linux/sched.h renamed from include/linux/sched.h~2_KPIAU_NO_LSM +1
-1@@ -1690,7 +1690,7 @@ extern int force_sigsegv(int, struct tasextern int force_sig_info (int ,struct siginfo *,struct task_struct *);extern int __kill_pgrp_info (int sig,struct siginfo *info,struct pid *pgrp);extern int kill_pid_info (int sig,struct siginfo *info,struct pid *pid); -extern int kill_pid_info_as_uid (int ,struct siginfo *,struct pid *,uid_t ,uid_t ,u32 ); +extern int kill_pid_info_as_uid (int ,struct siginfo *,struct pid *,uid_t ,uid_t );extern int kill_pgrp (struct pid *pid,int sig,int priv);extern int kill_pid (struct pid *pid,int sig,int priv);extern int kill_proc_info (int ,struct siginfo *,pid_t );kernel/signal.c renamed from kernel/signal.c~2_KPIAU_NO_LSM +1
-4@@ -1078,7 +1078,7 @@ kill_proc_info(int sig, struct siginfo */* like kill_pid_info(), but doesn't use uid/euid of "current" */ int kill_pid_info_as_uid (int sig,struct siginfo *info,struct pid *pid, -uid_t uid,uid_t euid,u32 secid) +uid_t uid,uid_t euid) {int ret = -EINVAL ;struct task_struct *p;@@ -1098,9 +1098,6 @@ int kill_pid_info_as_uid(int sig, struct ret = -EPERM ; goto out_unlock; } - ret =security_task_kill (p, info, sig, secid); -if (ret) - goto out_unlock;if (sig && p->sighand) {unsigned long flags;spin_lock_irqsave (&p->sighand->siglock, flags);drivers/usb/core/usb.h renamed from drivers/usb/core/usb.h~2_KPIAU_NO_LSM +0
-1@@ -155,7 +155,6 @@ struct dev_state {uid_t disc_uid, disc_euid;void __user *disccontext;unsigned long ifclaimed; -u32 secid; };/* internal notify stuff */ drivers/usb/core/devio.c renamed from drivers/usb/core/devio.c~2_KPIAU_NO_LSM +2
-5@@ -72,7 +72,6 @@ struct async {void __user *userurb;struct urb *urb;int status; -u32 secid; };static int usbfs_snoop;@@ -321,8 +320,8 @@ static void async_completed(struct urb * sinfo.si_errno = as->status; sinfo.si_code =SI_ASYNCIO ; sinfo.si_addr = as->userurb; -kill_pid_info_as_uid (as->signr, &sinfo, as->pid, as->uid, - as->euid, as->secid); +kill_pid_info_as_uid (as->signr, &sinfo, as->pid, + as->uid, as->euid); }snoop (&urb->dev->dev,"urb complete\n" );snoop_urb (urb, as->userurb);@@ -603,7 +602,6 @@ static int usbdev_open(struct inode *ino ps->disc_euid = current->euid; ps->disccontext =NULL ; ps->ifclaimed =0 ; -security_task_getsecid (current, &ps->secid);smp_wmb ();list_add_tail (&ps->list, &dev->filelist); file->private_data = ps;@@ -1132,7 +1130,6 @@ static int proc_do_submiturb(struct dev_ as->pid =get_pid (task_pid (current)); as->uid = current->uid; as->euid = current->euid; -security_task_getsecid (current, &as->secid);if (!is_in) {if (copy_from_user (as->urb->transfer_buffer, uurb->buffer, as->urb->transfer_buffer_length)) {drivers/usb/core/inode.c renamed from drivers/usb/core/inode.c~2_KPIAU_NO_LSM +2
-1@@ -728,7 +728,8 @@ static void usbfs_remove_device(struct u sinfo.si_errno =EPIPE ; sinfo.si_code =SI_ASYNCIO ; sinfo.si_addr = ds->disccontext; -kill_pid_info_as_uid (ds->discsignr, &sinfo, ds->disc_pid, ds->disc_uid, ds->disc_euid, ds->secid); +kill_pid_info_as_uid (ds->discsignr, &sinfo, ds->disc_pid, + ds->disc_uid, ds->disc_euid); } } }
Quoted 14 lines · Serge E. Hallyn
Quoted 12 lines · Oleg Nesterov
kill_pid_info_as_uid()is solely used bydrivers/usb/core/. The original "[PATCH] Fix signal sending in usbdevio on async URB completion" commit46113830a18847cff8da73005e57bc49c2f95a56was right, but nowadays we use struct pid and this solves most of the addressed problems.It would be nice to use
kill_pid_info()instead, but we can't because USB uses .si_code =SI_ASYNCIOwhich foolsSI_FROMUSER()and thus security checks.I think we should omit the permission checks completely, the task which does
ioctl(USBDEVFS_SUBMITURB)explicitly asks to send the signal to it, we should not deny the signal even if the task changes its credentials in any way.
Quoted 6 lines
Quoted 2 lines
For now, we can remove
security_task_kill(). It is bogus, the signal has come from kernel.Ok, could you augment the comment above kernel/signal.c:kill_pid_info_as_uid() to say that it is only called from within the usb subsystem?
OK, will do a bit later. I still hope we can kill this helper or at least cleanup it further.
What we need in fact is kill_pid_info_skip_check_kill_permission(), and only because USB uses SI_ASYNCIO < 0.
Oleg.
Quoted 11 lines · Oleg Nesterov
kill_pid_info_as_uid()is solely used bydrivers/usb/core/. The original "[PATCH] Fix signal sending in usbdevio on async URB completion" commit46113830a18847cff8da73005e57bc49c2f95a56was right, but nowadays we use struct pid and this solves most of the addressed problems.It would be nice to use
kill_pid_info()instead, but we can't because USB uses .si_code =SI_ASYNCIOwhich foolsSI_FROMUSER()and thus security checks.I think we should omit the permission checks completely, the task which does
ioctl(USBDEVFS_SUBMITURB)explicitly asks to send the signal to it, we should not deny the signal even if the task changes its credentials in any way.
If we are applying checks based on uid/gid to protect suid/sgid programs, then we ought to also invoke the LSM hook to allow protection of other credential-changing transformations, like SELinux context transitions. You either remove all checking or none, please. And if all, what's the rationale?
Quoted 103 lines
For now, we can remove
security_task_kill(). It is bogus, the signal has come from kernel.Signed-off-by Oleg Nesterov <[email protected]>include/linux/sched.h | 2 +- kernel/signal.c | 5 +---- drivers/usb/core/usb.h | 1 - drivers/usb/core/devio.c | 7 ++----- drivers/usb/core/inode.c | 3 ++- 5 files changed, 6 insertions(+), 12 deletions(-)include/linux/sched.h renamed from include/linux/sched.h~2_KPIAU_NO_LSM +1
-1@@ -1690,7 +1690,7 @@ extern int force_sigsegv(int, struct tasextern int force_sig_info (int ,struct siginfo *,struct task_struct *);extern int __kill_pgrp_info (int sig,struct siginfo *info,struct pid *pgrp);extern int kill_pid_info (int sig,struct siginfo *info,struct pid *pid); -extern int kill_pid_info_as_uid (int ,struct siginfo *,struct pid *,uid_t ,uid_t ,u32 ); +extern int kill_pid_info_as_uid (int ,struct siginfo *,struct pid *,uid_t ,uid_t );extern int kill_pgrp (struct pid *pid,int sig,int priv);extern int kill_pid (struct pid *pid,int sig,int priv);extern int kill_proc_info (int ,struct siginfo *,pid_t );kernel/signal.c renamed from kernel/signal.c~2_KPIAU_NO_LSM +1
-4@@ -1078,7 +1078,7 @@ kill_proc_info(int sig, struct siginfo */* like kill_pid_info(), but doesn't use uid/euid of "current" */ int kill_pid_info_as_uid (int sig,struct siginfo *info,struct pid *pid, -uid_t uid,uid_t euid,u32 secid) +uid_t uid,uid_t euid) {int ret = -EINVAL ;struct task_struct *p;@@ -1098,9 +1098,6 @@ int kill_pid_info_as_uid(int sig, struct ret = -EPERM ; goto out_unlock; } - ret =security_task_kill (p, info, sig, secid); -if (ret) - goto out_unlock;if (sig && p->sighand) {unsigned long flags;spin_lock_irqsave (&p->sighand->siglock, flags);drivers/usb/core/usb.h renamed from drivers/usb/core/usb.h~2_KPIAU_NO_LSM +0
-1@@ -155,7 +155,6 @@ struct dev_state {uid_t disc_uid, disc_euid;void __user *disccontext;unsigned long ifclaimed; -u32 secid; };/* internal notify stuff */ drivers/usb/core/devio.c renamed from drivers/usb/core/devio.c~2_KPIAU_NO_LSM +2
-5@@ -72,7 +72,6 @@ struct async {void __user *userurb;struct urb *urb;int status; -u32 secid; };static int usbfs_snoop;@@ -321,8 +320,8 @@ static void async_completed(struct urb * sinfo.si_errno = as->status; sinfo.si_code =SI_ASYNCIO ; sinfo.si_addr = as->userurb; -kill_pid_info_as_uid (as->signr, &sinfo, as->pid, as->uid, - as->euid, as->secid); +kill_pid_info_as_uid (as->signr, &sinfo, as->pid, + as->uid, as->euid); }snoop (&urb->dev->dev,"urb complete\n" );snoop_urb (urb, as->userurb);@@ -603,7 +602,6 @@ static int usbdev_open(struct inode *ino ps->disc_euid = current->euid; ps->disccontext =NULL ; ps->ifclaimed =0 ; -security_task_getsecid (current, &ps->secid);smp_wmb ();list_add_tail (&ps->list, &dev->filelist); file->private_data = ps;@@ -1132,7 +1130,6 @@ static int proc_do_submiturb(struct dev_ as->pid =get_pid (task_pid (current)); as->uid = current->uid; as->euid = current->euid; -security_task_getsecid (current, &as->secid);if (!is_in) {if (copy_from_user (as->urb->transfer_buffer, uurb->buffer, as->urb->transfer_buffer_length)) {drivers/usb/core/inode.c renamed from drivers/usb/core/inode.c~2_KPIAU_NO_LSM +2
-1@@ -728,7 +728,8 @@ static void usbfs_remove_device(struct u sinfo.si_errno =EPIPE ; sinfo.si_code =SI_ASYNCIO ; sinfo.si_addr = ds->disccontext; -kill_pid_info_as_uid (ds->discsignr, &sinfo, ds->disc_pid, ds->disc_uid, ds->disc_euid, ds->secid); +kill_pid_info_as_uid (ds->discsignr, &sinfo, ds->disc_pid, + ds->disc_uid, ds->disc_euid); } } }
Signature · 2 lines
Stephen Smalley National Security Agency
Quoted 10 lines · Stephen Smalley
Quoted 8 lines · Oleg Nesterov
kill_pid_info_as_uid()is solely used bydrivers/usb/core/. The original "[PATCH] Fix signal sending in usbdevio on async URB completion" commit46113830a18847cff8da73005e57bc49c2f95a56was right, but nowadays we use struct pid and this solves most of the addressed problems.It would be nice to use
kill_pid_info()instead, but we can't because USB uses .si_code =SI_ASYNCIOwhich foolsSI_FROMUSER()and thus security checks.
Quoted 8 lines
Quoted 3 lines
I think we should omit the permission checks completely, the task which does
ioctl(USBDEVFS_SUBMITURB)explicitly asks to send the signal to it, we should not deny the signal even if the task changes its credentials in any way.If we are applying checks based on uid/gid to protect suid/sgid programs, then we ought to also invoke the LSM hook to allow protection of other credential-changing transformations, like SELinux context transitions. You either remove all checking or none, please.
Yes, you are right. I'd like to remove all uid/euid checks. This patch doesn't do this because
- perhaps it will be possible to kill this helper
- if we remove these checks, we should do some subsequent cleanups in drivers/usb/core/, while this series is all about LSM hooks.
I am going to do this later.
Quoted 1 line
And if all, what's the rationale?
I think it is not good that LSM has some special (and unneeded!) hacks for USB. Please also look at the next patch.
Do you agree?
Oleg.
Quoted 16 lines · Oleg Nesterov
Quoted 14 lines · Stephen Smalley
Quoted 11 lines · Oleg Nesterov
kill_pid_info_as_uid()is solely used bydrivers/usb/core/. The original "[PATCH] Fix signal sending in usbdevio on async URB completion" commit46113830a18847cff8da73005e57bc49c2f95a56was right, but nowadays we use struct pid and this solves most of the addressed problems.It would be nice to use
kill_pid_info()instead, but we can't because USB uses .si_code =SI_ASYNCIOwhich foolsSI_FROMUSER()and thus security checks.I think we should omit the permission checks completely, the task which does
ioctl(USBDEVFS_SUBMITURB)explicitly asks to send the signal to it, we should not deny the signal even if the task changes its credentials in any way.
Quoted 6 lines
Quoted 4 lines
If we are applying checks based on uid/gid to protect suid/sgid programs, then we ought to also invoke the LSM hook to allow protection of other credential-changing transformations, like SELinux context transitions. You either remove all checking or none, please.
Yes, you are right. I'd like to remove all uid/euid checks.
Actually, I may be wrong, sorry. If the task does setuid exec, we probably should do these checks.
OK, please ignore 2nd and 3rd patches.
Still. The usage of security_task_kill(secid) doesn't look good, imho. We have the similar issues with send_sigio(). In that case we use security_file_send_sigiotask(), not security_task_kill().
Oleg.
Quoted 6 lines · --- Stephen Smalley
...
Quoted 2 lines
I think we should omit the permission checks completely, the task which
does
Quoted 1 line
ioctl(USBDEVFS_SUBMITURB)explicitly asks to send the signal to it, we
Quoted 8 lines
should
Quoted 1 line
not deny the signal even if the task changes its credentials in any way.
If we are applying checks based on uid/gid to protect suid/sgid programs, then we ought to also invoke the LSM hook to allow protection of other credential-changing transformations, like SELinux context transitions. You either remove all checking or none, please. And if all, what's the rationale?
Perhaps more important to my mind is what lead the developers of this code to go to such significant lengths to provide this access check in the first place. Why was it considered sufficiently important? I concur that it's an ugly bit of hackery, but someone must have felt it was necessary or they wouldn't have done it.
Casey Schaufler
[email protected]
Quoted 18 lines · Casey Schaufler
Quoted 6 lines · --- Stephen Smalley
...
Quoted 2 lines
I think we should omit the permission checks completely, the task which
does
Quoted 1 line
ioctl(USBDEVFS_SUBMITURB)explicitly asks to send the signal to it, weQuoted 8 lines
should
Quoted 1 line
not deny the signal even if the task changes its credentials in any way.
If we are applying checks based on uid/gid to protect suid/sgid programs, then we ought to also invoke the LSM hook to allow protection of other credential-changing transformations, like SELinux context transitions. You either remove all checking or none, please. And if all, what's the rationale?
Quoted 5 lines
Perhaps more important to my mind is what lead the developers of this code to go to such significant lengths to provide this access check in the first place. Why was it considered sufficiently important? I concur that it's an ugly bit of hackery, but someone must have felt it was necessary or they wouldn't have done it.
Previously, USB used "pid_t pid" as a target for the signal. This pid could be reused by the completely unrelated process, these checks ensure that we at least doesn't kill the wrong user in this case.
Now we are using "struct pid", this means that the signal always goes to the "right" task.
Oleg.