Skip to content

Commit 121cc35

Browse files
committed
Merge tag 'lsm-pr-20251201' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm
Pull LSM updates from Paul Moore: - Rework the LSM initialization code What started as a "quick" patch to enable a notification event once all of the individual LSMs were initialized, snowballed a bit into a 30+ patch patchset when everything was done. Most of the patches, and diffstat, is due to splitting out the initialization code into security/lsm_init.c and cleaning up some of the mess that was there. While not strictly necessary, it does cleanup the code signficantly, and hopefully makes the upkeep a bit easier in the future. Aside from the new LSM_STARTED_ALL notification, these changes also ensure that individual LSM initcalls are only called when the LSM is enabled at boot time. There should be a minor reduction in boot times for those who build multiple LSMs into their kernels, but only enable a subset at boot. It is worth mentioning that nothing at present makes use of the LSM_STARTED_ALL notification, but there is work in progress which is dependent upon LSM_STARTED_ALL. - Make better use of the seq_put*() helpers in device_cgroup * tag 'lsm-pr-20251201' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm: (36 commits) lsm: use unrcu_pointer() for current->cred in security_init() device_cgroup: Refactor devcgroup_seq_show to use seq_put* helpers lsm: add a LSM_STARTED_ALL notification event lsm: consolidate all of the LSM framework initcalls selinux: move initcalls to the LSM framework ima,evm: move initcalls to the LSM framework lockdown: move initcalls to the LSM framework apparmor: move initcalls to the LSM framework safesetid: move initcalls to the LSM framework tomoyo: move initcalls to the LSM framework smack: move initcalls to the LSM framework ipe: move initcalls to the LSM framework loadpin: move initcalls to the LSM framework lsm: introduce an initcall mechanism into the LSM framework lsm: group lsm_order_parse() with the other lsm_order_*() functions lsm: output available LSMs when debugging lsm: cleanup the debug and console output in lsm_init.c lsm: add/tweak function header comment blocks in lsm_init.c lsm: fold lsm_init_ordered() into security_init() lsm: cleanup initialize_lsm() and rename to lsm_init_single() ...
2 parents 7fc2cd2 + 9a948ee commit 121cc35

53 files changed

Lines changed: 1025 additions & 742 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/linux/lsm_hooks.h

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,23 @@ struct security_hook_list {
102102
* Security blob size or offset data.
103103
*/
104104
struct lsm_blob_sizes {
105-
int lbs_cred;
106-
int lbs_file;
107-
int lbs_ib;
108-
int lbs_inode;
109-
int lbs_sock;
110-
int lbs_superblock;
111-
int lbs_ipc;
112-
int lbs_key;
113-
int lbs_msg_msg;
114-
int lbs_perf_event;
115-
int lbs_task;
116-
int lbs_xattr_count; /* number of xattr slots in new_xattrs array */
117-
int lbs_tun_dev;
118-
int lbs_bdev;
119-
int lbs_bpf_map;
120-
int lbs_bpf_prog;
121-
int lbs_bpf_token;
105+
unsigned int lbs_cred;
106+
unsigned int lbs_file;
107+
unsigned int lbs_ib;
108+
unsigned int lbs_inode;
109+
unsigned int lbs_sock;
110+
unsigned int lbs_superblock;
111+
unsigned int lbs_ipc;
112+
unsigned int lbs_key;
113+
unsigned int lbs_msg_msg;
114+
unsigned int lbs_perf_event;
115+
unsigned int lbs_task;
116+
unsigned int lbs_xattr_count; /* num xattr slots in new_xattrs array */
117+
unsigned int lbs_tun_dev;
118+
unsigned int lbs_bdev;
119+
unsigned int lbs_bpf_map;
120+
unsigned int lbs_bpf_prog;
121+
unsigned int lbs_bpf_token;
122122
};
123123

124124
/*
@@ -151,13 +151,36 @@ enum lsm_order {
151151
LSM_ORDER_LAST = 1, /* This is only for integrity. */
152152
};
153153

