lkml.org 
[lkml]   [2021]   [Apr]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 3/5] security: Pass xattrs allocated by LSMs to the inode_init_security hook
Date
In preparation for moving EVM to the LSM infrastructure, this patch adds
the full array of xattrs allocated by LSMs as a new parameter of the
inode_init_security hook. It will be used by EVM to calculate the HMAC on
all xattrs.

This solution has been preferred to directly replacing the xattr name,
value and len with the full array, as LSMs would have had to scan it to
find an empty slot.

Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
---
include/linux/lsm_hook_defs.h | 2 +-
include/linux/lsm_hooks.h | 1 +
security/security.c | 7 ++++---
security/selinux/hooks.c | 3 ++-
security/smack/smack_lsm.c | 4 +++-
5 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index 477a597db013..45a0b8cbb974 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -112,7 +112,7 @@ LSM_HOOK(int, 0, inode_alloc_security, struct inode *inode)
LSM_HOOK(void, LSM_RET_VOID, inode_free_security, struct inode *inode)
LSM_HOOK(int, 0, inode_init_security, struct inode *inode,
struct inode *dir, const struct qstr *qstr, const char **name,
- void **value, size_t *len)
+ void **value, size_t *len, struct xattr *lsm_xattrs)
LSM_HOOK(int, 0, inode_init_security_anon, struct inode *inode,
const struct qstr *name, const struct inode *context_inode)
LSM_HOOK(int, 0, inode_create, struct inode *dir, struct dentry *dentry,
diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
index c5498f5174ce..1dd79e2f02ad 100644
--- a/include/linux/lsm_hooks.h
+++ b/include/linux/lsm_hooks.h
@@ -230,6 +230,7 @@
* @name will be set to the allocated name suffix (e.g. selinux).
* @value will be set to the allocated attribute value.
* @len will be set to the length of the value.
+ * @lsm_xattrs contains the full array of xattrs allocated by LSMs.
* Returns 0 if @name and @value have been successfully set,
* -EOPNOTSUPP if no security attribute is needed, or
* -ENOMEM on memory allocation failure.
diff --git a/security/security.c b/security/security.c
index 65624357b335..8aabbc0f0dfc 100644
--- a/security/security.c
+++ b/security/security.c
@@ -1036,7 +1036,7 @@ int security_inode_init_security(struct inode *inode, struct inode *dir,

if (!initxattrs)
return call_int_hook(inode_init_security, -EOPNOTSUPP, inode,
- dir, qstr, NULL, NULL, NULL);
+ dir, qstr, NULL, NULL, NULL, NULL);

/* Determine at run-time the max number of xattr structs to allocate. */
hlist_for_each_entry(P, &security_hook_heads.inode_init_security, list)
@@ -1056,7 +1056,8 @@ int security_inode_init_security(struct inode *inode, struct inode *dir,
ret = P->hook.inode_init_security(inode, dir, qstr,
&lsm_xattr->name,
&lsm_xattr->value,
- &lsm_xattr->value_len);
+ &lsm_xattr->value_len,
+ new_xattrs);
if (ret && ret != -EOPNOTSUPP)
goto out;

@@ -1112,7 +1113,7 @@ int security_old_inode_init_security(struct inode *inode, struct inode *dir,
hlist_for_each_entry(P, &security_hook_heads.inode_init_security,
list) {
ret = P->hook.inode_init_security(inode, dir, qstr,
- name, value, len);
+ name, value, len, NULL);
if (ret && ret != -EOPNOTSUPP)
return ret;

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index ddd097790d47..2fe9c39414d0 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -2917,7 +2917,8 @@ static int selinux_dentry_create_files_as(struct dentry *dentry, int mode,
static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
const struct qstr *qstr,
const char **name,
- void **value, size_t *len)
+ void **value, size_t *len,
+ struct xattr *lsm_xattrs)
{
const struct task_security_struct *tsec = selinux_cred(current_cred());
struct superblock_security_struct *sbsec;
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 12a45e61c1a5..9d562ea576ca 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -965,12 +965,14 @@ static int smack_inode_alloc_security(struct inode *inode)
* @name: where to put the attribute name
* @value: where to put the attribute value
* @len: where to put the length of the attribute
+ * @lsm_xattrs: unused
*
* Returns 0 if it all works out, -ENOMEM if there's no memory
*/
static int smack_inode_init_security(struct inode *inode, struct inode *dir,
const struct qstr *qstr, const char **name,
- void **value, size_t *len)
+ void **value, size_t *len,
+ struct xattr *lsm_xattrs)
{
struct inode_smack *issp = smack_inode(inode);
struct smack_known *skp = smk_of_current();
--
2.26.2
\
 
 \ /
  Last update: 2021-04-15 12:06    [W:0.083 / U:1.964 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site