Skip to content

Commit 3156bc8

Browse files
committed
selinux: move initcalls to the LSM framework
SELinux currently has a number of initcalls so we've created a new function, selinux_initcall(), which wraps all of these initcalls so that we have a single initcall function that can be registered with the LSM framework. Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 82fe793 commit 3156bc8

File tree

12 files changed

+107
-40
lines changed

12 files changed

+107
-40
lines changed

security/selinux/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ccflags-y := -I$(srctree)/security/selinux -I$(srctree)/security/selinux/include
1515
ccflags-$(CONFIG_SECURITY_SELINUX_DEBUG) += -DDEBUG
1616

1717
selinux-y := avc.o hooks.o selinuxfs.o netlink.o nlmsgtab.o netif.o \
18-
netnode.o netport.o status.o \
18+
netnode.o netport.o status.o initcalls.o \
1919
ss/ebitmap.o ss/hashtab.o ss/symtab.o ss/sidtab.o ss/avtab.o \
2020
ss/policydb.o ss/services.o ss/conditional.o ss/mls.o ss/context.o
2121

security/selinux/hooks.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
#include <linux/io_uring/cmd.h>
9595
#include <uapi/linux/lsm.h>
9696

97+
#include "initcalls.h"
9798
#include "avc.h"
9899
#include "objsec.h"
99100
#include "netif.h"
@@ -7612,6 +7613,10 @@ static __init int selinux_init(void)
76127613
if (avc_add_callback(selinux_lsm_notifier_avc_callback, AVC_CALLBACK_RESET))
76137614
panic("SELinux: Unable to register AVC LSM notifier callback\n");
76147615

7616+
if (avc_add_callback(selinux_audit_rule_avc_callback,
7617+
AVC_CALLBACK_RESET))
7618+
panic("SELinux: Unable to register AVC audit callback\n");
7619+
76157620
if (selinux_enforcing_boot)
76167621
pr_debug("SELinux: Starting in enforcing mode\n");
76177622
else
@@ -7644,6 +7649,7 @@ DEFINE_LSM(selinux) = {
76447649
.enabled = &selinux_enabled_boot,
76457650
.blobs = &selinux_blob_sizes,
76467651
.init = selinux_init,
7652+
.initcall_device = selinux_initcall,
76477653
};
76487654

76497655
#if defined(CONFIG_NETFILTER)
@@ -7705,7 +7711,7 @@ static struct pernet_operations selinux_net_ops = {
77057711
.exit = selinux_nf_unregister,
77067712
};
77077713

7708-
static int __init selinux_nf_ip_init(void)
7714+
int __init selinux_nf_ip_init(void)
77097715
{
77107716
int err;
77117717

@@ -7720,5 +7726,4 @@ static int __init selinux_nf_ip_init(void)
77207726

77217727
return 0;
77227728
}
7723-
__initcall(selinux_nf_ip_init);
77247729
#endif /* CONFIG_NETFILTER */

security/selinux/ibpkey.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/list.h>
2424
#include <linux/spinlock.h>
2525

26+
#include "initcalls.h"
2627
#include "ibpkey.h"
2728
#include "objsec.h"
2829

@@ -218,7 +219,7 @@ void sel_ib_pkey_flush(void)
218219
spin_unlock_irqrestore(&sel_ib_pkey_lock, flags);
219220
}
220221

221-
static __init int sel_ib_pkey_init(void)
222+
int __init sel_ib_pkey_init(void)
222223
{
223224
int iter;
224225

@@ -232,5 +233,3 @@ static __init int sel_ib_pkey_init(void)
232233

233234
return 0;
234235
}
235-
236-
subsys_initcall(sel_ib_pkey_init);

security/selinux/include/audit.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
#include <linux/audit.h>
1616
#include <linux/types.h>
1717

18+
/**
19+
* selinux_audit_rule_avc_callback - update the audit LSM rules on AVC events.
20+
* @event: the AVC event
21+
*
22+
* Update any audit LSM rules based on the AVC event specified in @event.
23+
* Returns 0 on success, negative values otherwise.
24+
*/
25+
int selinux_audit_rule_avc_callback(u32 event);
26+
1827
/**
1928
* selinux_audit_rule_init - alloc/init an selinux audit rule structure.
2029
* @field: the field this rule refers to
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* SELinux initcalls
4+
*/
5+
6+
#ifndef _SELINUX_INITCALLS_H
7+
#define _SELINUX_INITCALLS_H
8+
9+
int init_sel_fs(void);
10+
int sel_netport_init(void);
11+
int sel_netnode_init(void);
12+
int sel_netif_init(void);
13+
int sel_netlink_init(void);
14+
int sel_ib_pkey_init(void);
15+
int selinux_nf_ip_init(void);
16+
17+
int selinux_initcall(void);
18+
19+
#endif

