security,fs,nfs,net: update security_inode_listsecurity() interface
Subsystems (9)
Stephen Smalley
maintainerPATCH v2 1/1 security,fs,nfs,net: update security_inode_listsecurity() interface
Update the security_inode_listsecurity() interface to allow use of the xattr_list_one() helper and update the hook implementations.
---
This patch is relative to the one linked above, which in theory is on vfs.fixes but doesn't appear to have been pushed when I looked.
fs/nfs/nfs4proc.c | 10 ++++++---- fs/xattr.c | 19 +++++++------------ include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 5 +++-- net/socket.c | 17 +++++++---------- security/security.c | 16 ++++++++-------- security/selinux/hooks.c | 10 +++------- security/smack/smack_lsm.c | 13 ++++--------- 8 files changed, 40 insertions(+), 54 deletions(-)
fs/nfs/nfs4proc.c +6 -4
@@ -8023,12 +8023,14 @@ static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler,static ssize_t nfs4_listxattr_nfs4_label (struct inode *inode,char *list,size_t list_len) { -int len =0 ; +ssize_t len =0 ;if (nfs_server_capable (inode,NFS_CAP_SECURITY_LABEL )) { - len =security_inode_listsecurity (inode, list, list_len); -if (len >=0 && list_len && len > list_len) -return -ERANGE ; +ssize_t remaining = list_len; + + len =security_inode_listsecurity (inode, &list, &remaining); +if (!len) + len = list_len - remaining; }return len; }
fs/xattr.c +7 -12
@@ -492,9 +492,11 @@ vfs_listxattr(struct dentry *dentry, char *list, size_t size)if (inode->i_op->listxattr) { error = inode->i_op->listxattr (dentry, list, size); }else { - error =security_inode_listsecurity (inode, list, size); -if (size && error > size) - error = -ERANGE ; +ssize_t remaining = size; + + error =security_inode_listsecurity (inode, &list, &remaining); +if (!error) + error = size - remaining; }return error; }
@@ -1469,17 +1471,10 @@ ssize_t simple_xattr_list(struct inode *inode, struct simple_xattrs *xattrs,if (err)return err; - err =security_inode_listsecurity (inode, buffer, remaining_size); -if (err <0 ) + err =security_inode_listsecurity (inode, &buffer, &remaining_size); +if (err)return err; -if (buffer) { -if (remaining_size < err) -return -ERANGE ; - buffer += err; - } - remaining_size -= err; -read_lock (&xattrs->lock);for (rbp =rb_first (&xattrs->rb_root); rbp; rbp =rb_next (rbp)) { xattr = rb_entry(rbp, struct simple_xattr, rb_node);
include/linux/lsm_hook_defs.h +2 -2
@@ -174,8 +174,8 @@ LSM_HOOK(int, -EOPNOTSUPP, inode_getsecurity, struct mnt_idmap *idmap, struct inode *inode, const char *name, void **buffer, bool alloc) LSM_HOOK(int, -EOPNOTSUPP, inode_setsecurity, struct inode *inode, const char *name, const void *value, size_t size, int flags) -LSM_HOOK(int, 0, inode_listsecurity, struct inode *inode, char *buffer, - size_t buffer_size) +LSM_HOOK(int, 0, inode_listsecurity, struct inode *inode, char **buffer, + ssize_t *remaining_size) LSM_HOOK(void, LSM_RET_VOID, inode_getlsmprop, struct inode *inode, struct lsm_prop *prop) LSM_HOOK(int, 0, inode_copy_up, struct dentry *src, struct cred **new)
include/linux/security.h +3 -2
@@ -457,7 +457,7 @@ int security_inode_getsecurity(struct mnt_idmap *idmap, struct inode *inode, const char *name, void **buffer, bool alloc);int security_inode_setsecurity (struct inode *inode,const char *name,const void *value,size_t size,int flags); -int security_inode_listsecurity (struct inode *inode,char *buffer,size_t buffer_size); +int security_inode_listsecurity (struct inode *inode,char **buffer,ssize_t *remaining_size);void security_inode_getlsmprop (struct inode *inode,struct lsm_prop *prop);int security_inode_copy_up (struct dentry *src,struct cred **new);int security_inode_copy_up_xattr (struct dentry *src,const char *name);
@@ -1077,7 +1077,8 @@ static inline int security_inode_setsecurity(struct inode *inode, const char *nareturn -EOPNOTSUPP ; } -static inline int security_inode_listsecurity (struct inode *inode,char *buffer,size_t buffer_size) +static inline int security_inode_listsecurity (struct inode *inode, +char **buffer,ssize_t *remaining_size) {return 0 ; }
net/socket.c +7 -10
@@ -560,17 +560,14 @@ static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer, size_t size) {ssize_t len; -ssize_t used =0 ; +ssize_t used, remaining; +int err; - len =security_inode_listsecurity (d_inode (dentry), buffer, size); -if (len <0 ) -return len; - used += len; -if (buffer) { -if (size < used) -return -ERANGE ; - buffer += len; - } + err =security_inode_listsecurity (d_inode (dentry), &buffer, + &remaining); +if (err) +return err; + used = size - remaining; len = (XATTR_NAME_SOCKPROTONAME_LEN +1 ); used += len;
security/security.c +8 -8
@@ -2710,22 +2710,22 @@ int security_inode_setsecurity(struct inode *inode, const char *name,/** * security_inode_listsecurity() - List the xattr security label names * @inode: inode -* @buffer: buffer -* @buffer_size: size of buffer +* @buffer: pointer to buffer +* @remaining_size: pointer to remaining size of buffer * * Copy the extended attribute names for the security labels associated with -* @inode into @buffer. The maximum size of @buffer is specified by -* @buffer_size. @buffer may be NULL to request the size of the buffer -* required. +* @inode into *(@buffer). The remaining size of @buffer is specified by +* *(@remaining_size). *(@buffer) may be NULL to request the size of the +* buffer required. Updates *(@buffer) and *(@remaining_size). * -* Return: Returns number of bytes used/required on success. +* Return: Returns 0 on success, or -errno on failure. */ int security_inode_listsecurity (struct inode *inode, -char *buffer,size_t buffer_size) +char **buffer,ssize_t *remaining_size) {if (unlikely (IS_PRIVATE (inode)))return 0 ; -return call_int_hook (inode_listsecurity, inode, buffer, buffer_size); +return call_int_hook (inode_listsecurity, inode, buffer, remaining_size); }EXPORT_SYMBOL (security_inode_listsecurity);
security/selinux/hooks.c +3 -7
@@ -3612,16 +3612,12 @@ static int selinux_inode_setsecurity(struct inode *inode, const char *name,return 0 ; } -static int selinux_inode_listsecurity (struct inode *inode,char *buffer,size_t buffer_size) +static int selinux_inode_listsecurity (struct inode *inode,char **buffer, +ssize_t *remaining_size) { -const int len =sizeof (XATTR_NAME_SELINUX ); -if (!selinux_initialized ())return 0 ; - -if (buffer && len <= buffer_size) -memcpy (buffer,XATTR_NAME_SELINUX , len); -return len; +return xattr_list_one (buffer, remaining_size,XATTR_NAME_SELINUX ); }static void selinux_inode_getlsmprop (struct inode *inode,struct lsm_prop *prop)
security/smack/smack_lsm.c +4 -9
@@ -1619,17 +1619,12 @@ static int smack_inode_getsecurity(struct mnt_idmap *idmap,* smack_inode_listsecurity - list the Smack attributes * @inode: the object * @buffer: where they go -* @buffer_size: size of buffer +* @remaining_size: size of buffer */ -static int smack_inode_listsecurity (struct inode *inode,char *buffer, -size_t buffer_size) +static int smack_inode_listsecurity (struct inode *inode,char **buffer, +ssize_t *remaining_size) { -int len =sizeof (XATTR_NAME_SMACK ); - -if (buffer !=NULL && len <= buffer_size) -memcpy (buffer,XATTR_NAME_SMACK , len); - -return len; +return xattr_list_one (buffer, remaining_size,XATTR_NAME_SMACK ); }/**
Signature · 1 line
2.49.0
Christian Brauner
maintainerQuoted 10 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>---
This patch is relative to the one linked above, which in theory is on vfs.fixes but doesn't appear to have been pushed when I looked.
It should be now.
Thanks for doing this.
Stephen Smalley
maintainerQuoted 8 lines · Christian Brauner
Quoted 6 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Stephen Smalley <[email protected]>---
This patch is relative to the one linked above, which in theory is on vfs.fixes but doesn't appear to have been pushed when I looked.It should be now.
Thanks for doing this.
Maybe I am looking in the wrong place?
$ git remote -v | grep vfs vfs https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git (fetch) vfs https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git (push) $ git fetch vfs $ git log vfs/vfs.fixes fs/xattr.c commit f520bed25d17bb31c2d2d72b0a785b593a4e3179 (tag: vfs-6.15-rc4.fixes, vfs/vfs.fixes, vfs.fixes) Author: Jan Kara <[email protected]> Date: Thu Apr 24 15:22:47 2025 +0200
fs/xattr: Fix handling of AT_FDCWD in setxattrat(2) and getxattrat(2)
Currently, setxattrat(2) and getxattrat(2) are wrongly handling the calls of the from setxattrat(AF_FDCWD, NULL, AT_EMPTY_PATH, ...) and fail with -EBADF error instead of operating on CWD. Fix it.
commit 46a7fcec097da5b3188dce608362fe6bf4ea26ee (tag: pull-xattr, viro/work.xattr2)
Author: Colin Ian King <[email protected]> Date: Wed Oct 30 18:25:47 2024 +0000
xattr: remove redundant check on variable err
Curretly in function generic_listxattr the for_each_xattr_handler loop checks err and will return out of the function if err is non-zero. It's impossible for err to be non-zero at the end of the function where err is checked again for a non-zero value. The final non-zero check is therefore redundant and can be removed. Also move the declaration of err into the loop.
Paul Moore
maintainerQuoted 12 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>---
This patch is relative to the one linked above, which in theory is on vfs.fixes but doesn't appear to have been pushed when I looked.
Quoted 9 lines
fs/nfs/nfs4proc.c | 10 ++++++---- fs/xattr.c | 19 +++++++------------ include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 5 +++-- net/socket.c | 17 +++++++---------- security/security.c | 16 ++++++++-------- security/selinux/hooks.c | 10 +++------- security/smack/smack_lsm.c | 13 ++++--------- 8 files changed, 40 insertions(+), 54 deletions(-)
Thanks Stephen. Once we get ACKs from the NFS, netdev, and Smack folks I can pull this into the LSM tree.
Signature · 1 line
paul-moore.com
Paul Moore
maintainerQuoted 24 lines · Paul Moore
Quoted 12 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>---
This patch is relative to the one linked above, which in theory is on vfs.fixes but doesn't appear to have been pushed when I looked.Quoted 9 lines
fs/nfs/nfs4proc.c | 10 ++++++---- fs/xattr.c | 19 +++++++------------ include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 5 +++-- net/socket.c | 17 +++++++---------- security/security.c | 16 ++++++++-------- security/selinux/hooks.c | 10 +++------- security/smack/smack_lsm.c | 13 ++++--------- 8 files changed, 40 insertions(+), 54 deletions(-)
Quoted 2 lines
Thanks Stephen. Once we get ACKs from the NFS, netdev, and Smack folks I can pull this into the LSM tree.
Gentle ping for Trond, Anna, Jakub, and Casey ... can I get some ACKs on this patch? It's a little late for the upcoming merge window, but I'd like to merge this via the LSM tree after the merge window closes.
Link to the patch if you can't find it in your inbox:
https://lore.kernel.org/linux-security-module/[email protected]/
--
paul-moore.com
Quoted 10 lines · Paul Moore
Quoted 9 lines · Paul Moore
Quoted 7 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>
I haven't been able to test the change in Smack, but it appears reasonable.
Quoted 25 lines
Quoted 13 lines
Quoted 4 lines
---
This patch is relative to the one linked above, which in theory is on vfs.fixes but doesn't appear to have been pushed when I looked.Quoted 9 lines
fs/nfs/nfs4proc.c | 10 ++++++---- fs/xattr.c | 19 +++++++------------ include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 5 +++-- net/socket.c | 17 +++++++---------- security/security.c | 16 ++++++++-------- security/selinux/hooks.c | 10 +++------- security/smack/smack_lsm.c | 13 ++++--------- 8 files changed, 40 insertions(+), 54 deletions(-)Quoted 2 lines
Thanks Stephen. Once we get ACKs from the NFS, netdev, and Smack folks I can pull this into the LSM tree.
Gentle ping for Trond, Anna, Jakub, and Casey ... can I get some ACKs on this patch? It's a little late for the upcoming merge window, but I'd like to merge this via the LSM tree after the merge window closes.
Link to the patch if you can't find it in your inbox:
https://lore.kernel.org/linux-security-module/[email protected]/--
paul-moore.com
Anna Schumaker
Acked-byQuoted 25 lines · Paul Moore
Quoted 24 lines · Paul Moore
Quoted 21 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>---
This patch is relative to the one linked above, which in theory is on vfs.fixes but doesn't appear to have been pushed when I looked.fs/nfs/nfs4proc.c | 10 ++++++---- fs/xattr.c | 19 +++++++------------ include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 5 +++-- net/socket.c | 17 +++++++---------- security/security.c | 16 ++++++++-------- security/selinux/hooks.c | 10 +++------- security/smack/smack_lsm.c | 13 ++++--------- 8 files changed, 40 insertions(+), 54 deletions(-)
Quoted 6 lines
Quoted 2 lines
Thanks Stephen. Once we get ACKs from the NFS, netdev, and Smack folks I can pull this into the LSM tree.
Gentle ping for Trond, Anna, Jakub, and Casey ... can I get some ACKs on this patch? It's a little late for the upcoming merge window, but I'd like to merge this via the LSM tree after the merge window closes.
For the NFS change:
Anna
Quoted 6 lines
Link to the patch if you can't find it in your inbox:
https://lore.kernel.org/linux-security-module/[email protected]/--
paul-moore.com
Paul Moore
maintainerQuoted 29 lines · Anna Schumaker
Quoted 28 lines · Paul Moore
Quoted 26 lines · Paul Moore
Quoted 12 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>---
This patch is relative to the one linked above, which in theory is on vfs.fixes but doesn't appear to have been pushed when I looked.Quoted 9 lines
fs/nfs/nfs4proc.c | 10 ++++++---- fs/xattr.c | 19 +++++++------------ include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 5 +++-- net/socket.c | 17 +++++++---------- security/security.c | 16 ++++++++-------- security/selinux/hooks.c | 10 +++------- security/smack/smack_lsm.c | 13 ++++--------- 8 files changed, 40 insertions(+), 54 deletions(-)Thanks Stephen. Once we get ACKs from the NFS, netdev, and Smack folks I can pull this into the LSM tree.
Quoted 6 lines
Quoted 3 lines
Gentle ping for Trond, Anna, Jakub, and Casey ... can I get some ACKs on this patch? It's a little late for the upcoming merge window, but I'd like to merge this via the LSM tree after the merge window closes.
For the NFS change:
Acked-by Anna Schumaker <[email protected]>
Hi Anna,
Thanks for reviewing the patch. Unfortunately when merging the patch today and fixing up some merge conflicts I bumped into an odd case in the NFS space and I wanted to check with you on how you would like to resolve it.
Commit 243fea134633 ("NFSv4.2: fix listxattr to return selinux security label")[1] adds a direct call to security_inode_listsecurity() in nfs4_listxattr(), despite the existing nfs4_listxattr_nfs4_label() call which calls into the same LSM hook, although that call is conditional on the server supporting NFS_CAP_SECURITY_LABEL. Based on a quick search, it appears the only caller for nfs4_listxattr_nfs4_label() is nfs4_listxattr() so I'm wondering if there isn't some room for improvement here.
I think there are two obvious options, and I'm curious about your thoughts on which of these you would prefer, or if there is another third option that you would like to see merged.
Option #1:
Essentially back out commit 243fea134633, removing the direct LSM call in nfs4_listxattr() and relying on the nfs4_listxattr_nfs4_label() for the LSM/SELinux xattrs. I think we would want to remove the NFS_CAP_SECURITY_LABEL check and build nfs4_listxattr_nfs4_label() regardless of CONFIG_NFS_V4_SECURITY_LABEL.
Option #2:
Remove nfs4_listxattr_nfs4_label() entirely and keep the direct LSM call in nfs4_listxattr(), with the required changes for this patch.
Thoughts?
[1] https://lore.kernel.org/all/[email protected]/
Signature · 1 line
paul-moore.com
Paul Moore
maintainerQuoted 65 lines · Paul Moore
Quoted 29 lines · Anna Schumaker
Quoted 28 lines · Paul Moore
Quoted 26 lines · Paul Moore
Quoted 12 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>---
This patch is relative to the one linked above, which in theory is on vfs.fixes but doesn't appear to have been pushed when I looked.Quoted 9 lines
fs/nfs/nfs4proc.c | 10 ++++++---- fs/xattr.c | 19 +++++++------------ include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 5 +++-- net/socket.c | 17 +++++++---------- security/security.c | 16 ++++++++-------- security/selinux/hooks.c | 10 +++------- security/smack/smack_lsm.c | 13 ++++--------- 8 files changed, 40 insertions(+), 54 deletions(-)Thanks Stephen. Once we get ACKs from the NFS, netdev, and Smack folks I can pull this into the LSM tree.
Quoted 6 lines
Quoted 3 lines
Gentle ping for Trond, Anna, Jakub, and Casey ... can I get some ACKs on this patch? It's a little late for the upcoming merge window, but I'd like to merge this via the LSM tree after the merge window closes.
For the NFS change:
Acked-by Anna Schumaker <[email protected]>Hi Anna,
Thanks for reviewing the patch. Unfortunately when merging the patch today and fixing up some merge conflicts I bumped into an odd case in the NFS space and I wanted to check with you on how you would like to resolve it.
Commit
243fea134633("NFSv4.2: fix listxattr to return selinux security label")[1] adds a direct call tosecurity_inode_listsecurity()innfs4_listxattr(), despite the existingnfs4_listxattr_nfs4_label()call which calls into the same LSM hook, although that call is conditional on the server supportingNFS_CAP_SECURITY_LABEL. Based on a quick search, it appears the only caller fornfs4_listxattr_nfs4_label()isnfs4_listxattr()so I'm wondering if there isn't some room for improvement here.I think there are two obvious options, and I'm curious about your thoughts on which of these you would prefer, or if there is another third option that you would like to see merged.
Option #1:
Essentially back out commit243fea134633, removing the direct LSM call innfs4_listxattr()and relying on thenfs4_listxattr_nfs4_label()for the LSM/SELinux xattrs. I think we would want to remove theNFS_CAP_SECURITY_LABELcheck and buildnfs4_listxattr_nfs4_label()regardless ofCONFIG_NFS_V4_SECURITY_LABEL.
Quoted 7 lines
Option #2:
Removenfs4_listxattr_nfs4_label()entirely and keep the direct LSM call innfs4_listxattr(), with the required changes for this patch.Thoughts?
A gentle ping on the question above for the NFS folks. If I don't hear anything I'll hack up something and send it out for review, but I thought it would nice if we could sort out the proper fix first.
Signature · 1 line
paul-moore.com
Stephen Smalley
maintainerQuoted 71 lines · Paul Moore
Quoted 69 lines · Paul Moore
Quoted 29 lines · Anna Schumaker
Quoted 28 lines · Paul Moore
Quoted 26 lines · Paul Moore
Quoted 12 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>---
This patch is relative to the one linked above, which in theory is on vfs.fixes but doesn't appear to have been pushed when I looked.Quoted 9 lines
fs/nfs/nfs4proc.c | 10 ++++++---- fs/xattr.c | 19 +++++++------------ include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 5 +++-- net/socket.c | 17 +++++++---------- security/security.c | 16 ++++++++-------- security/selinux/hooks.c | 10 +++------- security/smack/smack_lsm.c | 13 ++++--------- 8 files changed, 40 insertions(+), 54 deletions(-)Thanks Stephen. Once we get ACKs from the NFS, netdev, and Smack folks I can pull this into the LSM tree.
Quoted 6 lines
Quoted 3 lines
Gentle ping for Trond, Anna, Jakub, and Casey ... can I get some ACKs on this patch? It's a little late for the upcoming merge window, but I'd like to merge this via the LSM tree after the merge window closes.
For the NFS change:
Acked-by Anna Schumaker <[email protected]>Hi Anna,
Thanks for reviewing the patch. Unfortunately when merging the patch today and fixing up some merge conflicts I bumped into an odd case in the NFS space and I wanted to check with you on how you would like to resolve it.
Commit
243fea134633("NFSv4.2: fix listxattr to return selinux security label")[1] adds a direct call tosecurity_inode_listsecurity()innfs4_listxattr(), despite the existingnfs4_listxattr_nfs4_label()call which calls into the same LSM hook, although that call is conditional on the server supportingNFS_CAP_SECURITY_LABEL. Based on a quick search, it appears the only caller fornfs4_listxattr_nfs4_label()isnfs4_listxattr()so I'm wondering if there isn't some room for improvement here.I think there are two obvious options, and I'm curious about your thoughts on which of these you would prefer, or if there is another third option that you would like to see merged.
Option #1:
Essentially back out commit243fea134633, removing the direct LSM call innfs4_listxattr()and relying on thenfs4_listxattr_nfs4_label()for the LSM/SELinux xattrs. I think we would want to remove theNFS_CAP_SECURITY_LABELcheck and buildnfs4_listxattr_nfs4_label()regardless ofCONFIG_NFS_V4_SECURITY_LABEL.Option #2:
Removenfs4_listxattr_nfs4_label()entirely and keep the direct LSM call innfs4_listxattr(), with the required changes for this patch.
Quoted 7 lines
Quoted 3 lines
Thoughts?
A gentle ping on the question above for the NFS folks. If I don't hear anything I'll hack up something and send it out for review, but I thought it would nice if we could sort out the proper fix first.
Raising this thread back up again to see if the NFS folks have a preference on option #1 or #2 above, or
something else altogether. Should returning of the security.selinux xattr name from listxattr() be dependent on NFS_CAP_SECURITY_LABEL being set by the server and should it be dependent on CONFIG_NFS_V4_SECURITY_LABEL?
Paul Moore
maintainerQuoted 79 lines · Stephen Smalley
Quoted 70 lines · Paul Moore
Quoted 69 lines · Paul Moore
Quoted 29 lines · Anna Schumaker
Quoted 28 lines · Paul Moore
Quoted 26 lines · Paul Moore
Quoted 12 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>---
This patch is relative to the one linked above, which in theory is on vfs.fixes but doesn't appear to have been pushed when I looked.Quoted 9 lines
fs/nfs/nfs4proc.c | 10 ++++++---- fs/xattr.c | 19 +++++++------------ include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 5 +++-- net/socket.c | 17 +++++++---------- security/security.c | 16 ++++++++-------- security/selinux/hooks.c | 10 +++------- security/smack/smack_lsm.c | 13 ++++--------- 8 files changed, 40 insertions(+), 54 deletions(-)Thanks Stephen. Once we get ACKs from the NFS, netdev, and Smack folks I can pull this into the LSM tree.
Quoted 6 lines
Quoted 3 lines
Gentle ping for Trond, Anna, Jakub, and Casey ... can I get some ACKs on this patch? It's a little late for the upcoming merge window, but I'd like to merge this via the LSM tree after the merge window closes.
For the NFS change:
Acked-by Anna Schumaker <[email protected]>Hi Anna,
Thanks for reviewing the patch. Unfortunately when merging the patch today and fixing up some merge conflicts I bumped into an odd case in the NFS space and I wanted to check with you on how you would like to resolve it.
Commit
243fea134633("NFSv4.2: fix listxattr to return selinux security label")[1] adds a direct call tosecurity_inode_listsecurity()innfs4_listxattr(), despite the existingnfs4_listxattr_nfs4_label()call which calls into the same LSM hook, although that call is conditional on the server supportingNFS_CAP_SECURITY_LABEL. Based on a quick search, it appears the only caller fornfs4_listxattr_nfs4_label()isnfs4_listxattr()so I'm wondering if there isn't some room for improvement here.I think there are two obvious options, and I'm curious about your thoughts on which of these you would prefer, or if there is another third option that you would like to see merged.
Option #1:
Essentially back out commit243fea134633, removing the direct LSM call innfs4_listxattr()and relying on thenfs4_listxattr_nfs4_label()for the LSM/SELinux xattrs. I think we would want to remove theNFS_CAP_SECURITY_LABELcheck and buildnfs4_listxattr_nfs4_label()regardless ofCONFIG_NFS_V4_SECURITY_LABEL.Option #2:
Removenfs4_listxattr_nfs4_label()entirely and keep the direct LSM call innfs4_listxattr(), with the required changes for this patch.Quoted 7 lines
Quoted 3 lines
Thoughts?
A gentle ping on the question above for the NFS folks. If I don't hear anything I'll hack up something and send it out for review, but I thought it would nice if we could sort out the proper fix first.
Quoted 6 lines
Raising this thread back up again to see if the NFS folks have a preference on option #1 or #2 above, or
something else altogether. Should returning of the security.selinux xattr name fromlistxattr()be dependent onNFS_CAP_SECURITY_LABELbeing set by the server and should it be dependent onCONFIG_NFS_V4_SECURITY_LABEL?
Thanks for bringing this back up Stephen, it would be good to get this resolved.
Signature · 1 line
paul-moore.com
Stephen Smalley
maintainerQuoted 82 lines · Paul Moore
Quoted 79 lines · Stephen Smalley
Quoted 77 lines · Paul Moore
Quoted 65 lines · Paul Moore
Quoted 29 lines · Anna Schumaker
Quoted 28 lines · Paul Moore
Quoted 26 lines · Paul Moore
Quoted 12 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>---
This patch is relative to the one linked above, which in theory is on vfs.fixes but doesn't appear to have been pushed when I looked.Quoted 9 lines
fs/nfs/nfs4proc.c | 10 ++++++---- fs/xattr.c | 19 +++++++------------ include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 5 +++-- net/socket.c | 17 +++++++---------- security/security.c | 16 ++++++++-------- security/selinux/hooks.c | 10 +++------- security/smack/smack_lsm.c | 13 ++++--------- 8 files changed, 40 insertions(+), 54 deletions(-)Thanks Stephen. Once we get ACKs from the NFS, netdev, and Smack folks I can pull this into the LSM tree.
Quoted 6 lines
Quoted 3 lines
Gentle ping for Trond, Anna, Jakub, and Casey ... can I get some ACKs on this patch? It's a little late for the upcoming merge window, but I'd like to merge this via the LSM tree after the merge window closes.
For the NFS change:
Acked-by Anna Schumaker <[email protected]>Hi Anna,
Thanks for reviewing the patch. Unfortunately when merging the patch today and fixing up some merge conflicts I bumped into an odd case in the NFS space and I wanted to check with you on how you would like to resolve it.
Commit
243fea134633("NFSv4.2: fix listxattr to return selinux security label")[1] adds a direct call tosecurity_inode_listsecurity()innfs4_listxattr(), despite the existingnfs4_listxattr_nfs4_label()call which calls into the same LSM hook, although that call is conditional on the server supportingNFS_CAP_SECURITY_LABEL. Based on a quick search, it appears the only caller fornfs4_listxattr_nfs4_label()isnfs4_listxattr()so I'm wondering if there isn't some room for improvement here.I think there are two obvious options, and I'm curious about your thoughts on which of these you would prefer, or if there is another third option that you would like to see merged.
Option #1:
Essentially back out commit243fea134633, removing the direct LSM call innfs4_listxattr()and relying on thenfs4_listxattr_nfs4_label()for the LSM/SELinux xattrs. I think we would want to remove theNFS_CAP_SECURITY_LABELcheck and buildnfs4_listxattr_nfs4_label()regardless ofCONFIG_NFS_V4_SECURITY_LABEL.Quoted 7 lines
Option #2:
Removenfs4_listxattr_nfs4_label()entirely and keep the direct LSM call innfs4_listxattr(), with the required changes for this patch.Thoughts?
A gentle ping on the question above for the NFS folks. If I don't hear anything I'll hack up something and send it out for review, but I thought it would nice if we could sort out the proper fix first.
Quoted 8 lines
Quoted 6 lines
Raising this thread back up again to see if the NFS folks have a preference on option #1 or #2 above, or
something else altogether. Should returning of the security.selinux xattr name fromlistxattr()be dependent onNFS_CAP_SECURITY_LABELbeing set by the server and should it be dependent onCONFIG_NFS_V4_SECURITY_LABEL?Thanks for bringing this back up Stephen, it would be good to get this resolved.
On second look, I realized that commit 243fea134633 ("NFSv4.2: fix listxattr to return selinux security label") was likely motivated by the same issue as commit 8b0ba61df5a1c44e2b3cf6 ("fs/xattr.c: fix simple_xattr_list to always include security.* xattrs"), i.e. the coreutils change that switched ls -Z from unconditionally calling getxattr("security.selinux") (via libselinux getfilecon(3)) to only doing so if listxattr() returns the "security.selinux" xattr name. Hence, we want the call to security_inode_listsecurity() to be unconditional, which favors option #2. My only residual question though is that commit 243fea134633 put the call _after_ fetching the user.* xattr names, whereas the nfs4_listxattr_nfs4_label() returns it _before_ any user.* xattrs are appended. I'd be inclined to move up the security_inode_listsecurity() call to replace the nfs4_listxattr_nfs4_label() call along with option #2.
Stephen Smalley
maintainerQuoted 93 lines · Stephen Smalley
Quoted 82 lines · Paul Moore
Quoted 79 lines · Stephen Smalley
Quoted 77 lines · Paul Moore
Quoted 65 lines · Paul Moore
Quoted 29 lines · Anna Schumaker
Quoted 28 lines · Paul Moore
Quoted 26 lines · Paul Moore
Quoted 12 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>---
This patch is relative to the one linked above, which in theory is on vfs.fixes but doesn't appear to have been pushed when I looked.Quoted 9 lines
fs/nfs/nfs4proc.c | 10 ++++++---- fs/xattr.c | 19 +++++++------------ include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 5 +++-- net/socket.c | 17 +++++++---------- security/security.c | 16 ++++++++-------- security/selinux/hooks.c | 10 +++------- security/smack/smack_lsm.c | 13 ++++--------- 8 files changed, 40 insertions(+), 54 deletions(-)Thanks Stephen. Once we get ACKs from the NFS, netdev, and Smack folks I can pull this into the LSM tree.
Quoted 6 lines
Quoted 3 lines
Gentle ping for Trond, Anna, Jakub, and Casey ... can I get some ACKs on this patch? It's a little late for the upcoming merge window, but I'd like to merge this via the LSM tree after the merge window closes.
For the NFS change:
Acked-by Anna Schumaker <[email protected]>Hi Anna,
Thanks for reviewing the patch. Unfortunately when merging the patch today and fixing up some merge conflicts I bumped into an odd case in the NFS space and I wanted to check with you on how you would like to resolve it.
Commit
243fea134633("NFSv4.2: fix listxattr to return selinux security label")[1] adds a direct call tosecurity_inode_listsecurity()innfs4_listxattr(), despite the existingnfs4_listxattr_nfs4_label()call which calls into the same LSM hook, although that call is conditional on the server supportingNFS_CAP_SECURITY_LABEL. Based on a quick search, it appears the only caller fornfs4_listxattr_nfs4_label()isnfs4_listxattr()so I'm wondering if there isn't some room for improvement here.I think there are two obvious options, and I'm curious about your thoughts on which of these you would prefer, or if there is another third option that you would like to see merged.
Option #1:
Essentially back out commit243fea134633, removing the direct LSM call innfs4_listxattr()and relying on thenfs4_listxattr_nfs4_label()for the LSM/SELinux xattrs. I think we would want to remove theNFS_CAP_SECURITY_LABELcheck and buildnfs4_listxattr_nfs4_label()regardless ofCONFIG_NFS_V4_SECURITY_LABEL.Quoted 7 lines
Option #2:
Removenfs4_listxattr_nfs4_label()entirely and keep the direct LSM call innfs4_listxattr(), with the required changes for this patch.Thoughts?
A gentle ping on the question above for the NFS folks. If I don't hear anything I'll hack up something and send it out for review, but I thought it would nice if we could sort out the proper fix first.
Quoted 8 lines
Quoted 6 lines
Raising this thread back up again to see if the NFS folks have a preference on option #1 or #2 above, or
something else altogether. Should returning of the security.selinux xattr name fromlistxattr()be dependent onNFS_CAP_SECURITY_LABELbeing set by the server and should it be dependent onCONFIG_NFS_V4_SECURITY_LABEL?Thanks for bringing this back up Stephen, it would be good to get this resolved.
Quoted 14 lines
On second look, I realized that commit
243fea134633("NFSv4.2: fix listxattr to return selinux security label") was likely motivated by the same issue as commit8b0ba61df5a1c44e2b3cf6("fs/xattr.c: fixsimple_xattr_listto always include security.* xattrs"), i.e. the coreutils change that switched ls -Z from unconditionally callinggetxattr("security.selinux")(via libselinux getfilecon(3)) to only doing so iflistxattr()returns the "security.selinux" xattr name. Hence, we want the call tosecurity_inode_listsecurity()to be unconditional, which favors option #2. My only residual question though is that commit243fea134633put the call _after_ fetching the user.* xattr names, whereas thenfs4_listxattr_nfs4_label()returns it _before_ any user.* xattrs are appended. I'd be inclined to move up thesecurity_inode_listsecurity()call to replace thenfs4_listxattr_nfs4_label()call along with option #2.
I've made an attempt to unify the two security_inode_listsecurity() hook calls in the nfs4 code into a single, unconditional call from nfs4_listxattr(), which can be found here:
https://lore.kernel.org/selinux/[email protected]/T/#u
If this is deemed acceptable by the NFS folks, then I can re-base this patch on top of that one.
Stephen Smalley
maintainerQuoted 25 lines · Paul Moore
Quoted 12 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>---
This patch is relative to the one linked above, which in theory is on vfs.fixes but doesn't appear to have been pushed when I looked.Quoted 9 lines
fs/nfs/nfs4proc.c | 10 ++++++---- fs/xattr.c | 19 +++++++------------ include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 5 +++-- net/socket.c | 17 +++++++---------- security/security.c | 16 ++++++++-------- security/selinux/hooks.c | 10 +++------- security/smack/smack_lsm.c | 13 ++++--------- 8 files changed, 40 insertions(+), 54 deletions(-)
Quoted 2 lines
Thanks Stephen. Once we get ACKs from the NFS, netdev, and Smack folks I can pull this into the LSM tree.
Note that this will need to have a conflict resolved with:
https://lore.kernel.org/selinux/[email protected]/
Fortunately it should be straightforward - just delete the line added by that patch since this patch fixes the security_inode_listsecurity() hook interface to return 0 or -errno itself.
Quoted 3 lines
--
paul-moore.com
Paul Moore
maintainerQuoted 29 lines · Stephen Smalley
Quoted 25 lines · Paul Moore
Quoted 12 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>---
This patch is relative to the one linked above, which in theory is on vfs.fixes but doesn't appear to have been pushed when I looked.Quoted 9 lines
fs/nfs/nfs4proc.c | 10 ++++++---- fs/xattr.c | 19 +++++++------------ include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 5 +++-- net/socket.c | 17 +++++++---------- security/security.c | 16 ++++++++-------- security/selinux/hooks.c | 10 +++------- security/smack/smack_lsm.c | 13 ++++--------- 8 files changed, 40 insertions(+), 54 deletions(-)Quoted 2 lines
Thanks Stephen. Once we get ACKs from the NFS, netdev, and Smack folks I can pull this into the LSM tree.
Quoted 6 lines
Note that this will need to have a conflict resolved with:
https://lore.kernel.org/selinux/[email protected]/Fortunately it should be straightforward - just delete the line added by that patch since this patch fixes the
security_inode_listsecurity()hook interface to return 0 or -errno itself.
Yep, I'm pretty much just waiting on -rc1 right now.
Signature · 1 line
paul-moore.com
From: Stephen Smalley <[email protected]>
Date: Mon, 28 Apr 2025 15:50:19 -0400
Quoted 7 lines
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>
[...]
net/socket.c static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer, · line 564
Quoted 11 lines
net/socket.c +2
-1@@ -560,17 +560,14 @@ static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer, size_t size) {ssize_t len; -ssize_t used =0 ; +ssize_t used, remaining; +int err;
Paul: Could you sort this in the reverse xmas tree order before merging ?
https://docs.kernel.org/process/maintainer-netdev.html#local-variable-ordering-reverse-xmas-tree-rcs
otherwise the socket part looks good to me:
Quoted 18 lines
net/socket.c +5
-9- len =security_inode_listsecurity (d_inode (dentry), buffer, size); -if (len <0 ) -return len; - used += len; -if (buffer) { -if (size < used) -return -ERANGE ; - buffer += len; - } + err =security_inode_listsecurity (d_inode (dentry), &buffer, + &remaining); +if (err) +return err; + used = size - remaining; len = (XATTR_NAME_SOCKPROTONAME_LEN +1 ); used += len;
Paul Moore
maintainerQuoted 10 lines · Kuniyuki Iwashima
From: Stephen Smalley <[email protected]>
Date: Mon, 28 Apr 2025 15:50:19 -0400Quoted 7 lines
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>[...]
Quoted 14 lines
net/socket.c static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer, · line 564
Quoted 11 lines
net/socket.c +2
-1@@ -560,17 +560,14 @@ static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer, size_t size) {ssize_t len; -ssize_t used =0 ; +ssize_t used, remaining; +int err;Paul: Could you sort this in the reverse xmas tree order before merging ?
https://docs.kernel.org/process/maintainer-netdev.html#local-variable-ordering-reverse-xmas-tree-rcs
Done, thanks for reviewing the patch.
Quoted 3 lines
otherwise the socket part looks good to me:
Reviewed-by Kuniyuki Iwashima <[email protected]>
Signature · 1 line
paul-moore.com
Stephen Smalley, 28/04/2025:
Quoted 5 lines
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.
Sorry for being late to the party.
Your approach assumes that every fs-specific xattr lister called like
| vfs_listxattr() {
| if (inode->i_op->listxattr)
| error = inode->i_op->listxattr(dentry, list, size)
| ...must call LSM to integrate LSM's xattr(s) into fs-specific list. You did this for tmpfs:
| simple_xattr_list() {
| security_inode_listsecurity()
| // iterate real xatts listWell, but what about other filesystems in the linux kernel? Should all of them also modify their xattr listers?
To me, taking care of security xattrs is improper responsibility for filesystem code.
May it be better to merge LSM xattrs
and fs-backed xattrs at the vfs level (vfs_listxattr)?
--
Konstantin Andreev
Stephen Smalley
maintainerQuoted 26 lines · Konstantin Andreev
Stephen Smalley, 28/04/2025:
Quoted 5 lines
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Sorry for being late to the party.
Your approach assumes that every fs-specific xattr lister called like
| vfs_listxattr() { | if (inode->i_op->listxattr) | error = inode->i_op->listxattr(dentry, list, size) | ...must call LSM to integrate LSM's xattr(s) into fs-specific list. You did this for tmpfs:
| simple_xattr_list() { | security_inode_listsecurity() | // iterate real xatts list
Quoted 8 lines
Well, but what about other filesystems in the linux kernel? Should all of them also modify their xattr listers?
To me, taking care of security xattrs is improper responsibility for filesystem code.
May it be better to merge LSM xattrs
and fs-backed xattrs at the vfs level (vfs_listxattr)?
This patch and the preceding one on which it depends were specifically to address a regression in the handling of listxattr() for tmpfs/shmem and similar filesystems.
Originally they had no xattr handler at the filesystem level and vfs_listxattr() already has a fallback to ensure inclusion of the security.* xattr for that case.
For filesystems like ext4 that have always (relative to first introduction of security.* xattrs) provided handlers, they already return the fs-backed xattr value and we don't need to ask the LSM for it.
That said, you may be correct that it would be better to introduce some additional handling in vfs_listxattr() but I would recommend doing that as a follow-up.
Stephen Smalley, 06/06/2025 10:28 -0400:
Quoted 35 lines · Konstantin Andreev
Quoted 25 lines
Stephen Smalley, 28/04/2025:
Quoted 5 lines
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Sorry for being late to the party.
Your approach assumes that every fs-specific xattr lister called like
| vfs_listxattr() { | if (inode->i_op->listxattr) | error = inode->i_op->listxattr(dentry, list, size) | ...must call LSM to integrate LSM's xattr(s) into fs-specific list. You did this for tmpfs:
| simple_xattr_list() { | security_inode_listsecurity() | // iterate real xatts listQuoted 8 lines
Well, but what about other filesystems in the linux kernel? Should all of them also modify their xattr listers?
To me, taking care of security xattrs is improper responsibility for filesystem code.
May it be better to merge LSM xattrs
and fs-backed xattrs at the vfs level (vfs_listxattr)?
Quoted 6 lines
This patch and the preceding one on which it depends were specifically to address a regression in the handling of
listxattr()for tmpfs/shmem and similar filesystems.
Originally they had no xattr handler at the filesystem level andvfs_listxattr()already has a fallback to ensure inclusion of the security.* xattr for that case.
Understood
Quoted 4 lines
For filesystems like ext4 that have always (relative to first introduction of security.* xattrs) provided handlers, they already return the fs-backed xattr value and we don't need to ask the LSM for it.
They only return those security.* xattrs that were physically stored in the fs permanent storage.
If LSM's xattrs are not stored they are not listed :(
Quoted 3 lines
That said, you may be correct that it would be better to introduce some additional handling in
vfs_listxattr()but I would recommend doing that as a follow-up.
Understood
--
Konstantin Andreev
Paul Moore
maintainerPATCH v2 1/1 security,fs,nfs,net: update security_inode_listsecurity() interface
In reply to Stephen SmalleyFrom: Stephen Smalley <[email protected]>
Update the security_inode_listsecurity() interface to allow use of the xattr_list_one() helper and update the hook implementations.
--- fs/nfs/nfs4proc.c | 7 ++----- fs/xattr.c | 11 +++++++---- include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 5 +++-- security/security.c | 16 ++++++++-------- security/selinux/hooks.c | 10 +++------- security/smack/smack_lsm.c | 13 ++++--------- 7 files changed, 29 insertions(+), 37 deletions(-)
fs/nfs/nfs4proc.c +2 -5
@@ -10562,13 +10562,10 @@ static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size) left -= error; } - error2 =security_inode_listsecurity (d_inode (dentry), list, left); + error2 =security_inode_listsecurity (d_inode (dentry), &list, &left);if (error2 <0 )return error2; -if (list) { - list += error2; - left -= error2; - } + error2 = size - error - left; error3 =nfs4_listxattr_nfs4_user (d_inode (dentry), list, left);if (error3 <0 )
fs/xattr.c +7 -4
@@ -510,9 +510,12 @@ vfs_listxattr(struct dentry *dentry, char *list, size_t size)if (inode->i_op->listxattr) { error = inode->i_op->listxattr (dentry, list, size); }else { - error =security_inode_listsecurity (inode, list, size); -if (size && error > size) - error = -ERANGE ; +ssize_t remaining = size; + + error =security_inode_listsecurity (inode, &list, &remaining); +if (error) +return error; + error = size - remaining; }return error; }
@@ -1540,7 +1543,7 @@ ssize_t simple_xattr_list(struct inode *inode, struct simple_xattrs *xattrs,if (err)return err; - err =security_inode_listsecurity (inode, buffer, remaining_size); + err =security_inode_listsecurity (inode, &buffer, &remaining_size);if (err <0 )return err;
include/linux/lsm_hook_defs.h +2 -2
@@ -176,8 +176,8 @@ LSM_HOOK(int, -EOPNOTSUPP, inode_getsecurity, struct mnt_idmap *idmap, struct inode *inode, const char *name, void **buffer, bool alloc) LSM_HOOK(int, -EOPNOTSUPP, inode_setsecurity, struct inode *inode, const char *name, const void *value, size_t size, int flags) -LSM_HOOK(int, 0, inode_listsecurity, struct inode *inode, char *buffer, - size_t buffer_size) +LSM_HOOK(int, 0, inode_listsecurity, struct inode *inode, char **buffer, + ssize_t *remaining_size) LSM_HOOK(void, LSM_RET_VOID, inode_getlsmprop, struct inode *inode, struct lsm_prop *prop) LSM_HOOK(int, 0, inode_copy_up, struct dentry *src, struct cred **new)
include/linux/security.h +3 -2
@@ -459,7 +459,7 @@ int security_inode_getsecurity(struct mnt_idmap *idmap, struct inode *inode, const char *name, void **buffer, bool alloc);int security_inode_setsecurity (struct inode *inode,const char *name,const void *value,size_t size,int flags); -int security_inode_listsecurity (struct inode *inode,char *buffer,size_t buffer_size); +int security_inode_listsecurity (struct inode *inode,char **buffer,ssize_t *remaining_size);void security_inode_getlsmprop (struct inode *inode,struct lsm_prop *prop);int security_inode_copy_up (struct dentry *src,struct cred **new);int security_inode_copy_up_xattr (struct dentry *src,const char *name);
@@ -1097,7 +1097,8 @@ static inline int security_inode_setsecurity(struct inode *inode, const char *nareturn -EOPNOTSUPP ; } -static inline int security_inode_listsecurity (struct inode *inode,char *buffer,size_t buffer_size) +static inline int security_inode_listsecurity (struct inode *inode, +char **buffer,ssize_t *remaining_size) {return 0 ; }
security/security.c +8 -8
@@ -2258,22 +2258,22 @@ int security_inode_setsecurity(struct inode *inode, const char *name,/** * security_inode_listsecurity() - List the xattr security label names * @inode: inode -* @buffer: buffer -* @buffer_size: size of buffer +* @buffer: pointer to buffer +* @remaining_size: pointer to remaining size of buffer * * Copy the extended attribute names for the security labels associated with -* @inode into @buffer. The maximum size of @buffer is specified by -* @buffer_size. @buffer may be NULL to request the size of the buffer -* required. +* @inode into *(@buffer). The remaining size of @buffer is specified by +* *(@remaining_size). *(@buffer) may be NULL to request the size of the +* buffer required. Updates *(@buffer) and *(@remaining_size). * -* Return: Returns number of bytes used/required on success. +* Return: Returns 0 on success, or -errno on failure. */ int security_inode_listsecurity (struct inode *inode, -char *buffer,size_t buffer_size) +char **buffer,ssize_t *remaining_size) {if (unlikely (IS_PRIVATE (inode)))return 0 ; -return call_int_hook (inode_listsecurity, inode, buffer, buffer_size); +return call_int_hook (inode_listsecurity, inode, buffer, remaining_size); }EXPORT_SYMBOL (security_inode_listsecurity);
security/selinux/hooks.c +3 -7
@@ -3684,16 +3684,12 @@ static int selinux_inode_setsecurity(struct inode *inode, const char *name,return 0 ; } -static int selinux_inode_listsecurity (struct inode *inode,char *buffer,size_t buffer_size) +static int selinux_inode_listsecurity (struct inode *inode,char **buffer, +ssize_t *remaining_size) { -const int len =sizeof (XATTR_NAME_SELINUX ); -if (!selinux_initialized ())return 0 ; - -if (buffer && len <= buffer_size) -memcpy (buffer,XATTR_NAME_SELINUX , len); -return len; +return xattr_list_one (buffer, remaining_size,XATTR_NAME_SELINUX ); }static void selinux_inode_getlsmprop (struct inode *inode,struct lsm_prop *prop)
security/smack/smack_lsm.c +4 -9
@@ -1665,17 +1665,12 @@ static int smack_inode_getsecurity(struct mnt_idmap *idmap,* smack_inode_listsecurity - list the Smack attributes * @inode: the object * @buffer: where they go -* @buffer_size: size of buffer +* @remaining_size: size of buffer */ -static int smack_inode_listsecurity (struct inode *inode,char *buffer, -size_t buffer_size) +static int smack_inode_listsecurity (struct inode *inode,char **buffer, +ssize_t *remaining_size) { -int len =sizeof (XATTR_NAME_SMACK ); - -if (buffer !=NULL && len <= buffer_size) -memcpy (buffer,XATTR_NAME_SMACK , len); - -return len; +return xattr_list_one (buffer, remaining_size,XATTR_NAME_SMACK ); }/**
Signature · 1 line
2.54.0
Paul Moore
maintainerQuoted 11 lines · Paul Moore
From: Stephen Smalley <[email protected]>
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>[PM: forward porting to bring this patch up to v7.1-rc1+]Signed-off-by Paul Moore <[email protected]>
Quoted 9 lines
--- fs/nfs/nfs4proc.c | 7 ++----- fs/xattr.c | 11 +++++++---- include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 5 +++-- security/security.c | 16 ++++++++-------- security/selinux/hooks.c | 10 +++------- security/smack/smack_lsm.c | 13 ++++--------- 7 files changed, 29 insertions(+), 37 deletions(-)
With the security_inode_listsecurity() cleanup shipping in Linux v7.0, I wanted to get this patch ready for the next merge window. As expected, some borderline non-trivial porting was needed, so I'm posting the ported version in case anyone wants to review the patch again. If I don't hear anything over the next few days, I'll plan to merge this into lsm/dev later this week.
The SELinux test suite runs clean for both local and NFS test runs.
Signature · 1 line
paul-moore.com
Paul Moore
maintainerQuoted 22 lines · Paul Moore
Quoted 11 lines · Paul Moore
From: Stephen Smalley <[email protected]>
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.Signed-off-by Stephen Smalley <[email protected]>[PM: forward porting to bring this patch up to v7.1-rc1+]Signed-off-by Paul Moore <[email protected]>Quoted 9 lines
--- fs/nfs/nfs4proc.c | 7 ++----- fs/xattr.c | 11 +++++++---- include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 5 +++-- security/security.c | 16 ++++++++-------- security/selinux/hooks.c | 10 +++------- security/smack/smack_lsm.c | 13 ++++--------- 7 files changed, 29 insertions(+), 37 deletions(-)
Quoted 6 lines
With the
security_inode_listsecurity()cleanup shipping in Linux v7.0, I wanted to get this patch ready for the next merge window. As expected, some borderline non-trivial porting was needed, so I'm posting the ported version in case anyone wants to review the patch again. If I don't hear anything over the next few days, I'll plan to merge this into lsm/dev later this week.
This has now been merged into lsm/dev, thanks all.
Quoted 1 line
The SELinux test suite runs clean for both local and NFS test runs.
Signature · 1 line
paul-moore.com
Chuck Lever
maintainerQuoted 3 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.
This commit wedges an NFSv4.2 client running fstests.
A kdevops fstests run against nfsd-next hangs at generic/086. The client stops making progress and never recovers:
watchdog: BUG: soft lockup - CPU#3 stuck for 250s! [086:60396]
Comm: 086 Tainted: G D L 7.2.0-rc4
__pv_queued_spin_lock_slowpath
_raw_spin_lock
nfs4_xattr_set_listcache [nfsv4]
nfs4_xattr_discard_cache [nfsv4]
nfs4_xattr_cache_scan [nfsv4]
do_shrink_slab
drop_caches_sysctl_handlerThe D taint says something died earlier. It did: by the time the lockup fires, the client has already taken two dozen NULL pointer dereferences, all of them in the same place:
BUG: kernel NULL pointer dereference, address: 0000000000000000
RIP: _copy_from_pages+0x44/0xd0 [sunrpc]
nfs4_xattr_cache_list [nfsv4]
nfs4_listxattr [nfsv4]
vfs_listxattr
__x64_sys_listxattrThe two stages are connected. nfs4_listxattr() declares its remaining-size accumulator as an unsigned size_t. On a size query, where listxattr(2) passes a NULL buffer and a length of zero, xattr_list_one() decrements that accumulator for the SELinux label without regard to the NULL buffer, so it wraps to a very large value. nfs4_xattr_cache_list() then sees a NULL buffer paired with a buffer length large enough to pass its own bounds check, and copies into it. The fault happens while the xattr listcache spinlock is held. Task exit does not release spinlocks, so the lock is orphaned, and the next shrinker pass spins on it until the watchdog fires.
The reproducer is a plain getfattr on a file on an NFSv4.2 mount with SELinux enforcing, which is what fstests generic/086 arrives at by way of a drop_caches write. No fstests machinery is needed to see the oops.
An audit of the listxattr path pointed here, so I built nfsd-next with this commit reverted and reran the full fstests nfs_v42 section on the same pair of guests. 745 tests, no soft lockup, no oops, and generic/086 passes. The two failures that remain, generic/033 and generic/258, are unrelated to xattrs.
I am not proposing the revert as the fix. Achilles Gaikwad has already posted a targeted patch for the accounting itself:
https://lore.kernel.org/linux-nfs/[email protected]/
Whether the right answer is that patch, a change to xattr_list_one() so it leaves the remaining size alone when the buffer is NULL, or hardening nfs4_xattr_cache_list() against a NULL buffer, is for the three of you to settle. I am reporting the severity, because the accounting bug is not confined to a short size query: on a filesystem that caches xattrs behind a lock, it takes the whole machine down.
I can test whatever you settle on against the same setup.
--
Chuck Lever
Paul Moore
maintainerQuoted 68 lines · Chuck Lever
Quoted 3 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.This commit wedges an NFSv4.2 client running fstests.
A kdevops fstests run against nfsd-next hangs at generic/086. The client stops making progress and never recovers:
watchdog: BUG: soft lockup - CPU#3 stuck for 250s! [086:60396] Comm: 086 Tainted: G D L 7.2.0-rc4 __pv_queued_spin_lock_slowpath _raw_spin_lock nfs4_xattr_set_listcache [nfsv4] nfs4_xattr_discard_cache [nfsv4] nfs4_xattr_cache_scan [nfsv4] do_shrink_slab drop_caches_sysctl_handlerThe D taint says something died earlier. It did: by the time the lockup fires, the client has already taken two dozen NULL pointer dereferences, all of them in the same place:
BUG: kernel NULL pointer dereference, address: 0000000000000000 RIP: _copy_from_pages+0x44/0xd0 [sunrpc] nfs4_xattr_cache_list [nfsv4] nfs4_listxattr [nfsv4] vfs_listxattr __x64_sys_listxattrThe two stages are connected.
nfs4_listxattr()declares its remaining-size accumulator as an unsignedsize_t. On a size query, where listxattr(2) passes a NULL buffer and a length of zero,xattr_list_one()decrements that accumulator for the SELinux label without regard to the NULL buffer, so it wraps to a very large value.nfs4_xattr_cache_list()then sees a NULL buffer paired with a buffer length large enough to pass its own bounds check, and copies into it. The fault happens while the xattr listcache spinlock is held. Task exit does not release spinlocks, so the lock is orphaned, and the next shrinker pass spins on it until the watchdog fires.The reproducer is a plain getfattr on a file on an NFSv4.2 mount with SELinux enforcing, which is what fstests generic/086 arrives at by way of a
drop_cacheswrite. No fstests machinery is needed to see the oops.An audit of the listxattr path pointed here, so I built nfsd-next with this commit reverted and reran the full fstests
nfs_v42section on the same pair of guests. 745 tests, no soft lockup, no oops, and generic/086 passes. The two failures that remain, generic/033 and generic/258, are unrelated to xattrs.I am not proposing the revert as the fix. Achilles Gaikwad has already posted a targeted patch for the accounting itself:
https://lore.kernel.org/linux-nfs/[email protected]/
Whether the right answer is that patch, a change to
xattr_list_one()so it leaves the remaining size alone when the buffer is NULL, or hardeningnfs4_xattr_cache_list()against a NULL buffer, is for the three of you to settle. I am reporting the severity, because the accounting bug is not confined to a short size query: on a filesystem that caches xattrs behind a lock, it takes the whole machine down.
Quoted 1 line
I can test whatever you settle on against the same setup.
I reviewed Achilles's patch back in early July and it looked okay to me (see my tag in my email in that thread from July 7th). I had figured that the NFS folks would have wanted to pull that via the NFS tree since it only touches NFS code. If they would prefer I send it up to Linus via the LSM tree I can do that, but I would appreciate an ACK and Tested-by from someone on the NFS side.
While I don't suspect it will be very interesting, I just started building a test kernel with Achilles's patch that I'll run through the normal selinux-testsuite automated testing.
Signature · 1 line
paul-moore.com
Paul Moore
maintainerQuoted 4 lines · Paul Moore
While I don't suspect it will be very interesting, I just started building a test kernel with Achilles's patch that I'll run through the normal selinux-testsuite automated testing.
Not that I was expecting this to be a good test, but FWIW, the selinux-testsuite (and audit-testsuite for that matter) ran clean with Achilles's patch.
Signature · 1 line
paul-moore.com
Paul Moore
maintainerQuoted 78 lines · Paul Moore
Quoted 68 lines · Chuck Lever
Quoted 3 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.This commit wedges an NFSv4.2 client running fstests.
A kdevops fstests run against nfsd-next hangs at generic/086. The client stops making progress and never recovers:
watchdog: BUG: soft lockup - CPU#3 stuck for 250s! [086:60396] Comm: 086 Tainted: G D L 7.2.0-rc4 __pv_queued_spin_lock_slowpath _raw_spin_lock nfs4_xattr_set_listcache [nfsv4] nfs4_xattr_discard_cache [nfsv4] nfs4_xattr_cache_scan [nfsv4] do_shrink_slab drop_caches_sysctl_handlerThe D taint says something died earlier. It did: by the time the lockup fires, the client has already taken two dozen NULL pointer dereferences, all of them in the same place:
BUG: kernel NULL pointer dereference, address: 0000000000000000 RIP: _copy_from_pages+0x44/0xd0 [sunrpc] nfs4_xattr_cache_list [nfsv4] nfs4_listxattr [nfsv4] vfs_listxattr __x64_sys_listxattrThe two stages are connected.
nfs4_listxattr()declares its remaining-size accumulator as an unsignedsize_t. On a size query, where listxattr(2) passes a NULL buffer and a length of zero,xattr_list_one()decrements that accumulator for the SELinux label without regard to the NULL buffer, so it wraps to a very large value.nfs4_xattr_cache_list()then sees a NULL buffer paired with a buffer length large enough to pass its own bounds check, and copies into it. The fault happens while the xattr listcache spinlock is held. Task exit does not release spinlocks, so the lock is orphaned, and the next shrinker pass spins on it until the watchdog fires.The reproducer is a plain getfattr on a file on an NFSv4.2 mount with SELinux enforcing, which is what fstests generic/086 arrives at by way of a
drop_cacheswrite. No fstests machinery is needed to see the oops.An audit of the listxattr path pointed here, so I built nfsd-next with this commit reverted and reran the full fstests
nfs_v42section on the same pair of guests. 745 tests, no soft lockup, no oops, and generic/086 passes. The two failures that remain, generic/033 and generic/258, are unrelated to xattrs.I am not proposing the revert as the fix. Achilles Gaikwad has already posted a targeted patch for the accounting itself:
https://lore.kernel.org/linux-nfs/[email protected]/
Whether the right answer is that patch, a change to
xattr_list_one()so it leaves the remaining size alone when the buffer is NULL, or hardeningnfs4_xattr_cache_list()against a NULL buffer, is for the three of you to settle. I am reporting the severity, because the accounting bug is not confined to a short size query: on a filesystem that caches xattrs behind a lock, it takes the whole machine down.Quoted 1 line
I can test whatever you settle on against the same setup.
I reviewed Achilles's patch back in early July and it looked okay to me (see my tag in my email in that thread from July 7th). I had figured that the NFS folks would have wanted to pull that via the NFS tree since it only touches NFS code. If they would prefer I send it up to Linus via the LSM tree I can do that, but I would appreciate an ACK and Tested-by from someone on the NFS side.
Quoted 3 lines
While I don't suspect it will be very interesting, I just started building a test kernel with Achilles's patch that I'll run through the normal selinux-testsuite automated testing.
Chuck, Anna, Trond, Jeff - can someone ACK Achilles's patch below or suggest what changes might be necessary? There is a known regression (see the existing mails) and we need to fix this before v7.2 ships. I'm happy to send this up to Linus if you would prefer, but I would *really* like to see an ACK from someone on the NFS side. If I don't see any comments be early next week I'll send this up to Linus via the LSM tree.
https://lore.kernel.org/linux-nfs/[email protected]/
Signature · 1 line
paul-moore.com
Chuck Lever
maintainerQuoted 91 lines · Paul Moore
Quoted 78 lines · Paul Moore
Quoted 68 lines · Chuck Lever
Quoted 3 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.This commit wedges an NFSv4.2 client running fstests.
A kdevops fstests run against nfsd-next hangs at generic/086. The client stops making progress and never recovers:
watchdog: BUG: soft lockup - CPU#3 stuck for 250s! [086:60396] Comm: 086 Tainted: G D L 7.2.0-rc4 __pv_queued_spin_lock_slowpath _raw_spin_lock nfs4_xattr_set_listcache [nfsv4] nfs4_xattr_discard_cache [nfsv4] nfs4_xattr_cache_scan [nfsv4] do_shrink_slab drop_caches_sysctl_handlerThe D taint says something died earlier. It did: by the time the lockup fires, the client has already taken two dozen NULL pointer dereferences, all of them in the same place:
BUG: kernel NULL pointer dereference, address: 0000000000000000 RIP: _copy_from_pages+0x44/0xd0 [sunrpc] nfs4_xattr_cache_list [nfsv4] nfs4_listxattr [nfsv4] vfs_listxattr __x64_sys_listxattrThe two stages are connected.
nfs4_listxattr()declares its remaining-size accumulator as an unsignedsize_t. On a size query, where listxattr(2) passes a NULL buffer and a length of zero,xattr_list_one()decrements that accumulator for the SELinux label without regard to the NULL buffer, so it wraps to a very large value.nfs4_xattr_cache_list()then sees a NULL buffer paired with a buffer length large enough to pass its own bounds check, and copies into it. The fault happens while the xattr listcache spinlock is held. Task exit does not release spinlocks, so the lock is orphaned, and the next shrinker pass spins on it until the watchdog fires.The reproducer is a plain getfattr on a file on an NFSv4.2 mount with SELinux enforcing, which is what fstests generic/086 arrives at by way of a
drop_cacheswrite. No fstests machinery is needed to see the oops.An audit of the listxattr path pointed here, so I built nfsd-next with this commit reverted and reran the full fstests
nfs_v42section on the same pair of guests. 745 tests, no soft lockup, no oops, and generic/086 passes. The two failures that remain, generic/033 and generic/258, are unrelated to xattrs.I am not proposing the revert as the fix. Achilles Gaikwad has already posted a targeted patch for the accounting itself:
https://lore.kernel.org/linux-nfs/[email protected]/
Whether the right answer is that patch, a change to
xattr_list_one()so it leaves the remaining size alone when the buffer is NULL, or hardeningnfs4_xattr_cache_list()against a NULL buffer, is for the three of you to settle. I am reporting the severity, because the accounting bug is not confined to a short size query: on a filesystem that caches xattrs behind a lock, it takes the whole machine down.Quoted 1 line
I can test whatever you settle on against the same setup.
I reviewed Achilles's patch back in early July and it looked okay to me (see my tag in my email in that thread from July 7th). I had figured that the NFS folks would have wanted to pull that via the NFS tree since it only touches NFS code. If they would prefer I send it up to Linus via the LSM tree I can do that, but I would appreciate an ACK and Tested-by from someone on the NFS side.
Quoted 3 lines
While I don't suspect it will be very interesting, I just started building a test kernel with Achilles's patch that I'll run through the normal selinux-testsuite automated testing.
Chuck, Anna, Trond, Jeff - can someone ACK Achilles's patch below or suggest what changes might be necessary? There is a known regression (see the existing mails) and we need to fix this before v7.2 ships. I'm happy to send this up to Linus if you would prefer, but I would *really* like to see an ACK from someone on the NFS side. If I don't see any comments be early next week I'll send this up to Linus via the LSM tree.
Quoted 1 line
Since Achilles' patch is client-side, I shouldn't Ack it.
I don't see this patch in Anna's tree either. A response from the NFS maintainers would be helpful.
Signature · 1 line
Chuck Lever
Anna Schumaker
maintainerQuoted 92 lines · Chuck Lever
Quoted 91 lines · Paul Moore
Quoted 78 lines · Paul Moore
Quoted 68 lines · Chuck Lever
Quoted 3 lines · Stephen Smalley
Update the
security_inode_listsecurity()interface to allow use of thexattr_list_one()helper and update the hook implementations.This commit wedges an NFSv4.2 client running fstests.
A kdevops fstests run against nfsd-next hangs at generic/086. The client stops making progress and never recovers:
watchdog: BUG: soft lockup - CPU#3 stuck for 250s! [086:60396] Comm: 086 Tainted: G D L 7.2.0-rc4 __pv_queued_spin_lock_slowpath _raw_spin_lock nfs4_xattr_set_listcache [nfsv4] nfs4_xattr_discard_cache [nfsv4] nfs4_xattr_cache_scan [nfsv4] do_shrink_slab drop_caches_sysctl_handlerThe D taint says something died earlier. It did: by the time the lockup fires, the client has already taken two dozen NULL pointer dereferences, all of them in the same place:
BUG: kernel NULL pointer dereference, address: 0000000000000000 RIP: _copy_from_pages+0x44/0xd0 [sunrpc] nfs4_xattr_cache_list [nfsv4] nfs4_listxattr [nfsv4] vfs_listxattr __x64_sys_listxattrThe two stages are connected.
nfs4_listxattr()declares its remaining-size accumulator as an unsignedsize_t. On a size query, where listxattr(2) passes a NULL buffer and a length of zero,xattr_list_one()decrements that accumulator for the SELinux label without regard to the NULL buffer, so it wraps to a very large value.nfs4_xattr_cache_list()then sees a NULL buffer paired with a buffer length large enough to pass its own bounds check, and copies into it. The fault happens while the xattr listcache spinlock is held. Task exit does not release spinlocks, so the lock is orphaned, and the next shrinker pass spins on it until the watchdog fires.The reproducer is a plain getfattr on a file on an NFSv4.2 mount with SELinux enforcing, which is what fstests generic/086 arrives at by way of a
drop_cacheswrite. No fstests machinery is needed to see the oops.An audit of the listxattr path pointed here, so I built nfsd-next with this commit reverted and reran the full fstests
nfs_v42section on the same pair of guests. 745 tests, no soft lockup, no oops, and generic/086 passes. The two failures that remain, generic/033 and generic/258, are unrelated to xattrs.I am not proposing the revert as the fix. Achilles Gaikwad has already posted a targeted patch for the accounting itself:
https://lore.kernel.org/linux-nfs/[email protected]/
Whether the right answer is that patch, a change to
xattr_list_one()so it leaves the remaining size alone when the buffer is NULL, or hardeningnfs4_xattr_cache_list()against a NULL buffer, is for the three of you to settle. I am reporting the severity, because the accounting bug is not confined to a short size query: on a filesystem that caches xattrs behind a lock, it takes the whole machine down.Quoted 1 line
I can test whatever you settle on against the same setup.
I reviewed Achilles's patch back in early July and it looked okay to me (see my tag in my email in that thread from July 7th). I had figured that the NFS folks would have wanted to pull that via the NFS tree since it only touches NFS code. If they would prefer I send it up to Linus via the LSM tree I can do that, but I would appreciate an ACK and Tested-by from someone on the NFS side.
Quoted 3 lines
While I don't suspect it will be very interesting, I just started building a test kernel with Achilles's patch that I'll run through the normal selinux-testsuite automated testing.
Chuck, Anna, Trond, Jeff - can someone ACK Achilles's patch below or suggest what changes might be necessary? There is a known regression (see the existing mails) and we need to fix this before v7.2 ships. I'm happy to send this up to Linus if you would prefer, but I would *really* like to see an ACK from someone on the NFS side. If I don't see any comments be early next week I'll send this up to Linus via the LSM tree.
Quoted 6 lines
Quoted 1 line
Since Achilles' patch is client-side, I shouldn't Ack it.
I don't see this patch in Anna's tree either. A response from the NFS maintainers would be helpful.
Looks like I did have it in a branch with other commits for testing, but I never pushed it out. I've moved it over to my public linux-next and will pass it along to Linus in the next few days.
Anna
Quoted 4 lines
Signature · 2 lines
-- Chuck Lever
Paul Moore
maintainerQuoted 4 lines · Anna Schumaker
Looks like I did have it in a branch with other commits for testing, but I never pushed it out. I've moved it over to my public linux-next and will pass it along to Linus in the next few days.
Perfect, thanks Anna!
Signature · 1 line
paul-moore.com