usb, signal, security: only pass the cred, not the secid, to kill_pid_info_as_cred...
authorStephen Smalley <sds@tycho.nsa.gov>
Fri, 8 Sep 2017 16:40:01 +0000 (12:40 -0400)
committerJames Morris <james.morris@microsoft.com>
Tue, 6 Mar 2018 22:05:53 +0000 (09:05 +1100)
commit d178bc3a708f39cbfefc3fab37032d3f2511b4ec ("user namespace: usb:
 make usb urbs user namespace aware (v2)") changed kill_pid_info_as_uid
to kill_pid_info_as_cred, saving and passing a cred structure instead of
uids.  Since the secid can be obtained from the cred, drop the secid fields
from the usb_dev_state and async structures, and drop the secid argument to
kill_pid_info_as_cred.  Replace the secid argument to security_task_kill
with the cred.  Update SELinux, Smack, and AppArmor to use the cred, which
avoids the need for Smack and AppArmor to use a secid at all in this hook.
Further changes to Smack might still be required to take full advantage of
this change, since it should now be possible to perform capability
checking based on the supplied cred.  The changes to Smack and AppArmor
have only been compile-tested.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Acked-by: Paul Moore <paul@paul-moore.com>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: James Morris <james.morris@microsoft.com>
drivers/usb/core/devio.c
include/linux/lsm_hooks.h
include/linux/sched/signal.h
include/linux/security.h
kernel/signal.c
security/apparmor/lsm.c
security/security.c
security/selinux/hooks.c
security/smack/smack_lsm.c

index d526595bc959c495b4578be386822ddd1ab62365..76e16c5251b9ffe21771e90667184fced5a30867 100644 (file)
@@ -65,7 +65,6 @@ struct usb_dev_state {
        const struct cred *cred;
        void __user *disccontext;
        unsigned long ifclaimed;
        const struct cred *cred;
        void __user *disccontext;
        unsigned long ifclaimed;
-       u32 secid;
        u32 disabled_bulk_eps;
        bool privileges_dropped;
        unsigned long interface_allowed_mask;
        u32 disabled_bulk_eps;
        bool privileges_dropped;
        unsigned long interface_allowed_mask;
@@ -95,7 +94,6 @@ struct async {
        struct usb_memory *usbm;
        unsigned int mem_usage;
        int status;
        struct usb_memory *usbm;
        unsigned int mem_usage;
        int status;
-       u32 secid;
        u8 bulk_addr;
        u8 bulk_status;
 };
        u8 bulk_addr;
        u8 bulk_status;
 };
@@ -586,7 +584,6 @@ static void async_completed(struct urb *urb)
        struct usb_dev_state *ps = as->ps;
        struct siginfo sinfo;
        struct pid *pid = NULL;
        struct usb_dev_state *ps = as->ps;
        struct siginfo sinfo;
        struct pid *pid = NULL;
-       u32 secid = 0;
        const struct cred *cred = NULL;
        int signr;
 
        const struct cred *cred = NULL;
        int signr;
 
@@ -602,7 +599,6 @@ static void async_completed(struct urb *urb)
                sinfo.si_addr = as->userurb;
                pid = get_pid(as->pid);
                cred = get_cred(as->cred);
                sinfo.si_addr = as->userurb;
                pid = get_pid(as->pid);
                cred = get_cred(as->cred);
-               secid = as->secid;
        }
        snoop(&urb->dev->dev, "urb complete\n");
        snoop_urb(urb->dev, as->userurb, urb->pipe, urb->actual_length,
        }
        snoop(&urb->dev->dev, "urb complete\n");
        snoop_urb(urb->dev, as->userurb, urb->pipe, urb->actual_length,
@@ -618,7 +614,7 @@ static void async_completed(struct urb *urb)
        spin_unlock(&ps->lock);
 
        if (signr) {
        spin_unlock(&ps->lock);
 
        if (signr) {
-               kill_pid_info_as_cred(sinfo.si_signo, &sinfo, pid, cred, secid);
+               kill_pid_info_as_cred(sinfo.si_signo, &sinfo, pid, cred);
                put_pid(pid);
                put_cred(cred);
        }
                put_pid(pid);
                put_cred(cred);
        }
@@ -1013,7 +1009,6 @@ static int usbdev_open(struct inode *inode, struct file *file)
        init_waitqueue_head(&ps->wait);
        ps->disc_pid = get_pid(task_pid(current));
        ps->cred = get_current_cred();
        init_waitqueue_head(&ps->wait);
        ps->disc_pid = get_pid(task_pid(current));
        ps->cred = get_current_cred();
-       security_task_getsecid(current, &ps->secid);
        smp_wmb();
        list_add_tail(&ps->list, &dev->filelist);
        file->private_data = ps;
        smp_wmb();
        list_add_tail(&ps->list, &dev->filelist);
        file->private_data = ps;
@@ -1727,7 +1722,6 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
        as->ifnum = ifnum;
        as->pid = get_pid(task_pid(current));
        as->cred = get_current_cred();
        as->ifnum = ifnum;
        as->pid = get_pid(task_pid(current));
        as->cred = get_current_cred();
-       security_task_getsecid(current, &as->secid);
        snoop_urb(ps->dev, as->userurb, as->urb->pipe,
                        as->urb->transfer_buffer_length, 0, SUBMIT,
                        NULL, 0);
        snoop_urb(ps->dev, as->userurb, as->urb->pipe,
                        as->urb->transfer_buffer_length, 0, SUBMIT,
                        NULL, 0);
@@ -2617,7 +2611,7 @@ static void usbdev_remove(struct usb_device *udev)
                        sinfo.si_code = SI_ASYNCIO;
                        sinfo.si_addr = ps->disccontext;
                        kill_pid_info_as_cred(ps->discsignr, &sinfo,
                        sinfo.si_code = SI_ASYNCIO;
                        sinfo.si_addr = ps->disccontext;
                        kill_pid_info_as_cred(ps->discsignr, &sinfo,
-                                       ps->disc_pid, ps->cred, ps->secid);
+                                       ps->disc_pid, ps->cred);
                }
        }
 }
                }
        }
 }
