Commit 6db7d1de authored by Roberto Sassu's avatar Roberto Sassu Committed by Paul Moore

evm: Align evm_inode_init_security() definition with LSM infrastructure

Change the evm_inode_init_security() definition to align with the LSM
infrastructure. Keep the existing behavior of including in the HMAC
calculation only the first xattr provided by LSMs.

Changing the evm_inode_init_security() definition requires passing the
xattr array allocated by security_inode_init_security(), and the number of
xattrs filled by previously invoked LSMs.

Use the newly introduced lsm_get_xattr_slot() to position EVM correctly in
the xattrs array, like a regular LSM, and to increment the number of filled
slots. For now, the LSM infrastructure allocates enough xattrs slots to
store the EVM xattr, without using the reservation mechanism.
Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: default avatarMimi Zohar <zohar@linux.ibm.com>
Acked-by: default avatarMimi Zohar <zohar@linux.ibm.com>
Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
parent baed456a
...@@ -56,9 +56,10 @@ static inline void evm_inode_post_set_acl(struct dentry *dentry, ...@@ -56,9 +56,10 @@ static inline void evm_inode_post_set_acl(struct dentry *dentry,
{ {
return evm_inode_post_setxattr(dentry, acl_name, NULL, 0); return evm_inode_post_setxattr(dentry, acl_name, NULL, 0);
} }
extern int evm_inode_init_security(struct inode *inode,
const struct xattr *xattr_array, int evm_inode_init_security(struct inode *inode, struct inode *dir,
struct xattr *evm); const struct qstr *qstr, struct xattr *xattrs,
int *xattr_count);
extern bool evm_revalidate_status(const char *xattr_name); extern bool evm_revalidate_status(const char *xattr_name);
extern int evm_protected_xattr_if_enabled(const char *req_xattr_name); extern int evm_protected_xattr_if_enabled(const char *req_xattr_name);
extern int evm_read_protected_xattrs(struct dentry *dentry, u8 *buffer, extern int evm_read_protected_xattrs(struct dentry *dentry, u8 *buffer,
...@@ -157,9 +158,10 @@ static inline void evm_inode_post_set_acl(struct dentry *dentry, ...@@ -157,9 +158,10 @@ static inline void evm_inode_post_set_acl(struct dentry *dentry,
return; return;
} }
static inline int evm_inode_init_security(struct inode *inode, static inline int evm_inode_init_security(struct inode *inode, struct inode *dir,
const struct xattr *xattr_array, const struct qstr *qstr,
struct xattr *evm) struct xattr *xattrs,
int *xattr_count)
{ {
return 0; return 0;
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/evm.h> #include <linux/evm.h>
#include <linux/magic.h> #include <linux/magic.h>
#include <linux/posix_acl_xattr.h> #include <linux/posix_acl_xattr.h>
#include <linux/lsm_hooks.h>
#include <crypto/hash.h> #include <crypto/hash.h>
#include <crypto/hash_info.h> #include <crypto/hash_info.h>
...@@ -866,23 +867,26 @@ void evm_inode_post_setattr(struct dentry *dentry, int ia_valid) ...@@ -866,23 +867,26 @@ void evm_inode_post_setattr(struct dentry *dentry, int ia_valid)
/* /*
* evm_inode_init_security - initializes security.evm HMAC value * evm_inode_init_security - initializes security.evm HMAC value
*/ */
int evm_inode_init_security(struct inode *inode, int evm_inode_init_security(struct inode *inode, struct inode *dir,
const struct xattr *lsm_xattr, const struct qstr *qstr, struct xattr *xattrs,
struct xattr *evm_xattr) int *xattr_count)
{ {
struct evm_xattr *xattr_data; struct evm_xattr *xattr_data;
struct xattr *evm_xattr;
int rc; int rc;
if (!(evm_initialized & EVM_INIT_HMAC) || if (!(evm_initialized & EVM_INIT_HMAC) || !xattrs ||
!evm_protected_xattr(lsm_xattr->name)) !evm_protected_xattr(xattrs->name))
return 0; return 0;
evm_xattr = lsm_get_xattr_slot(xattrs, xattr_count);
xattr_data = kzalloc(sizeof(*xattr_data), GFP_NOFS); xattr_data = kzalloc(sizeof(*xattr_data), GFP_NOFS);
if (!xattr_data) if (!xattr_data)
return -ENOMEM; return -ENOMEM;
xattr_data->data.type = EVM_XATTR_HMAC; xattr_data->data.type = EVM_XATTR_HMAC;
rc = evm_init_hmac(inode, lsm_xattr, xattr_data->digest); rc = evm_init_hmac(inode, xattrs, xattr_data->digest);
if (rc < 0) if (rc < 0)
goto out; goto out;
......
...@@ -1647,8 +1647,8 @@ int security_inode_init_security(struct inode *inode, struct inode *dir, ...@@ -1647,8 +1647,8 @@ int security_inode_init_security(struct inode *inode, struct inode *dir,
if (!xattr_count) if (!xattr_count)
goto out; goto out;
ret = evm_inode_init_security(inode, new_xattrs, ret = evm_inode_init_security(inode, dir, qstr, new_xattrs,
&new_xattrs[xattr_count]); &xattr_count);
if (ret) if (ret)
goto out; goto out;
ret = initxattrs(inode, new_xattrs, fs_data); ret = initxattrs(inode, new_xattrs, fs_data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment