Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selinux: Add IB Port SMP access vector

Add a type for Infiniband ports and an access vector for subnet
management packets. Implement the ib_port_smp hook to check that the
caller has permission to send and receive SMPs on the end port specified
by the device name and port. Add interface to query the SID for a IB
port, which walks the IB_PORT ocontexts to find an entry for the
given name and port.

Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
Reviewed-by: James Morris <james.l.morris@oracle.com>
Acked-by: Doug Ledford <dledford@redhat.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>

authored by

Daniel Jurgens and committed by
Paul Moore
ab861dfc cfc4d882

+83
+8
include/linux/lsm_audit.h
··· 21 21 #include <linux/path.h> 22 22 #include <linux/key.h> 23 23 #include <linux/skbuff.h> 24 + #include <rdma/ib_verbs.h> 24 25 25 26 struct lsm_network_audit { 26 27 int netif; ··· 51 50 u16 pkey; 52 51 }; 53 52 53 + struct lsm_ibendport_audit { 54 + char dev_name[IB_DEVICE_NAME_MAX]; 55 + u8 port; 56 + }; 57 + 54 58 /* Auxiliary data to use in generating the audit record. */ 55 59 struct common_audit_data { 56 60 char type; ··· 72 66 #define LSM_AUDIT_DATA_IOCTL_OP 11 73 67 #define LSM_AUDIT_DATA_FILE 12 74 68 #define LSM_AUDIT_DATA_IBPKEY 13 69 + #define LSM_AUDIT_DATA_IBENDPORT 14 75 70 union { 76 71 struct path path; 77 72 struct dentry *dentry; ··· 91 84 struct lsm_ioctlop_audit *op; 92 85 struct file *file; 93 86 struct lsm_ibpkey_audit *ibpkey; 87 + struct lsm_ibendport_audit *ibendport; 94 88 } u; 95 89 /* this union contains LSM specific data */ 96 90 union {
+5
security/lsm_audit.c
··· 421 421 a->u.ibpkey->pkey, &sbn_pfx); 422 422 break; 423 423 } 424 + case LSM_AUDIT_DATA_IBENDPORT: 425 + audit_log_format(ab, " device=%s port_num=%u", 426 + a->u.ibendport->dev_name, 427 + a->u.ibendport->port); 428 + break; 424 429 } /* switch (a->type) */ 425 430 } 426 431
+25
security/selinux/hooks.c
··· 6169 6169 INFINIBAND_PKEY__ACCESS, &ad); 6170 6170 } 6171 6171 6172 + static int selinux_ib_endport_manage_subnet(void *ib_sec, const char *dev_name, 6173 + u8 port_num) 6174 + { 6175 + struct common_audit_data ad; 6176 + int err; 6177 + u32 sid = 0; 6178 + struct ib_security_struct *sec = ib_sec; 6179 + struct lsm_ibendport_audit ibendport; 6180 + 6181 + err = security_ib_endport_sid(dev_name, port_num, &sid); 6182 + 6183 + if (err) 6184 + return err; 6185 + 6186 + ad.type = LSM_AUDIT_DATA_IBENDPORT; 6187 + strncpy(ibendport.dev_name, dev_name, sizeof(ibendport.dev_name)); 6188 + ibendport.port = port_num; 6189 + ad.u.ibendport = &ibendport; 6190 + return avc_has_perm(sec->sid, sid, 6191 + SECCLASS_INFINIBAND_ENDPORT, 6192 + INFINIBAND_ENDPORT__MANAGE_SUBNET, &ad); 6193 + } 6194 + 6172 6195 static int selinux_ib_alloc_security(void **ib_sec) 6173 6196 { 6174 6197 struct ib_security_struct *sec; ··· 6397 6374 LSM_HOOK_INIT(tun_dev_open, selinux_tun_dev_open), 6398 6375 #ifdef CONFIG_SECURITY_INFINIBAND 6399 6376 LSM_HOOK_INIT(ib_pkey_access, selinux_ib_pkey_access), 6377 + LSM_HOOK_INIT(ib_endport_manage_subnet, 6378 + selinux_ib_endport_manage_subnet), 6400 6379 LSM_HOOK_INIT(ib_alloc_security, selinux_ib_alloc_security), 6401 6380 LSM_HOOK_INIT(ib_free_security, selinux_ib_free_security), 6402 6381 #endif
+2
security/selinux/include/classmap.h
··· 233 233 { COMMON_SOCK_PERMS, NULL } }, 234 234 { "infiniband_pkey", 235 235 { "access", NULL } }, 236 + { "infiniband_endport", 237 + { "manage_subnet", NULL } }, 236 238 { NULL } 237 239 }; 238 240
+2
security/selinux/include/security.h
··· 183 183 184 184 int security_ib_pkey_sid(u64 subnet_prefix, u16 pkey_num, u32 *out_sid); 185 185 186 + int security_ib_endport_sid(const char *dev_name, u8 port_num, u32 *out_sid); 187 + 186 188 int security_netif_sid(char *name, u32 *if_sid); 187 189 188 190 int security_node_sid(u16 domain, void *addr, u32 addrlen,
+41
security/selinux/ss/services.c
··· 2273 2273 } 2274 2274 2275 2275 /** 2276 + * security_ib_endport_sid - Obtain the SID for a subnet management interface. 2277 + * @dev_name: device name 2278 + * @port: port number 2279 + * @out_sid: security identifier 2280 + */ 2281 + int security_ib_endport_sid(const char *dev_name, u8 port_num, u32 *out_sid) 2282 + { 2283 + struct ocontext *c; 2284 + int rc = 0; 2285 + 2286 + read_lock(&policy_rwlock); 2287 + 2288 + c = policydb.ocontexts[OCON_IBENDPORT]; 2289 + while (c) { 2290 + if (c->u.ibendport.port == port_num && 2291 + !strncmp(c->u.ibendport.dev_name, 2292 + dev_name, 2293 + IB_DEVICE_NAME_MAX)) 2294 + break; 2295 + 2296 + c = c->next; 2297 + } 2298 + 2299 + if (c) { 2300 + if (!c->sid[0]) { 2301 + rc = sidtab_context_to_sid(&sidtab, 2302 + &c->context[0], 2303 + &c->sid[0]); 2304 + if (rc) 2305 + goto out; 2306 + } 2307 + *out_sid = c->sid[0]; 2308 + } else 2309 + *out_sid = SECINITSID_UNLABELED; 2310 + 2311 + out: 2312 + read_unlock(&policy_rwlock); 2313 + return rc; 2314 + } 2315 + 2316 + /** 2276 2317 * security_netif_sid - Obtain the SID for a network interface. 2277 2318 * @name: interface name 2278 2319 * @if_sid: interface SID