154+
/**
155+
* struct lsm_info - Define an individual LSM for the LSM framework.
156+
* @id: LSM name/ID info
157+
* @order: ordering with respect to other LSMs, optional
158+
* @flags: descriptive flags, optional
159+
* @blobs: LSM blob sharing, optional
160+
* @enabled: controlled by CONFIG_LSM, optional
161+
* @init: LSM specific initialization routine
162+
* @initcall_pure: LSM callback for initcall_pure() setup, optional
163+
* @initcall_early: LSM callback for early_initcall setup, optional
164+
* @initcall_core: LSM callback for core_initcall() setup, optional
165+
* @initcall_subsys: LSM callback for subsys_initcall() setup, optional
166+
* @initcall_fs: LSM callback for fs_initcall setup, optional
167+
* @nitcall_device: LSM callback for device_initcall() setup, optional
168+
* @initcall_late: LSM callback for late_initcall() setup, optional
169+
*/
154170
struct lsm_info {
155-
const char *name; /* Required. */
156-
enum lsm_order order; /* Optional: default is LSM_ORDER_MUTABLE */
157-
unsigned long flags; /* Optional: flags describing LSM */
158-
int *enabled; /* Optional: controlled by CONFIG_LSM */
159-
int (*init)(void); /* Required. */
160-
struct lsm_blob_sizes *blobs; /* Optional: for blob sharing. */
171+
const struct lsm_id *id;
172+
enum lsm_order order;
173+
unsigned long flags;
174+
struct lsm_blob_sizes *blobs;
175+
int *enabled;
176+
int (*init)(void);
177+
int (*initcall_pure)(void);
178+
int (*initcall_early)(void);
179+
int (*initcall_core)(void);
180+
int (*initcall_subsys)(void);
181+
int (*initcall_fs)(void);
182+
int (*initcall_device)(void);
183+
int (*initcall_late)(void);
161184
};
162185

