[PATCH 06/14] security: imbed evm calls in security hooks

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Mimi Zohar
Date: Wednesday, April 21, 2010 - 2:49 pm

Imbed the evm calls evm_inode_setxattr(), evm_inode_post_setxattr(),
evm_inode_removexattr() in the security hooks.  evm_inode_setxattr()
protects security.evm xattr.  evm_inode_post_setxattr() and
evm_inode_removexattr() updates the hmac associated with an inode.

(Assumes an LSM module protects the setting/removing of xattr.)

Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Acked-by: Serge Hallyn <serue@us.ibm.com>

diff --git a/include/linux/evm.h b/include/linux/evm.h
new file mode 100644
index 0000000..1a30beb
--- /dev/null
+++ b/include/linux/evm.h
@@ -0,0 +1,54 @@
+/*
+ * evm.h
+ *
+ * Copyright (c) 2009 IBM Corporation
+ * Author: Mimi Zohar <zohar@us.ibm.com>
+ */
+
+#ifndef _LINUX_EVM_H
+#define _LINUX_EVM_H
+
+#include <linux/integrity.h>
+
+#ifdef CONFIG_EVM
+extern enum integrity_status evm_verifyxattr(struct dentry *dentry,
+					     char *xattr_name,
+					     char *xattr_value,
+					     size_t xattr_value_len);
+extern int evm_inode_setxattr(struct dentry *dentry, const char *name,
+			      const void *value, size_t size);
+extern void evm_inode_post_setxattr(struct dentry *dentry,
+				    const char *xattr_name,
+				    const void *xattr_value,
+				    size_t xattr_value_len);
+extern int evm_inode_removexattr(struct dentry *dentry, const char *xattr_name);
+#else
+static enum integrity_status evm_verifyxattr(struct dentry *dentry,
+					     char *xattr_name,
+					     char *xattr_value,
+					     size_t xattr_value_len)
+{
+	return INTEGRITY_UNKNOWN;
+}
+
+static inline int evm_inode_setxattr(struct dentry *dentry, const char *name,
+				     const void *value, size_t size)
+{
+	return 0;
+}
+
+static inline void evm_inode_post_setxattr(struct dentry *dentry,
+					   const char *xattr_name,
+					   const void *xattr_value,
+					   size_t xattr_value_len)
+{
+	return;
+}
+
+static inline int evm_inode_removexattr(struct dentry *dentry,
+					const char *xattr_name)
+{
+	return 0;
+}
+#endif /* CONFIG_EVM_H */
+#endif /* LINUX_EVM_H */
diff --git a/security/security.c b/security/security.c
index e42a78e..6b1e50e 100644
--- a/security/security.c
+++ b/security/security.c
@@ -18,6 +18,7 @@
 #include <linux/security.h>
 #include <linux/integrity.h>
 #include <linux/ima.h>
+#include <linux/evm.h>
 
 /* Boot-time LSM user choice */
 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
