From: Roberto Sassu <roberto.sassu@huawei.com> To: <zohar@linux.ibm.com>, <jmorris@namei.org>, <paul@paul-moore.com>, <casey@schaufler-ca.com> Cc: <linux-integrity@vger.kernel.org>, <linux-security-module@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <selinux@vger.kernel.org>, <reiserfs-devel@vger.kernel.org>, Roberto Sassu <roberto.sassu@huawei.com> Subject: [PATCH 3/5] security: Pass xattrs allocated by LSMs to the inode_init_security hook Date: Thu, 15 Apr 2021 12:04:33 +0200 [thread overview] Message-ID: <20210415100435.18619-4-roberto.sassu@huawei.com> (raw) In-Reply-To: <20210415100435.18619-1-roberto.sassu@huawei.com> 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
WARNING: multiple messages have this Message-ID (diff)
From: Roberto Sassu <roberto.sassu@huawei.com> To: zohar@linux.ibm.com, jmorris@namei.org, paul@paul-moore.com, casey@schaufler-ca.com Cc: linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, selinux@vger.kernel.org, reiserfs-devel@vger.kernel.org, Roberto Sassu <roberto.sassu@huawei.com> Subject: [PATCH 3/5] security: Pass xattrs allocated by LSMs to the inode_init_security hook Date: Thu, 15 Apr 2021 12:04:33 +0200 [thread overview] Message-ID: <20210415100435.18619-4-roberto.sassu@huawei.com> (raw) In-Reply-To: <20210415100435.18619-1-roberto.sassu@huawei.com> 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
next prev parent reply other threads:[~2021-04-15 10:05 UTC|newest] Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-04-15 10:04 [PATCH 0/5] evm: Prepare for moving to the LSM infrastructure Roberto Sassu 2021-04-15 10:04 ` Roberto Sassu 2021-04-15 10:04 ` [PATCH 1/5] xattr: Complete constify ->name member of "struct xattr" Roberto Sassu 2021-04-15 10:04 ` Roberto Sassu 2021-04-15 11:20 ` Tetsuo Handa 2021-04-15 12:25 ` Roberto Sassu 2021-04-15 10:04 ` [PATCH 2/5] security: Support multiple LSMs implementing the inode_init_security hook Roberto Sassu 2021-04-15 10:04 ` Roberto Sassu 2021-04-15 10:04 ` Roberto Sassu [this message] 2021-04-15 10:04 ` [PATCH 3/5] security: Pass xattrs allocated by LSMs to " Roberto Sassu 2021-04-15 10:04 ` [PATCH 4/5] evm: Align evm_inode_init_security() definition with LSM infrastructure Roberto Sassu 2021-04-15 10:04 ` Roberto Sassu 2021-04-15 10:04 ` [PATCH 5/5] evm: Support multiple LSMs providing an xattr Roberto Sassu 2021-04-15 10:04 ` Roberto Sassu 2021-04-15 20:43 ` [PATCH 0/5] evm: Prepare for moving to the LSM infrastructure Casey Schaufler 2021-04-16 16:37 ` Roberto Sassu 2021-04-16 21:25 ` Casey Schaufler 2021-04-20 16:09 ` Roberto Sassu
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210415100435.18619-4-roberto.sassu@huawei.com \ --to=roberto.sassu@huawei.com \ --cc=casey@schaufler-ca.com \ --cc=jmorris@namei.org \ --cc=linux-integrity@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-security-module@vger.kernel.org \ --cc=paul@paul-moore.com \ --cc=reiserfs-devel@vger.kernel.org \ --cc=selinux@vger.kernel.org \ --cc=zohar@linux.ibm.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.