]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - security/selinux/hooks.c
selinux: use pernet operations for hook registration
[mirror_ubuntu-artful-kernel.git] / security / selinux / hooks.c
index b59255f86274195a6e493ebcf313bc4644827fd8..9926adbd50a9624e392ad280ac80198e71ad40d8 100644 (file)
@@ -91,6 +91,7 @@
 #include "netif.h"
 #include "netnode.h"
 #include "netport.h"
+#include "ibpkey.h"
 #include "xfrm.h"
 #include "netlabel.h"
 #include "audit.h"
@@ -174,8 +175,10 @@ static int selinux_netcache_avc_callback(u32 event)
 
 static int selinux_lsm_notifier_avc_callback(u32 event)
 {
-       if (event == AVC_CALLBACK_RESET)
+       if (event == AVC_CALLBACK_RESET) {
+               sel_ib_pkey_flush();
                call_lsm_notifier(LSM_POLICY_CHANGE, NULL);
+       }
 
        return 0;
 }
@@ -6156,7 +6159,7 @@ static int selinux_ib_pkey_access(void *ib_sec, u64 subnet_prefix, u16 pkey_val)
        struct ib_security_struct *sec = ib_sec;
        struct lsm_ibpkey_audit ibpkey;
 
-       err = security_ib_pkey_sid(subnet_prefix, pkey_val, &sid);
+       err = sel_ib_pkey_sid(subnet_prefix, pkey_val, &sid);
        if (err)
                return err;
 
@@ -6169,6 +6172,29 @@ static int selinux_ib_pkey_access(void *ib_sec, u64 subnet_prefix, u16 pkey_val)
                            INFINIBAND_PKEY__ACCESS, &ad);
 }
 
+static int selinux_ib_endport_manage_subnet(void *ib_sec, const char *dev_name,
+                                           u8 port_num)
+{
+       struct common_audit_data ad;
+       int err;
+       u32 sid = 0;
+       struct ib_security_struct *sec = ib_sec;
+       struct lsm_ibendport_audit ibendport;
+
+       err = security_ib_endport_sid(dev_name, port_num, &sid);
+
+       if (err)
+               return err;
+
+       ad.type = LSM_AUDIT_DATA_IBENDPORT;
+       strncpy(ibendport.dev_name, dev_name, sizeof(ibendport.dev_name));
+       ibendport.port = port_num;
+       ad.u.ibendport = &ibendport;
+       return avc_has_perm(sec->sid, sid,
+                           SECCLASS_INFINIBAND_ENDPORT,
+                           INFINIBAND_ENDPORT__MANAGE_SUBNET, &ad);
+}
+
 static int selinux_ib_alloc_security(void **ib_sec)
 {
        struct ib_security_struct *sec;
@@ -6374,6 +6400,8 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {
        LSM_HOOK_INIT(tun_dev_open, selinux_tun_dev_open),
 #ifdef CONFIG_SECURITY_INFINIBAND
        LSM_HOOK_INIT(ib_pkey_access, selinux_ib_pkey_access),
+       LSM_HOOK_INIT(ib_endport_manage_subnet,
+                     selinux_ib_endport_manage_subnet),
        LSM_HOOK_INIT(ib_alloc_security, selinux_ib_alloc_security),
        LSM_HOOK_INIT(ib_free_security, selinux_ib_free_security),
 #endif
@@ -6512,6 +6540,23 @@ static struct nf_hook_ops selinux_nf_ops[] = {
 #endif /* IPV6 */
 };
 
+static int __net_init selinux_nf_register(struct net *net)
+{
+       return nf_register_net_hooks(net, selinux_nf_ops,
+                                    ARRAY_SIZE(selinux_nf_ops));
+}
+
+static void __net_exit selinux_nf_unregister(struct net *net)
+{
+       nf_unregister_net_hooks(net, selinux_nf_ops,
+                               ARRAY_SIZE(selinux_nf_ops));
+}
+
+static struct pernet_operations selinux_net_ops = {
+       .init = selinux_nf_register,
+       .exit = selinux_nf_unregister,
+};
+
 static int __init selinux_nf_ip_init(void)
 {
        int err;
@@ -6521,13 +6566,12 @@ static int __init selinux_nf_ip_init(void)
 
        printk(KERN_DEBUG "SELinux:  Registering netfilter hooks\n");
 
-       err = nf_register_hooks(selinux_nf_ops, ARRAY_SIZE(selinux_nf_ops));
+       err = register_pernet_subsys(&selinux_net_ops);
        if (err)
-               panic("SELinux: nf_register_hooks: error %d\n", err);
+               panic("SELinux: register_pernet_subsys: error %d\n", err);
 
        return 0;
 }
-
 __initcall(selinux_nf_ip_init);
 
 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
@@ -6535,7 +6579,7 @@ static void selinux_nf_ip_exit(void)
 {
        printk(KERN_DEBUG "SELinux:  Unregistering netfilter hooks\n");
 
-       nf_unregister_hooks(selinux_nf_ops, ARRAY_SIZE(selinux_nf_ops));
+       unregister_pernet_subsys(&selinux_net_ops);
 }
 #endif