@@ -549,9 +550,14 @@ int security_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
 int security_inode_setxattr(struct dentry *dentry, const char *name,
 			    const void *value, size_t size, int flags)
 {
+	int ret;
+
 	if (unlikely(IS_PRIVATE(dentry->d_inode)))
 		return 0;
-	return security_ops->inode_setxattr(dentry, name, value, size, flags);
+	ret = security_ops->inode_setxattr(dentry, name, value, size, flags);
+	if (ret)
+		return ret;
+	return evm_inode_setxattr(dentry, name, value, size);
 }
 
 void security_inode_post_setxattr(struct dentry *dentry, const char *name,
@@ -560,6 +566,7 @@ void security_inode_post_setxattr(struct dentry *dentry, const char *name,
 	if (unlikely(IS_PRIVATE(dentry->d_inode)))
 		return;
 	security_ops->inode_post_setxattr(dentry, name, value, size, flags);
+	evm_inode_post_setxattr(dentry, name, value, size);
 }
 
 int security_inode_getxattr(struct dentry *dentry, const char *name)
@@ -578,9 +585,14 @@ int security_inode_listxattr(struct dentry *dentry)
 
 int security_inode_removexattr(struct dentry *dentry, const char *name)
 {
+	int ret;
+
 	if (unlikely(IS_PRIVATE(dentry->d_inode)))
 		return 0;
-	return security_ops->inode_removexattr(dentry, name);
+	ret = security_ops->inode_removexattr(dentry, name);
+	if (ret)
+		return ret;
+	return evm_inode_removexattr(dentry, name);
 }
 
 int security_inode_need_killpriv(struct dentry *dentry)
-- 
1.6.6.1

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/14] EVM, Mimi Zohar, (Wed Apr 21, 2:49 pm)
[PATCH 04/14] evm: re-release, Mimi Zohar, (Wed Apr 21, 2:49 pm)
[PATCH 06/14] security: imbed evm calls in security hooks, Mimi Zohar, (Wed Apr 21, 2:49 pm)
[PATCH 07/14] evm: inode post removexattr, Mimi Zohar, (Wed Apr 21, 2:49 pm)
[PATCH 08/14] evm: imbed evm_inode_post_setattr, Mimi Zohar, (Wed Apr 21, 2:49 pm)
[PATCH 09/14] evm: inode_post_init, Mimi Zohar, (Wed Apr 21, 2:49 pm)
[PATCH 10/14] fs: add evm_inode_post_init calls, Mimi Zohar, (Wed Apr 21, 2:49 pm)
[PATCH 11/14] ima: integrity appraisal extension, Mimi Zohar, (Wed Apr 21, 2:49 pm)
[PATCH 12/14] ima: appraise default rules, Mimi Zohar, (Wed Apr 21, 2:49 pm)
[PATCH 13/14] ima: inode post_setattr, Mimi Zohar, (Wed Apr 21, 2:49 pm)
Re: [PATCH 00/14] EVM, Randy Dunlap, (Wed Apr 21, 2:58 pm)
Re: [PATCH 00/14] EVM, Mimi Zohar, (Wed Apr 21, 3:18 pm)
Re: [PATCH 00/14] EVM, Randy Dunlap, (Wed Apr 21, 3:23 pm)
Re: [PATCH 00/14] EVM, Mimi Zohar, (Wed Apr 21, 3:41 pm)
Re: [PATCH 04/14] evm: re-release, Serge E. Hallyn, (Mon Apr 26, 2:03 pm)
Re: [PATCH 00/14] EVM, James Morris, (Sun May 30, 5:20 pm)
Re: [PATCH 00/14] EVM, Shaz, (Mon May 31, 3:02 am)
Re: [PATCH 00/14] EVM, Shaz, (Mon May 31, 3:08 am)
Re: [PATCH 00/14] EVM, Mimi Zohar, (Tue Jun 1, 12:28 pm)
Re: [PATCH 00/14] EVM, Dmitry Kasatkin, (Wed Jun 2, 12:03 am)
Re: [PATCH 00/14] EVM, Shaz, (Wed Jun 2, 12:50 am)
Re: [PATCH 00/14] EVM, Dmitry Kasatkin, (Wed Jun 2, 2:12 am)
Re: [PATCH 00/14] EVM, Shaz, (Wed Jun 2, 3:15 am)
Re: [PATCH 00/14] EVM, Dmitry Kasatkin, (Wed Jun 2, 3:23 am)
Re: [PATCH 00/14] EVM, Mimi Zohar, (Wed Jun 2, 7:02 am)
Re: [PATCH 00/14] EVM, James Morris, (Thu Jun 3, 5:57 pm)
Re: [PATCH 00/14] EVM, Shaz, (Thu Jun 3, 11:53 pm)
Re: [PATCH 00/14] EVM, Shaz, (Thu Jun 3, 11:56 pm)
Re: [PATCH 04/14] evm: re-release, Stephen Smalley, (Fri Jun 4, 7:28 am)
Re: [PATCH 04/14] evm: re-release, Mimi Zohar, (Fri Jun 4, 7:53 am)
Re: [PATCH 00/14] EVM, Mimi Zohar, (Fri Jun 4, 8:09 am)
Re: [PATCH 04/14] evm: re-release, Stephen Smalley, (Fri Jun 4, 8:20 am)
Re: [PATCH 04/14] evm: re-release, David Safford, (Fri Jun 4, 11:08 am)
Re: [PATCH 00/14] EVM, Shaz, (Fri Jun 4, 11:47 am)
Re: [ProbableSpam] Re: [PATCH 00/14] EVM, David Safford, (Fri Jun 4, 1:25 pm)