index 7161d8e7ee79246ffca220805826f883f26d7ddd..e0ac011d07a514ae5ee750ff025ffef559f5e78d 100644 (file)
  *     @p contains the task_struct for process.
  *     @info contains the signal information.
  *     @sig contains the signal value.
  *     @p contains the task_struct for process.
  *     @info contains the signal information.
  *     @sig contains the signal value.
- *     @secid contains the sid of the process where the signal originated
+ *     @cred contains the cred of the process where the signal originated, or
+ *     NULL if the current task is the originator.
  *     Return 0 if permission is granted.
  * @task_prctl:
  *     Check permission before performing a process control operation on the
  *     Return 0 if permission is granted.
  * @task_prctl:
  *     Check permission before performing a process control operation on the
@@ -1564,7 +1565,7 @@ union security_list_options {
        int (*task_getscheduler)(struct task_struct *p);
        int (*task_movememory)(struct task_struct *p);
        int (*task_kill)(struct task_struct *p, struct siginfo *info,
        int (*task_getscheduler)(struct task_struct *p);
        int (*task_movememory)(struct task_struct *p);
        int (*task_kill)(struct task_struct *p, struct siginfo *info,
-                               int sig, u32 secid);
+                               int sig, const struct cred *cred);
        int (*task_prctl)(int option, unsigned long arg2, unsigned long arg3,
                                unsigned long arg4, unsigned long arg5);
        void (*task_to_inode)(struct task_struct *p, struct inode *inode);
        int (*task_prctl)(int option, unsigned long arg2, unsigned long arg3,
                                unsigned long arg4, unsigned long arg5);
        void (*task_to_inode)(struct task_struct *p, struct inode *inode);
index 23b4f9cb82dbb3c265010883a94f26511358f133..a7ce74c74e494ae05ba687bf9ad0497a690faed2 100644 (file)
@@ -319,7 +319,7 @@ extern 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_cred(int, struct siginfo *, struct pid *,
 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_cred(int, struct siginfo *, struct pid *,
-                               const struct cred *, u32);
+                               const struct cred *);
 extern int kill_pgrp(struct pid *pid, int sig, int priv);
 extern int kill_pid(struct pid *pid, int sig, int priv);
 extern __must_check bool do_notify_parent(struct task_struct *, int);
 extern int kill_pgrp(struct pid *pid, int sig, int priv);
 extern int kill_pid(struct pid *pid, int sig, int priv);
 extern __must_check bool do_notify_parent(struct task_struct *, int);
index 73f1ef625d40c900430778fab29f8bad6cd2e029..3f5fd988ee875787c7019de29f5aebb5b7c34bc8 100644 (file)
@@ -347,7 +347,7 @@ int security_task_setscheduler(struct task_struct *p);
 int security_task_getscheduler(struct task_struct *p);
 int security_task_movememory(struct task_struct *p);
 int security_task_kill(struct task_struct *p, struct siginfo *info,
 int security_task_getscheduler(struct task_struct *p);
 int security_task_movememory(struct task_struct *p);
 int security_task_kill(struct task_struct *p, struct siginfo *info,
-                       int sig, u32 secid);
+                       int sig, const struct cred *cred);
 int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
                        unsigned long arg4, unsigned long arg5);
 void security_task_to_inode(struct task_struct *p, struct inode *inode);
 int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
                        unsigned long arg4, unsigned long arg5);
 void security_task_to_inode(struct task_struct *p, struct inode *inode);