163186
#define DEFINE_LSM(lsm) \
@@ -170,11 +193,9 @@ struct lsm_info {
170193
__used __section(".early_lsm_info.init") \
171194
__aligned(sizeof(unsigned long))
172195

196+
173197
/* DO NOT tamper with these variables outside of the LSM framework */
174-
extern char *lsm_names;
175198
extern struct lsm_static_calls_table static_calls_table __ro_after_init;
176-
extern struct lsm_info __start_lsm_info[], __end_lsm_info[];
177-
extern struct lsm_info __start_early_lsm_info[], __end_early_lsm_info[];
178199

179200
/**
180201
* lsm_get_xattr_slot - Return the next available slot and increment the index

include/linux/security.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct timezone;
8585

8686
enum lsm_event {
8787
LSM_POLICY_CHANGE,
88+
LSM_STARTED_ALL,
8889
};
8990

9091
struct dm_verity_digest {
@@ -167,8 +168,6 @@ struct lsm_prop {
167168
};
168169

169170
extern const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1];
170-
extern u32 lsm_active_cnt;
171-
extern const struct lsm_id *lsm_idlist[];
172171

173172
/* These functions are in security/commoncap.c */
174173
extern int cap_capable(const struct cred *cred, struct user_namespace *ns,

security/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ obj-$(CONFIG_SECURITY) += lsm_syscalls.o
1111
obj-$(CONFIG_MMU) += min_addr.o
1212

1313
# Object file lists
14-
obj-$(CONFIG_SECURITY) += security.o
14+
obj-$(CONFIG_SECURITY) += security.o lsm_notifier.o lsm_init.o
1515
obj-$(CONFIG_SECURITYFS) += inode.o
1616
obj-$(CONFIG_SECURITY_SELINUX) += selinux/
1717
obj-$(CONFIG_SECURITY_SMACK) += smack/

security/apparmor/apparmorfs.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,7 +2649,7 @@ static const struct inode_operations policy_link_iops = {
26492649
*
26502650
* Returns: error on failure
26512651
*/
2652-
static int __init aa_create_aafs(void)
2652+
int __init aa_create_aafs(void)
26532653
{
26542654
struct dentry *dent;
26552655
int error;
@@ -2728,5 +2728,3 @@ static int __init aa_create_aafs(void)
27282728
AA_ERROR("Error creating AppArmor securityfs\n");
27292729
return error;
27302730
}
2731-
2732-
fs_initcall(aa_create_aafs);

security/apparmor/crypto.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ int aa_calc_profile_hash(struct aa_profile *profile, u32 version, void *start,
5353
return 0;
5454
}
5555

56-
static int __init init_profile_hash(void)
56+
int __init init_profile_hash(void)
5757
{
5858
if (apparmor_initialized)
5959
aa_info_message("AppArmor sha256 policy hashing enabled");
6060
return 0;
6161
}
62-
late_initcall(init_profile_hash);

security/apparmor/include/apparmorfs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ enum aafs_prof_type {
104104
#define prof_dir(X) ((X)->dents[AAFS_PROF_DIR])
105105
#define prof_child_dir(X) ((X)->dents[AAFS_PROF_PROFS])
106106

107+
int aa_create_aafs(void);
108+
107109
void __aa_bump_ns_revision(struct aa_ns *ns);
108110
void __aafs_profile_rmdir(struct aa_profile *profile);
109111
void __aafs_profile_migrate_dents(struct aa_profile *old,

security/apparmor/include/crypto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "policy.h"
1414

1515
#ifdef CONFIG_SECURITY_APPARMOR_HASH
16+
int init_profile_hash(void);
1617
unsigned int aa_hash_size(void);
1718
char *aa_calc_hash(void *data, size_t len);
1819
int aa_calc_profile_hash(struct aa_profile *profile, u32 version, void *start,

security/apparmor/lsm.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "include/audit.h"
3333
#include "include/capability.h"
3434
#include "include/cred.h"
35+
#include "include/crypto.h"
3536
#include "include/file.h"
3637
#include "include/ipc.h"
3738
#include "include/net.h"
@@ -2426,7 +2427,6 @@ static int __init apparmor_nf_ip_init(void)
24262427

24272428
return 0;
24282429
}
2429-
__initcall(apparmor_nf_ip_init);
24302430
#endif
24312431

24322432
static char nulldfa_src[] __aligned(8) = {
@@ -2555,9 +2555,16 @@ static int __init apparmor_init(void)
25552555
}
25562556

25572557
DEFINE_LSM(apparmor) = {
2558-
.name = "apparmor",
2558+
.id = &apparmor_lsmid,
25592559
.flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
25602560
.enabled = &apparmor_enabled,
25612561
.blobs = &apparmor_blob_sizes,
25622562
.init = apparmor_init,
2563+
.initcall_fs = aa_create_aafs,
2564+
#if defined(CONFIG_NETFILTER) && defined(CONFIG_NETWORK_SECMARK)
2565+
.initcall_device = apparmor_nf_ip_init,
2566+
#endif
2567+
#ifdef CONFIG_SECURITY_APPARMOR_HASH
2568+
.initcall_late = init_profile_hash,
2569+
#endif
25632570
};

security/bpf/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct lsm_blob_sizes bpf_lsm_blob_sizes __ro_after_init = {
3333
};
3434

3535
DEFINE_LSM(bpf) = {
36-
.name = "bpf",
36+
.id = &bpf_lsmid,
3737
.init = bpf_lsm_init,
3838
.blobs = &bpf_lsm_blob_sizes
3939
};

security/commoncap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ static int __init capability_init(void)
15051505
}
15061506

15071507
DEFINE_LSM(capability) = {
1508-
.name = "capability",
1508+
.id = &capability_lsmid,
15091509
.order = LSM_ORDER_FIRST,
15101510
.init = capability_init,
15111511
};

0 commit comments

Comments
 (0)