@@ -589,9 +589,9 @@ static int evm_protect_xattr(struct mnt_idmap *idmap,
589589 * userspace from writing HMAC value. Writing 'security.evm' requires
590590 * requires CAP_SYS_ADMIN privileges.
591591 */
592- int evm_inode_setxattr (struct mnt_idmap * idmap , struct dentry * dentry ,
593- const char * xattr_name , const void * xattr_value ,
594- size_t xattr_value_len , int flags )
592+ static int evm_inode_setxattr (struct mnt_idmap * idmap , struct dentry * dentry ,
593+ const char * xattr_name , const void * xattr_value ,
594+ size_t xattr_value_len , int flags )
595595{
596596 const struct evm_ima_xattr_data * xattr_data = xattr_value ;
597597
@@ -621,8 +621,8 @@ int evm_inode_setxattr(struct mnt_idmap *idmap, struct dentry *dentry,
621621 * Removing 'security.evm' requires CAP_SYS_ADMIN privileges and that
622622 * the current value is valid.
623623 */
624- int evm_inode_removexattr (struct mnt_idmap * idmap ,
625- struct dentry * dentry , const char * xattr_name )
624+ static int evm_inode_removexattr (struct mnt_idmap * idmap , struct dentry * dentry ,
625+ const char * xattr_name )
626626{
627627 /* Policy permits modification of the protected xattrs even though
628628 * there's no HMAC key loaded
@@ -672,9 +672,11 @@ static inline int evm_inode_set_acl_change(struct mnt_idmap *idmap,
672672 * Prevent modifying posix acls causing the EVM HMAC to be re-calculated
673673 * and 'security.evm' xattr updated, unless the existing 'security.evm' is
674674 * valid.
675+ *
676+ * Return: zero on success, -EPERM on failure.
675677 */
676- int evm_inode_set_acl (struct mnt_idmap * idmap , struct dentry * dentry ,
677- const char * acl_name , struct posix_acl * kacl )
678+ static int evm_inode_set_acl (struct mnt_idmap * idmap , struct dentry * dentry ,
679+ const char * acl_name , struct posix_acl * kacl )
678680{
679681 enum integrity_status evm_status ;
680682
@@ -713,6 +715,24 @@ int evm_inode_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
713715 return - EPERM ;
714716}
715717
718+ /**
719+ * evm_inode_remove_acl - Protect the EVM extended attribute from posix acls
720+ * @idmap: idmap of the mount
721+ * @dentry: pointer to the affected dentry
722+ * @acl_name: name of the posix acl
723+ *
724+ * Prevent removing posix acls causing the EVM HMAC to be re-calculated
725+ * and 'security.evm' xattr updated, unless the existing 'security.evm' is
726+ * valid.
727+ *
728+ * Return: zero on success, -EPERM on failure.
729+ */
730+ static int evm_inode_remove_acl (struct mnt_idmap * idmap , struct dentry * dentry ,
731+ const char * acl_name )
732+ {
733+ return evm_inode_set_acl (idmap , dentry , acl_name , NULL );
734+ }
735+
716736static void evm_reset_status (struct inode * inode )
717737{
718738 struct integrity_iint_cache * iint ;
@@ -761,9 +781,11 @@ bool evm_revalidate_status(const char *xattr_name)
761781 * __vfs_setxattr_noperm(). The caller of which has taken the inode's
762782 * i_mutex lock.
763783 */
764- void evm_inode_post_setxattr (struct dentry * dentry , const char * xattr_name ,
765- const void * xattr_value , size_t xattr_value_len ,
766- int flags )
784+ static void evm_inode_post_setxattr (struct dentry * dentry ,
785+ const char * xattr_name ,
786+ const void * xattr_value ,
787+ size_t xattr_value_len ,
788+ int flags )
767789{
768790 if (!evm_revalidate_status (xattr_name ))
769791 return ;
@@ -782,6 +804,21 @@ void evm_inode_post_setxattr(struct dentry *dentry, const char *xattr_name,
782804 evm_update_evmxattr (dentry , xattr_name , xattr_value , xattr_value_len );
783805}
784806
807+ /**
808+ * evm_inode_post_set_acl - Update the EVM extended attribute from posix acls
809+ * @dentry: pointer to the affected dentry
810+ * @acl_name: name of the posix acl
811+ * @kacl: pointer to the posix acls
812+ *
813+ * Update the 'security.evm' xattr with the EVM HMAC re-calculated after setting
814+ * posix acls.
815+ */
816+ static void evm_inode_post_set_acl (struct dentry * dentry , const char * acl_name ,
817+ struct posix_acl * kacl )
818+ {
819+ return evm_inode_post_setxattr (dentry , acl_name , NULL , 0 , 0 );
820+ }
821+
785822/**
786823 * evm_inode_post_removexattr - update 'security.evm' after removing the xattr
787824 * @dentry: pointer to the affected dentry
@@ -792,7 +829,8 @@ void evm_inode_post_setxattr(struct dentry *dentry, const char *xattr_name,
792829 * No need to take the i_mutex lock here, as this function is called from
793830 * vfs_removexattr() which takes the i_mutex.
794831 */
795- void evm_inode_post_removexattr (struct dentry * dentry , const char * xattr_name )
832+ static void evm_inode_post_removexattr (struct dentry * dentry ,
833+ const char * xattr_name )
796834{
797835 if (!evm_revalidate_status (xattr_name ))
798836 return ;
@@ -808,6 +846,22 @@ void evm_inode_post_removexattr(struct dentry *dentry, const char *xattr_name)
808846 evm_update_evmxattr (dentry , xattr_name , NULL , 0 );
809847}
810848
849+ /**
850+ * evm_inode_post_remove_acl - Update the EVM extended attribute from posix acls
851+ * @idmap: idmap of the mount
852+ * @dentry: pointer to the affected dentry
853+ * @acl_name: name of the posix acl
854+ *
855+ * Update the 'security.evm' xattr with the EVM HMAC re-calculated after
856+ * removing posix acls.
857+ */
858+ static inline void evm_inode_post_remove_acl (struct mnt_idmap * idmap ,
859+ struct dentry * dentry ,
860+ const char * acl_name )
861+ {
862+ evm_inode_post_removexattr (dentry , acl_name );
863+ }
864+
811865static int evm_attr_change (struct mnt_idmap * idmap ,
812866 struct dentry * dentry , struct iattr * attr )
813867{
@@ -831,8 +885,8 @@ static int evm_attr_change(struct mnt_idmap *idmap,
831885 * Permit update of file attributes when files have a valid EVM signature,
832886 * except in the case of them having an immutable portable signature.
833887 */
834- int evm_inode_setattr (struct mnt_idmap * idmap , struct dentry * dentry ,
835- struct iattr * attr )
888+ static int evm_inode_setattr (struct mnt_idmap * idmap , struct dentry * dentry ,
889+ struct iattr * attr )
836890{
837891 unsigned int ia_valid = attr -> ia_valid ;
838892 enum integrity_status evm_status ;
@@ -883,8 +937,8 @@ int evm_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
883937 * This function is called from notify_change(), which expects the caller
884938 * to lock the inode's i_mutex.
885939 */
886- void evm_inode_post_setattr (struct mnt_idmap * idmap , struct dentry * dentry ,
887- int ia_valid )
940+ static void evm_inode_post_setattr (struct mnt_idmap * idmap ,
941+ struct dentry * dentry , int ia_valid )
888942{
889943 if (!evm_revalidate_status (NULL ))
890944 return ;
@@ -901,7 +955,7 @@ void evm_inode_post_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
901955 evm_update_evmxattr (dentry , NULL , NULL , 0 );
902956}
903957
904- int evm_inode_copy_up_xattr (const char * name )
958+ static int evm_inode_copy_up_xattr (const char * name )
905959{
906960 if (strcmp (name , XATTR_NAME_EVM ) == 0 )
907961 return 1 ; /* Discard */
@@ -1004,4 +1058,36 @@ static int __init init_evm(void)
10041058 return error ;
10051059}
10061060
1061+ static struct security_hook_list evm_hooks [] __ro_after_init = {
1062+ LSM_HOOK_INIT (inode_setattr , evm_inode_setattr ),
1063+ LSM_HOOK_INIT (inode_post_setattr , evm_inode_post_setattr ),
1064+ LSM_HOOK_INIT (inode_copy_up_xattr , evm_inode_copy_up_xattr ),
1065+ LSM_HOOK_INIT (inode_setxattr , evm_inode_setxattr ),
1066+ LSM_HOOK_INIT (inode_post_setxattr , evm_inode_post_setxattr ),
1067+ LSM_HOOK_INIT (inode_set_acl , evm_inode_set_acl ),
1068+ LSM_HOOK_INIT (inode_post_set_acl , evm_inode_post_set_acl ),
1069+ LSM_HOOK_INIT (inode_remove_acl , evm_inode_remove_acl ),
1070+ LSM_HOOK_INIT (inode_post_remove_acl , evm_inode_post_remove_acl ),
1071+ LSM_HOOK_INIT (inode_removexattr , evm_inode_removexattr ),
1072+ LSM_HOOK_INIT (inode_post_removexattr , evm_inode_post_removexattr ),
1073+ LSM_HOOK_INIT (inode_init_security , evm_inode_init_security ),
1074+ };
1075+
1076+ static const struct lsm_id evm_lsmid = {
1077+ .name = "evm" ,
1078+ .id = LSM_ID_EVM ,
1079+ };
1080+
1081+ static int __init init_evm_lsm (void )
1082+ {
1083+ security_add_hooks (evm_hooks , ARRAY_SIZE (evm_hooks ), & evm_lsmid );
1084+ return 0 ;
1085+ }
1086+
1087+ DEFINE_LSM (evm ) = {
1088+ .name = "evm" ,
1089+ .init = init_evm_lsm ,
1090+ .order = LSM_ORDER_LAST ,
1091+ };
1092+
10071093late_initcall (init_evm );
0 commit comments