@@ -1010,7 +1010,7 @@ static inline int security_task_movememory(struct task_struct *p)
 
 static inline int security_task_kill(struct task_struct *p,
                                     struct siginfo *info, int sig,
 
 static inline int security_task_kill(struct task_struct *p,
                                     struct siginfo *info, int sig,
-                                    u32 secid)
+                                    const struct cred *cred)
 {
        return 0;
 }
 {
        return 0;
 }
index c6e4c83dc090ab1361ee9c229f8ff185295c2f46..b033292f4beb42c131fa3c8b4e995a1783e25c90 100644 (file)
@@ -770,7 +770,7 @@ static int check_kill_permission(int sig, struct siginfo *info,
                }
        }
 
                }
        }
 
-       return security_task_kill(t, info, sig, 0);
+       return security_task_kill(t, info, sig, NULL);
 }
 
 /**
 }
 
 /**
@@ -1361,7 +1361,7 @@ static int kill_as_cred_perm(const struct cred *cred,
 
 /* like kill_pid_info(), but doesn't use uid/euid of "current" */
 int kill_pid_info_as_cred(int sig, struct siginfo *info, struct pid *pid,
 
 /* like kill_pid_info(), but doesn't use uid/euid of "current" */
 int kill_pid_info_as_cred(int sig, struct siginfo *info, struct pid *pid,
-                        const struct cred *cred, u32 secid)
+                        const struct cred *cred)
 {
        int ret = -EINVAL;
        struct task_struct *p;
 {
        int ret = -EINVAL;
        struct task_struct *p;
@@ -1380,7 +1380,7 @@ int kill_pid_info_as_cred(int sig, struct siginfo *info, struct pid *pid,
                ret = -EPERM;
                goto out_unlock;
        }
                ret = -EPERM;
                goto out_unlock;
        }
-       ret = security_task_kill(p, info, sig, secid);
+       ret = security_task_kill(p, info, sig, cred);
        if (ret)
                goto out_unlock;
 
        if (ret)
                goto out_unlock;
 
index 9a65eeaf7dfa22ab3b76d05b1445c56031195cd3..77bdfa7f84282182a143e8f2a53ed43f8be33586 100644 (file)
@@ -717,16 +717,23 @@ static int apparmor_task_setrlimit(struct task_struct *task,
 }
 
 static int apparmor_task_kill(struct task_struct *target, struct siginfo *info,
 }
 
 static int apparmor_task_kill(struct task_struct *target, struct siginfo *info,
-                             int sig, u32 secid)
+                             int sig, const struct cred *cred)
 {
        struct aa_label *cl, *tl;
        int error;
 
 {
        struct aa_label *cl, *tl;
        int error;
 
-       if (secid)
-               /* TODO: after secid to label mapping is done.
-                *  Dealing with USB IO specific behavior
+       if (cred) {
+               /*
+                * Dealing with USB IO specific behavior
                 */
                 */
-               return 0;
+               cl = aa_get_newest_cred_label(cred);
+               tl = aa_get_task_label(target);
+               error = aa_may_signal(cl, tl, sig);
+               aa_put_label(cl);
+               aa_put_label(tl);
+               return error;
+       }
+
        cl = __begin_current_label_crit_section();
        tl = aa_get_task_label(target);
        error = aa_may_signal(cl, tl, sig);
        cl = __begin_current_label_crit_section();
        tl = aa_get_task_label(target);
        error = aa_may_signal(cl, tl, sig);
index 1cd8526cb0b775647fe567a6910cc7b811cff21a..14c291910d25942c3ccef4d0f91f319b5ad157f6 100644 (file)
@@ -1114,9 +1114,9 @@ int security_task_movememory(struct task_struct *p)
 }
 
 int security_task_kill(struct task_struct *p, struct siginfo *info,
 }
 
 int security_task_kill(struct task_struct *p, struct siginfo *info,
-                       int sig, u32 secid)
+                       int sig, const struct cred *cred)
 {
 {
-       return call_int_hook(task_kill, 0, p, info, sig, secid);
+       return call_int_hook(task_kill, 0, p, info, sig, cred);
 }
 
 int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
 }
 
 int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
