@@ -589,9 +589,9 @@ static int evm_protect_xattr(struct mnt_idmap *idmap,
589
589
* userspace from writing HMAC value. Writing 'security.evm' requires
590
590
* requires CAP_SYS_ADMIN privileges.
591
591
*/
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 )
595
595
{
596
596
const struct evm_ima_xattr_data * xattr_data = xattr_value ;
597
597
@@ -621,8 +621,8 @@ int evm_inode_setxattr(struct mnt_idmap *idmap, struct dentry *dentry,
621
621
* Removing 'security.evm' requires CAP_SYS_ADMIN privileges and that
622
622
* the current value is valid.
623
623
*/
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 )
626
626
{
627
627
/* Policy permits modification of the protected xattrs even though
628
628
* there's no HMAC key loaded
@@ -672,9 +672,11 @@ static inline int evm_inode_set_acl_change(struct mnt_idmap *idmap,
672
672
* Prevent modifying posix acls causing the EVM HMAC to be re-calculated
673
673
* and 'security.evm' xattr updated, unless the existing 'security.evm' is
674
674
* valid.
675
+ *
676
+ * Return: zero on success, -EPERM on failure.
675
677
*/
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 )
678
680
{
679
681
enum integrity_status evm_status ;
680
682
@@ -713,6 +715,24 @@ int evm_inode_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
713
715
return - EPERM ;
714
716
}
715
717
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
+
716
736
static void evm_reset_status (struct inode * inode )
717
737
{
718
738
struct integrity_iint_cache * iint ;
@@ -761,9 +781,11 @@ bool evm_revalidate_status(const char *xattr_name)
761
781
* __vfs_setxattr_noperm(). The caller of which has taken the inode's
762
782
* i_mutex lock.
763
783
*/
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 )
767
789
{
768
790
if (!evm_revalidate_status (xattr_name ))
769
791
return ;
@@ -782,6 +804,21 @@ void evm_inode_post_setxattr(struct dentry *dentry, const char *xattr_name,
782
804
evm_update_evmxattr (dentry , xattr_name , xattr_value , xattr_value_len );
783
805
}
784
806
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
+
785
822
/**
786
823
* evm_inode_post_removexattr - update 'security.evm' after removing the xattr
787
824
* @dentry: pointer to the affected dentry
@@ -792,7 +829,8 @@ void evm_inode_post_setxattr(struct dentry *dentry, const char *xattr_name,
792
829
* No need to take the i_mutex lock here, as this function is called from
793
830
* vfs_removexattr() which takes the i_mutex.
794
831
*/
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 )
796
834
{
797
835
if (!evm_revalidate_status (xattr_name ))
798
836
return ;
@@ -808,6 +846,22 @@ void evm_inode_post_removexattr(struct dentry *dentry, const char *xattr_name)
808
846
evm_update_evmxattr (dentry , xattr_name , NULL , 0 );
809
847
}
810
848
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
+
811
865
static int evm_attr_change (struct mnt_idmap * idmap ,
812
866
struct dentry * dentry , struct iattr * attr )
813
867
{
@@ -831,8 +885,8 @@ static int evm_attr_change(struct mnt_idmap *idmap,
831
885
* Permit update of file attributes when files have a valid EVM signature,
832
886
* except in the case of them having an immutable portable signature.
833
887
*/
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 )
836
890
{
837
891
unsigned int ia_valid = attr -> ia_valid ;
838
892
enum integrity_status evm_status ;
@@ -883,8 +937,8 @@ int evm_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
883
937
* This function is called from notify_change(), which expects the caller
884
938
* to lock the inode's i_mutex.
885
939
*/
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 )
888
942
{
889
943
if (!evm_revalidate_status (NULL ))
890
944
return ;
@@ -901,7 +955,7 @@ void evm_inode_post_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
901
955
evm_update_evmxattr (dentry , NULL , NULL , 0 );
902
956
}
903
957
904
- int evm_inode_copy_up_xattr (const char * name )
958
+ static int evm_inode_copy_up_xattr (const char * name )
905
959
{
906
960
if (strcmp (name , XATTR_NAME_EVM ) == 0 )
907
961
return 1 ; /* Discard */
@@ -1004,4 +1058,36 @@ static int __init init_evm(void)
1004
1058
return error ;
1005
1059
}
1006
1060
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
+
1007
1093
late_initcall (init_evm );
0 commit comments