3434#include <linux/sockptr.h>
3535#include <linux/bpf.h>
3636#include <uapi/linux/lsm.h>
37+ #include <linux/lsm/selinux.h>
38+ #include <linux/lsm/smack.h>
39+ #include <linux/lsm/apparmor.h>
40+ #include <linux/lsm/bpf.h>
3741
3842struct linux_binprm ;
3943struct cred ;
@@ -152,6 +156,16 @@ enum lockdown_reason {
152156 LOCKDOWN_CONFIDENTIALITY_MAX ,
153157};
154158
159+ /*
160+ * Data exported by the security modules
161+ */
162+ struct lsm_prop {
163+ struct lsm_prop_selinux selinux ;
164+ struct lsm_prop_smack smack ;
165+ struct lsm_prop_apparmor apparmor ;
166+ struct lsm_prop_bpf bpf ;
167+ };
168+
155169extern const char * const lockdown_reasons [LOCKDOWN_CONFIDENTIALITY_MAX + 1 ];
156170extern u32 lsm_active_cnt ;
157171extern const struct lsm_id * lsm_idlist [];
@@ -269,8 +283,32 @@ static inline const char *kernel_load_data_id_str(enum kernel_load_data_id id)
269283 return kernel_load_data_str [id ];
270284}
271285
286+ /**
287+ * lsmprop_init - initialize a lsm_prop structure
288+ * @prop: Pointer to the data to initialize
289+ *
290+ * Set all secid for all modules to the specified value.
291+ */
292+ static inline void lsmprop_init (struct lsm_prop * prop )
293+ {
294+ memset (prop , 0 , sizeof (* prop ));
295+ }
296+
272297#ifdef CONFIG_SECURITY
273298
299+ /**
300+ * lsmprop_is_set - report if there is a value in the lsm_prop
301+ * @prop: Pointer to the exported LSM data
302+ *
303+ * Returns true if there is a value set, false otherwise
304+ */
305+ static inline bool lsmprop_is_set (struct lsm_prop * prop )
306+ {
307+ const struct lsm_prop empty = {};
308+
309+ return !!memcmp (prop , & empty , sizeof (* prop ));
310+ }
311+
274312int call_blocking_lsm_notifier (enum lsm_event event , void * data );
275313int register_blocking_lsm_notifier (struct notifier_block * nb );
276314int unregister_blocking_lsm_notifier (struct notifier_block * nb );
@@ -408,7 +446,7 @@ int security_inode_getsecurity(struct mnt_idmap *idmap,
408446 void * * buffer , bool alloc );
409447int security_inode_setsecurity (struct inode * inode , const char * name , const void * value , size_t size , int flags );
410448int security_inode_listsecurity (struct inode * inode , char * buffer , size_t buffer_size );
411- void security_inode_getsecid (struct inode * inode , u32 * secid );
449+ void security_inode_getlsmprop (struct inode * inode , struct lsm_prop * prop );
412450int security_inode_copy_up (struct dentry * src , struct cred * * new );
413451int security_inode_copy_up_xattr (struct dentry * src , const char * name );
414452int security_inode_setintegrity (const struct inode * inode ,
@@ -444,6 +482,7 @@ void security_cred_free(struct cred *cred);
444482int security_prepare_creds (struct cred * new , const struct cred * old , gfp_t gfp );
445483void security_transfer_creds (struct cred * new , const struct cred * old );
446484void security_cred_getsecid (const struct cred * c , u32 * secid );
485+ void security_cred_getlsmprop (const struct cred * c , struct lsm_prop * prop );
447486int security_kernel_act_as (struct cred * new , u32 secid );
448487int security_kernel_create_files_as (struct cred * new , struct inode * inode );
449488int security_kernel_module_request (char * kmod_name );
@@ -463,8 +502,8 @@ int security_task_fix_setgroups(struct cred *new, const struct cred *old);
463502int security_task_setpgid (struct task_struct * p , pid_t pgid );
464503int security_task_getpgid (struct task_struct * p );
465504int security_task_getsid (struct task_struct * p );
466- void security_current_getsecid_subj ( u32 * secid );
467- void security_task_getsecid_obj (struct task_struct * p , u32 * secid );
505+ void security_current_getlsmprop_subj ( struct lsm_prop * prop );
506+ void security_task_getlsmprop_obj (struct task_struct * p , struct lsm_prop * prop );
468507int security_task_setnice (struct task_struct * p , int nice );
469508int security_task_setioprio (struct task_struct * p , int ioprio );
470509int security_task_getioprio (struct task_struct * p );
@@ -482,7 +521,7 @@ int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
482521void security_task_to_inode (struct task_struct * p , struct inode * inode );
483522int security_create_user_ns (const struct cred * cred );
484523int security_ipc_permission (struct kern_ipc_perm * ipcp , short flag );
485- void security_ipc_getsecid (struct kern_ipc_perm * ipcp , u32 * secid );
524+ void security_ipc_getlsmprop (struct kern_ipc_perm * ipcp , struct lsm_prop * prop );
486525int security_msg_msg_alloc (struct msg_msg * msg );
487526void security_msg_msg_free (struct msg_msg * msg );
488527int security_msg_queue_alloc (struct kern_ipc_perm * msq );
@@ -515,6 +554,7 @@ int security_setprocattr(int lsmid, const char *name, void *value, size_t size);
515554int security_netlink_send (struct sock * sk , struct sk_buff * skb );
516555int security_ismaclabel (const char * name );
517556int security_secid_to_secctx (u32 secid , char * * secdata , u32 * seclen );
557+ int security_lsmprop_to_secctx (struct lsm_prop * prop , char * * secdata , u32 * seclen );
518558int security_secctx_to_secid (const char * secdata , u32 seclen , u32 * secid );
519559void security_release_secctx (char * secdata , u32 seclen );
520560void security_inode_invalidate_secctx (struct inode * inode );
@@ -531,6 +571,17 @@ int security_bdev_setintegrity(struct block_device *bdev,
531571 size_t size );
532572#else /* CONFIG_SECURITY */
533573
574+ /**
575+ * lsmprop_is_set - report if there is a value in the lsm_prop
576+ * @prop: Pointer to the exported LSM data
577+ *
578+ * Returns true if there is a value set, false otherwise
579+ */
580+ static inline bool lsmprop_is_set (struct lsm_prop * prop )
581+ {
582+ return false;
583+ }
584+
534585static inline int call_blocking_lsm_notifier (enum lsm_event event , void * data )
535586{
536587 return 0 ;
@@ -1020,9 +1071,10 @@ static inline int security_inode_listsecurity(struct inode *inode, char *buffer,
10201071 return 0 ;
10211072}
10221073
1023- static inline void security_inode_getsecid (struct inode * inode , u32 * secid )
1074+ static inline void security_inode_getlsmprop (struct inode * inode ,
1075+ struct lsm_prop * prop )
10241076{
1025- * secid = 0 ;
1077+ lsmprop_init ( prop ) ;
10261078}
10271079
10281080static inline int security_inode_copy_up (struct dentry * src , struct cred * * new )
@@ -1172,6 +1224,10 @@ static inline void security_cred_getsecid(const struct cred *c, u32 *secid)
11721224 * secid = 0 ;
11731225}
11741226
1227+ static inline void security_cred_getlsmprop (const struct cred * c ,
1228+ struct lsm_prop * prop )
1229+ { }
1230+
11751231static inline int security_kernel_act_as (struct cred * cred , u32 secid )
11761232{
11771233 return 0 ;
@@ -1249,14 +1305,15 @@ static inline int security_task_getsid(struct task_struct *p)
12491305 return 0 ;
12501306}
12511307
1252- static inline void security_current_getsecid_subj ( u32 * secid )
1308+ static inline void security_current_getlsmprop_subj ( struct lsm_prop * prop )
12531309{
1254- * secid = 0 ;
1310+ lsmprop_init ( prop ) ;
12551311}
12561312
1257- static inline void security_task_getsecid_obj (struct task_struct * p , u32 * secid )
1313+ static inline void security_task_getlsmprop_obj (struct task_struct * p ,
1314+ struct lsm_prop * prop )
12581315{
1259- * secid = 0 ;
1316+ lsmprop_init ( prop ) ;
12601317}
12611318
12621319static inline int security_task_setnice (struct task_struct * p , int nice )
@@ -1332,9 +1389,10 @@ static inline int security_ipc_permission(struct kern_ipc_perm *ipcp,
13321389 return 0 ;
13331390}
13341391
1335- static inline void security_ipc_getsecid (struct kern_ipc_perm * ipcp , u32 * secid )
1392+ static inline void security_ipc_getlsmprop (struct kern_ipc_perm * ipcp ,
1393+ struct lsm_prop * prop )
13361394{
1337- * secid = 0 ;
1395+ lsmprop_init ( prop ) ;
13381396}
13391397
13401398static inline int security_msg_msg_alloc (struct msg_msg * msg )
@@ -1468,7 +1526,14 @@ static inline int security_ismaclabel(const char *name)
14681526 return 0 ;
14691527}
14701528
1471- static inline int security_secid_to_secctx (u32 secid , char * * secdata , u32 * seclen )
1529+ static inline int security_secid_to_secctx (u32 secid , char * * secdata ,
1530+ u32 * seclen )
1531+ {
1532+ return - EOPNOTSUPP ;
1533+ }
1534+
1535+ static inline int security_lsmprop_to_secctx (struct lsm_prop * prop ,
1536+ char * * secdata , u32 * seclen )
14721537{
14731538 return - EOPNOTSUPP ;
14741539}
@@ -2095,7 +2160,8 @@ static inline void security_key_post_create_or_update(struct key *keyring,
20952160int security_audit_rule_init (u32 field , u32 op , char * rulestr , void * * lsmrule ,
20962161 gfp_t gfp );
20972162int security_audit_rule_known (struct audit_krule * krule );
2098- int security_audit_rule_match (u32 secid , u32 field , u32 op , void * lsmrule );
2163+ int security_audit_rule_match (struct lsm_prop * prop , u32 field , u32 op ,
2164+ void * lsmrule );
20992165void security_audit_rule_free (void * lsmrule );
21002166
21012167#else
@@ -2111,8 +2177,8 @@ static inline int security_audit_rule_known(struct audit_krule *krule)
21112177 return 0 ;
21122178}
21132179
2114- static inline int security_audit_rule_match (u32 secid , u32 field , u32 op ,
2115- void * lsmrule )
2180+ static inline int security_audit_rule_match (struct lsm_prop * prop , u32 field ,
2181+ u32 op , void * lsmrule )
21162182{
21172183 return 0 ;
21182184}
0 commit comments