evm: add evm_inode_setattr to prevent updating an invalid security.evm
authorMimi Zohar <zohar@linux.vnet.ibm.com>
Fri, 13 May 2011 16:53:38 +0000 (12:53 -0400)
committerMimi Zohar <zohar@linux.vnet.ibm.com>
Mon, 18 Jul 2011 16:29:50 +0000 (12:29 -0400)
Permit changing of security.evm only when valid, unless in fixmode.

Reported-by: Roberto Sassu <roberto.sassu@polito.it>
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
include/linux/evm.h
security/integrity/evm/evm_main.c
security/security.c

index 6d4e89b020c541216bf5b0e51d44e739e0d13e47..db5556dcdd27eb1b13faa7664263a789007ccc49 100644 (file)
@@ -19,6 +19,7 @@ extern enum integrity_status evm_verifyxattr(struct dentry *dentry,
                                             void *xattr_value,
                                             size_t xattr_value_len,
                                             struct integrity_iint_cache *iint);
+extern int evm_inode_setattr(struct dentry *dentry, struct iattr *attr);
 extern void evm_inode_post_setattr(struct dentry *dentry, int ia_valid);
 extern int evm_inode_setxattr(struct dentry *dentry, const char *name,
                              const void *value, size_t size);
@@ -44,6 +45,11 @@ static inline enum integrity_status evm_verifyxattr(struct dentry *dentry,
 }
 #endif
 
+static int evm_inode_setattr(struct dentry *dentry, struct iattr *attr)
+{
+       return 0;
+}
+
 static inline void evm_inode_post_setattr(struct dentry *dentry, int ia_valid)
 {
        return;
index 94d66af07aa4127cf8ee68536aef7eaef2dd874c..8fc5b5d7ceaaa77097b0cf5f14a86880ba0961c3 100644 (file)
@@ -277,6 +277,21 @@ void evm_inode_post_removexattr(struct dentry *dentry, const char *xattr_name)
        return;
 }
 
+/**
+ * evm_inode_setattr - prevent updating an invalid EVM extended attribute
+ * @dentry: pointer to the affected dentry
+ */
+int evm_inode_setattr(struct dentry *dentry, struct iattr *attr)
+{
+       unsigned int ia_valid = attr->ia_valid;
+       enum integrity_status evm_status;
+
+       if (ia_valid & ~(ATTR_MODE | ATTR_UID | ATTR_GID))
+               return 0;
+       evm_status = evm_verify_current_integrity(dentry);
+       return evm_status == INTEGRITY_PASS ? 0 : -EPERM;
+}
+
 /**
  * evm_inode_post_setattr - update 'security.evm' after modifying metadata
  * @dentry: pointer to the affected dentry
index 181990ae90c1e091bd20d905fc0e69fe9bcfc5b0..19251ccb2de0d09f2ed34a3e6018ffb80eb01cb2 100644 (file)
@@ -571,9 +571,14 @@ int security_inode_exec_permission(struct inode *inode, unsigned int flags)
 
 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
 {
+       int ret;
+
        if (unlikely(IS_PRIVATE(dentry->d_inode)))
                return 0;
-       return security_ops->inode_setattr(dentry, attr);
+       ret = security_ops->inode_setattr(dentry, attr);
+       if (ret)
+               return ret;
+       return evm_inode_setattr(dentry, attr);
 }
 EXPORT_SYMBOL_GPL(security_inode_setattr);