index 8644d864e3c196ca3dc8a10cb84c2daa97e3a596..8abd542c6b7c5f177b77c95b38f95daf255c0d4a 100644 (file)
@@ -4036,16 +4036,19 @@ static int selinux_task_movememory(struct task_struct *p)
 }
 
 static int selinux_task_kill(struct task_struct *p, struct siginfo *info,
 }
 
 static int selinux_task_kill(struct task_struct *p, struct siginfo *info,
-                               int sig, u32 secid)
+                               int sig, const struct cred *cred)
 {
 {
+       u32 secid;
        u32 perm;
 
        if (!sig)
                perm = PROCESS__SIGNULL; /* null signal; existence test */
        else
                perm = signal_to_av(sig);
        u32 perm;
 
        if (!sig)
                perm = PROCESS__SIGNULL; /* null signal; existence test */
        else
                perm = signal_to_av(sig);
-       if (!secid)
+       if (!cred)
                secid = current_sid();
                secid = current_sid();
+       else
+               secid = cred_sid(cred);
        return avc_has_perm(secid, task_sid(p), SECCLASS_PROCESS, perm, NULL);
 }
 
        return avc_has_perm(secid, task_sid(p), SECCLASS_PROCESS, perm, NULL);
 }
 
index 03fdecba93bb2b238d91e0e29efa0783c7e84b72..feada266532209a5e5e4015e88b71813c7dd82dd 100644 (file)
@@ -2228,15 +2228,13 @@ static int smack_task_movememory(struct task_struct *p)
  * @p: the task object
  * @info: unused
  * @sig: unused
  * @p: the task object
  * @info: unused
  * @sig: unused
- * @secid: identifies the smack to use in lieu of current's
+ * @cred: identifies the cred to use in lieu of current's
  *
  * Return 0 if write access is permitted
  *
  *
  * Return 0 if write access is permitted
  *
- * The secid behavior is an artifact of an SELinux hack
- * in the USB code. Someday it may go away.
  */
 static int smack_task_kill(struct task_struct *p, struct siginfo *info,
  */
 static int smack_task_kill(struct task_struct *p, struct siginfo *info,
-                          int sig, u32 secid)
+                          int sig, const struct cred *cred)
 {
        struct smk_audit_info ad;
        struct smack_known *skp;
 {
        struct smk_audit_info ad;
        struct smack_known *skp;
@@ -2252,17 +2250,17 @@ static int smack_task_kill(struct task_struct *p, struct siginfo *info,
         * Sending a signal requires that the sender
         * can write the receiver.
         */
         * Sending a signal requires that the sender
         * can write the receiver.
         */
-       if (secid == 0) {
+       if (cred == NULL) {
                rc = smk_curacc(tkp, MAY_DELIVER, &ad);
                rc = smk_bu_task(p, MAY_DELIVER, rc);
                return rc;
        }
        /*
                rc = smk_curacc(tkp, MAY_DELIVER, &ad);
                rc = smk_bu_task(p, MAY_DELIVER, rc);
                return rc;
        }
        /*
-        * If the secid isn't 0 we're dealing with some USB IO
+        * If the cred isn't NULL we're dealing with some USB IO
         * specific behavior. This is not clean. For one thing
         * we can't take privilege into account.
         */
         * specific behavior. This is not clean. For one thing
         * we can't take privilege into account.
         */
-       skp = smack_from_secid(secid);
+       skp = smk_of_task(cred->security);
        rc = smk_access(skp, tkp, MAY_DELIVER, &ad);
        rc = smk_bu_note("USB signal", skp, tkp, MAY_DELIVER, rc);
        return rc;
        rc = smk_access(skp, tkp, MAY_DELIVER, &ad);
        rc = smk_bu_note("USB signal", skp, tkp, MAY_DELIVER, rc);
        return rc;