Skip to content

Commit 66de33a

Browse files
cschauflerpcmoore
authored andcommitted
lsm: infrastructure management of the infiniband blob
Move management of the infiniband security blob out of the individual security modules and into the LSM infrastructure. The security modules tell the infrastructure how much space they require at initialization. There are no longer any modules that require the ib_free() hook. The hook definition has been removed. Signed-off-by: Casey Schaufler <[email protected]> Reviewed-by: John Johansen <[email protected]> [PM: subject tweak, selinux style fixes] Signed-off-by: Paul Moore <[email protected]>
1 parent a39c0f7 commit 66de33a

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

include/linux/lsm_hook_defs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,7 @@ LSM_HOOK(int, 0, mptcp_add_subflow, struct sock *sk, struct sock *ssk)
373373
LSM_HOOK(int, 0, ib_pkey_access, void *sec, u64 subnet_prefix, u16 pkey)
374374
LSM_HOOK(int, 0, ib_endport_manage_subnet, void *sec, const char *dev_name,
375375
u8 port_num)
376-
LSM_HOOK(int, 0, ib_alloc_security, void **sec)
377-
LSM_HOOK(void, LSM_RET_VOID, ib_free_security, void *sec)
376+
LSM_HOOK(int, 0, ib_alloc_security, void *sec)
378377
#endif /* CONFIG_SECURITY_INFINIBAND */
379378

380379
#ifdef CONFIG_SECURITY_NETWORK_XFRM

include/linux/lsm_hooks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct security_hook_list {
7272
struct lsm_blob_sizes {
7373
int lbs_cred;
7474
int lbs_file;
75+
int lbs_ib;
7576
int lbs_inode;
7677
int lbs_sock;
7778
int lbs_superblock;

security/security.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed)
219219

220220
lsm_set_blob_size(&needed->lbs_cred, &blob_sizes.lbs_cred);
221221
lsm_set_blob_size(&needed->lbs_file, &blob_sizes.lbs_file);
222+
lsm_set_blob_size(&needed->lbs_ib, &blob_sizes.lbs_ib);
222223
/*
223224
* The inode blob gets an rcu_head in addition to
224225
* what the modules might need.
@@ -402,6 +403,7 @@ static void __init ordered_lsm_init(void)
402403

403404
init_debug("cred blob size = %d\n", blob_sizes.lbs_cred);
404405
init_debug("file blob size = %d\n", blob_sizes.lbs_file);
406+
init_debug("ib blob size = %d\n", blob_sizes.lbs_ib);
405407
init_debug("inode blob size = %d\n", blob_sizes.lbs_inode);
406408
init_debug("ipc blob size = %d\n", blob_sizes.lbs_ipc);
407409
#ifdef CONFIG_KEYS
@@ -5096,7 +5098,18 @@ EXPORT_SYMBOL(security_ib_endport_manage_subnet);
50965098
*/
50975099
int security_ib_alloc_security(void **sec)
50985100
{
5099-
return call_int_hook(ib_alloc_security, sec);
5101+
int rc;
5102+
5103+
rc = lsm_blob_alloc(sec, blob_sizes.lbs_ib, GFP_KERNEL);
5104+
if (rc)
5105+
return rc;
5106+
5107+
rc = call_int_hook(ib_alloc_security, *sec);
5108+
if (rc) {
5109+
kfree(*sec);
5110+
*sec = NULL;
5111+
}
5112+
return rc;
51005113
}
51015114
EXPORT_SYMBOL(security_ib_alloc_security);
51025115

@@ -5108,7 +5121,7 @@ EXPORT_SYMBOL(security_ib_alloc_security);
51085121
*/
51095122
void security_ib_free_security(void *sec)
51105123
{
5111-
call_void_hook(ib_free_security, sec);
5124+
kfree(sec);
51125125
}
51135126
EXPORT_SYMBOL(security_ib_free_security);
51145127
#endif /* CONFIG_SECURITY_INFINIBAND */

security/selinux/hooks.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6781,23 +6781,13 @@ static int selinux_ib_endport_manage_subnet(void *ib_sec, const char *dev_name,
67816781
INFINIBAND_ENDPORT__MANAGE_SUBNET, &ad);
67826782
}
67836783

6784-
static int selinux_ib_alloc_security(void **ib_sec)
6784+
static int selinux_ib_alloc_security(void *ib_sec)
67856785
{
6786-
struct ib_security_struct *sec;
6786+
struct ib_security_struct *sec = selinux_ib(ib_sec);
67876787

6788-
sec = kzalloc(sizeof(*sec), GFP_KERNEL);
6789-
if (!sec)
6790-
return -ENOMEM;
67916788
sec->sid = current_sid();
6792-
6793-
*ib_sec = sec;
67946789
return 0;
67956790
}
6796-
6797-
static void selinux_ib_free_security(void *ib_sec)
6798-
{
6799-
kfree(ib_sec);
6800-
}
68016791
#endif
68026792

68036793
#ifdef CONFIG_BPF_SYSCALL
@@ -6969,6 +6959,7 @@ struct lsm_blob_sizes selinux_blob_sizes __ro_after_init = {
69696959
.lbs_superblock = sizeof(struct superblock_security_struct),
69706960
.lbs_xattr_count = SELINUX_INODE_INIT_XATTRS,
69716961
.lbs_tun_dev = sizeof(struct tun_security_struct),
6962+
.lbs_ib = sizeof(struct ib_security_struct),
69726963
};
69736964

69746965
#ifdef CONFIG_PERF_EVENTS
@@ -7288,7 +7279,6 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
72887279
LSM_HOOK_INIT(ib_pkey_access, selinux_ib_pkey_access),
72897280
LSM_HOOK_INIT(ib_endport_manage_subnet,
72907281
selinux_ib_endport_manage_subnet),
7291-
LSM_HOOK_INIT(ib_free_security, selinux_ib_free_security),
72927282
#endif
72937283
#ifdef CONFIG_SECURITY_NETWORK_XFRM
72947284
LSM_HOOK_INIT(xfrm_policy_free_security, selinux_xfrm_policy_free),

security/selinux/include/objsec.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,9 @@ static inline struct tun_security_struct *selinux_tun_dev(void *security)
212212
return security + selinux_blob_sizes.lbs_tun_dev;
213213
}
214214

215+
static inline struct ib_security_struct *selinux_ib(void *ib_sec)
216+
{
217+
return ib_sec + selinux_blob_sizes.lbs_ib;
218+
}
219+
215220
#endif /* _SELINUX_OBJSEC_H_ */

0 commit comments

Comments
 (0)