security/selinux/initcalls.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* SELinux initcalls
4+
*/
5+
6+
#include <linux/init.h>
7+
8+
#include "initcalls.h"
9+
10+
/**
11+
* selinux_initcall - Perform the SELinux initcalls
12+
*
13+
* Used as a device initcall in the SELinux LSM definition.
14+
*/
15+
int __init selinux_initcall(void)
16+
{
17+
int rc = 0, rc_tmp = 0;
18+
19+
rc_tmp = init_sel_fs();
20+
if (!rc && rc_tmp)
21+
rc = rc_tmp;
22+
23+
rc_tmp = sel_netport_init();
24+
if (!rc && rc_tmp)
25+
rc = rc_tmp;
26+
27+
rc_tmp = sel_netnode_init();
28+
if (!rc && rc_tmp)
29+
rc = rc_tmp;
30+
31+
rc_tmp = sel_netif_init();
32+
if (!rc && rc_tmp)
33+
rc = rc_tmp;
34+
35+
rc_tmp = sel_netlink_init();
36+
if (!rc && rc_tmp)
37+
rc = rc_tmp;
38+
39+
#if defined(CONFIG_SECURITY_INFINIBAND)
40+
rc_tmp = sel_ib_pkey_init();
41+
if (!rc && rc_tmp)
42+
rc = rc_tmp;
43+
#endif
44+
45+
#if defined(CONFIG_NETFILTER)
46+
rc_tmp = selinux_nf_ip_init();
47+
if (!rc && rc_tmp)
48+
rc = rc_tmp;
49+
#endif
50+
51+
return rc;
52+
}

security/selinux/netif.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/rcupdate.h>
2323
#include <net/net_namespace.h>
2424

25+
#include "initcalls.h"
2526
#include "security.h"
2627
#include "objsec.h"
2728
#include "netif.h"
@@ -265,7 +266,7 @@ static struct notifier_block sel_netif_netdev_notifier = {
265266
.notifier_call = sel_netif_netdev_notifier_handler,
266267
};
267268

268-
static __init int sel_netif_init(void)
269+
int __init sel_netif_init(void)
269270
{
270271
int i;
271272

@@ -280,5 +281,3 @@ static __init int sel_netif_init(void)
280281
return 0;
281282
}
282283

283-
__initcall(sel_netif_init);
284-

security/selinux/netlink.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <net/net_namespace.h>
1818
#include <net/netlink.h>
1919

20+
#include "initcalls.h"
2021
#include "security.h"
2122

2223
static struct sock *selnl __ro_after_init;
@@ -105,7 +106,7 @@ void selnl_notify_policyload(u32 seqno)
105106
selnl_notify(SELNL_MSG_POLICYLOAD, &seqno);
106107
}
107108

108-
static int __init selnl_init(void)
109+
int __init sel_netlink_init(void)
109110
{
110111
struct netlink_kernel_cfg cfg = {
111112
.groups = SELNLGRP_MAX,
@@ -117,5 +118,3 @@ static int __init selnl_init(void)
117118
panic("SELinux: Cannot create netlink socket.");
118119
return 0;
119120
}
120-
121-
__initcall(selnl_init);

security/selinux/netnode.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <net/ip.h>
3131
#include <net/ipv6.h>
3232

33+
#include "initcalls.h"
3334
#include "netnode.h"
3435
#include "objsec.h"
3536

@@ -290,7 +291,7 @@ void sel_netnode_flush(void)
290291
spin_unlock_bh(&sel_netnode_lock);
291292
}
292293

293-
static __init int sel_netnode_init(void)
294+
int __init sel_netnode_init(void)
294295
{
295296
int iter;
296297

@@ -304,5 +305,3 @@ static __init int sel_netnode_init(void)
304305

305306
return 0;
306307
}
307-
308-
__initcall(sel_netnode_init);

security/selinux/netport.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <net/ip.h>
3030
#include <net/ipv6.h>
3131

32+
#include "initcalls.h"
3233
#include "netport.h"
3334
#include "objsec.h"
3435

@@ -218,7 +219,7 @@ void sel_netport_flush(void)
218219
spin_unlock_bh(&sel_netport_lock);
219220
}
220221

221-
static __init int sel_netport_init(void)
222+
int __init sel_netport_init(void)
222223
{
223224
int iter;
224225

@@ -232,5 +233,3 @@ static __init int sel_netport_init(void)
232233

233234
return 0;
234235
}
235-
236-
__initcall(sel_netport_init);

0 commit comments

Comments
 (0)