Skip to contentSkip to conversation

NFSv4.2: fix nfs4_listxattr NULL pointer dereference

PATCH In review Achilles Gaikwad 5 participants 16 messages Jul 3 – Jul 15

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFSv4.2: fix nfs4_listxattr NULL pointer dereference

A call to listxattr() with a buffer size = 0 returns the actual size of the buffer needed for a subsequent call. On an NFSv4.2 mount this triggers the following oops:

  [  399.768687] BUG: kernel NULL pointer dereference, address: 0000000000000000
  [  399.768705] RIP: 0010:_copy_from_pages+0x44/0xe0
  [  399.768722] Call Trace:
  [  399.768723]  nfs4_xattr_alloc_entry+0x1bf/0x1e0
  [  399.768730]  nfs4_xattr_cache_set_list+0x43/0x1f0
  [  399.768731]  nfs4_listxattr+0x21f/0x250
  [  399.768733]  vfs_listxattr+0x55/0xa0
  [  399.768736]  listxattr+0x23/0x160
  [  399.768737]  path_listxattrat+0xba/0x1e0
  [  399.768739]  do_syscall_64+0xe2/0x680

security_inode_listsecurity() now decrements the remaining size even when the buffer is NULL, so in the size-query case 'left' underflows to a huge size_t value and nfs4_listxattr_nfs4_user() treats the NULL buffer as real, ending in a NULL dereference in _copy_from_pages().

Declare 'left' as ssize_t and pass a zero length to nfs4_listxattr_nfs4_user() when the buffer is NULL.

Fixes f71ece9712b7 ("security,fs,nfs,net: update security_inode_listsecurity() interface")
---
 fs/nfs/nfs4proc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/nfs/nfs4proc.c +3 -2
index 1360409d8de9..4859c2c96c78 100644
@@ -10585,7 +10585,7 @@ const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
 static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
 {
 	ssize_t error, error2, error3;
-	size_t left = size;
+	ssize_t left = size;
 
 	error = generic_listxattr(dentry, list, left);
 	if (error < 0)
@@ -10600,7 +10600,8 @@ static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
 		return error2;
 	error2 = size - error - left;
 
-	error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, left);
+	error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list,
+					  list ? left : 0);
 	if (error3 < 0)
 		return error3;
 

base-commit: 6eb8711ece2ce27e52e327a5b7a628ed39b97f45

Signature · 1 line
2.55.0
maintainer
#1 lore raw
Quoted 22 lines · Achilles Gaikwad

A call to listxattr() with a buffer size = 0 returns the actual size of the buffer needed for a subsequent call. On an NFSv4.2 mount this triggers the following oops:

  [  399.768687] BUG: kernel NULL pointer dereference, address: 0000000000000000
  [  399.768705] RIP: 0010:_copy_from_pages+0x44/0xe0
  [  399.768722] Call Trace:
  [  399.768723]  nfs4_xattr_alloc_entry+0x1bf/0x1e0
  [  399.768730]  nfs4_xattr_cache_set_list+0x43/0x1f0
  [  399.768731]  nfs4_listxattr+0x21f/0x250
  [  399.768733]  vfs_listxattr+0x55/0xa0
  [  399.768736]  listxattr+0x23/0x160
  [  399.768737]  path_listxattrat+0xba/0x1e0
  [  399.768739]  do_syscall_64+0xe2/0x680

security_inode_listsecurity() now decrements the remaining size even when the buffer is NULL, so in the size-query case 'left' underflows to a huge size_t value and nfs4_listxattr_nfs4_user() treats the NULL buffer as real, ending in a NULL dereference in _copy_from_pages().

Quoted 8 lines

Declare 'left' as ssize_t and pass a zero length to nfs4_listxattr_nfs4_user() when the buffer is NULL.

Fixes f71ece9712b7 ("security,fs,nfs,net: update security_inode_listsecurity() interface")
---
 fs/nfs/nfs4proc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Thanks for reporting this, one thought below ...

Quoted 14 lines
fs/nfs/nfs4proc.c +1 -1
index 1360409d8de9..4859c2c96c78 100644
@@ -10585,7 +10585,7 @@ const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
 static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
 {
        ssize_t error, error2, error3;
-       size_t left = size;
+       ssize_t left = size;
 
        error = generic_listxattr(dentry, list, left);
        if (error < 0)

fs/nfs/nfs4proc.c static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size) · line 10601

Quoted 2 lines
fs/nfs/nfs4proc.c +0 -0
@@ -10600,7 +10600,8 @@ static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
                return error2;
        error2 = size - error - left;

I wonder if it would be better associate the handling code with the security_inode_listsecurity() call a bit more closely? Thinking about it quickly, would something like what's below work?

  left2 = left;
  error2 = security_inode_listsecurity(..., &list, &left2);
  if (error2 < 0)
    return error2;
  error2 = left - left2;
  if (list)
    left -= error2;
Quoted 10 lines
fs/nfs/nfs4proc.c +2 -1
-       error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, left);
+       error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list,
+                                         list ? left : 0);
        if (error3 < 0)
                return error3;
 
 

base-commit: 6eb8711ece2ce27e52e327a5b7a628ed39b97f45 --
2.55.0

Signature · 1 line
paul-moore.com
#2 lore raw
Quoted 6 lines · Paul Moore

[...]

I wonder if it would be better associate the handling code with the security_inode_listsecurity() call a bit more closely? Thinking about it quickly, would something like what's below work?

Quoted 7 lines
  left2 = left;
  error2 = security_inode_listsecurity(..., &list, &left2);
  if (error2 < 0)
    return error2;
  error2 = left - left2;
  if (list)
    left -= error2;

Yes, that works and is better than what I was proposing. strace on my nfs mount:

    listxattr("/mnt/abc.txt", NULL, 0) = 26 <-- v1 patch, actual is 42
    listxattr("/mnt/abc.txt", NULL, 0) = 42 <-- with your changes

Tested your suggestion on v4.2 w/ an NFSv4 ACL, an SELinux label and a user xattr present; both the size query and the exact-size read now return 42.

Will send a v2 soon, thanks!

-Achilles

#3 lore raw

PATCH v2 1/1 NFSv4.2: fix nfs4_listxattr size accounting

In reply to Achilles Gaikwad

A call to listxattr() with a buffer size of 0 returns the actual size of the buffer needed for a subsequent call. On an NFSv4.2 mount this triggers the following oops:

  [  399.768687] BUG: kernel NULL pointer dereference, address: 0000000000000000
  [  399.768705] RIP: 0010:_copy_from_pages+0x44/0xe0
  [  399.768722] Call Trace:
  [  399.768723]  nfs4_xattr_alloc_entry+0x1bf/0x1e0
  [  399.768730]  nfs4_xattr_cache_set_list+0x43/0x1f0
  [  399.768731]  nfs4_listxattr+0x21f/0x250
  [  399.768733]  vfs_listxattr+0x55/0xa0
  [  399.768736]  listxattr+0x23/0x160
  [  399.768737]  path_listxattrat+0xba/0x1e0
  [  399.768739]  do_syscall_64+0xe2/0x680

security_inode_listsecurity() (via the xattr_list_one() helper) now decrements the remaining size even when the buffer pointer is NULL, so in the size-query case, 'left' underflows to a huge size_t value. As a result, nfs4_listxattr_nfs4_user() treats the NULL buffer as a real one, leading to a NULL pointer dereference in _copy_from_pages().

security_inode_listsecurity() does not return the number of bytes it added to the list, so the code derived it as
'size - error - left'. That is also wrong in the size-query case:
the generic_listxattr() contribution is only subtracted from 'left' when a buffer is present. Thus, the query result comes up short by exactly that contribution (e.g., "system.nfs4_acl" on a mount with ACL support), and a caller that allocates the returned size gets -ERANGE on the subsequent call.

Declare 'left' as ssize_t, use a scratch copy to measure security hook consumption, and only decrement 'left' if a buffer is present.

Fixes f71ece9712b7 ("security,fs,nfs,net: update security_inode_listsecurity() interface")

---
Changes in v2:
- Use a scratch variable to track security label size directly, replacing the old formula that undercounted the size-query case.
- Drop the now-unneeded NULL-buffer special case for nfs4_listxattr_nfs4_user().
- Retitled from "fix nfs4_listxattr NULL pointer dereference"
(the same accounting bug caused both the oops and the undercount).
v1: https://lore.kernel.org/linux-nfs/[email protected]/

 fs/nfs/nfs4proc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
fs/nfs/nfs4proc.c +7 -3
index 1360409d8de9..a3415082d610 100644
@@ -10585,7 +10585,8 @@ const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
 static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
 {
 	ssize_t error, error2, error3;
-	size_t left = size;
+	ssize_t left = size;
+	ssize_t left2;
 
 	error = generic_listxattr(dentry, list, left);
 	if (error < 0)
@@ -10595,10 +10596,13 @@ static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
 		left -= error;
 	}
 
-	error2 = security_inode_listsecurity(d_inode(dentry), &list, &left);
+	left2 = left;
+	error2 = security_inode_listsecurity(d_inode(dentry), &list, &left2);
 	if (error2 < 0)
 		return error2;
-	error2 = size - error - left;
+	error2 = left - left2;
+	if (list)
+		left -= error2;
 
 	error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, left);
 	if (error3 < 0)

base-commit: 6eb8711ece2ce27e52e327a5b7a628ed39b97f45

Signature · 1 line
2.55.0
maintainer Reviewed-by on v2 1/1
#4 lore raw

Re: [PATCH v2] NFSv4.2: fix nfs4_listxattr size accounting

Quoted 46 lines · Achilles Gaikwad

A call to listxattr() with a buffer size of 0 returns the actual size of the buffer needed for a subsequent call. On an NFSv4.2 mount this triggers the following oops:

  [  399.768687] BUG: kernel NULL pointer dereference, address: 0000000000000000
  [  399.768705] RIP: 0010:_copy_from_pages+0x44/0xe0
  [  399.768722] Call Trace:
  [  399.768723]  nfs4_xattr_alloc_entry+0x1bf/0x1e0
  [  399.768730]  nfs4_xattr_cache_set_list+0x43/0x1f0
  [  399.768731]  nfs4_listxattr+0x21f/0x250
  [  399.768733]  vfs_listxattr+0x55/0xa0
  [  399.768736]  listxattr+0x23/0x160
  [  399.768737]  path_listxattrat+0xba/0x1e0
  [  399.768739]  do_syscall_64+0xe2/0x680

security_inode_listsecurity() (via the xattr_list_one() helper) now decrements the remaining size even when the buffer pointer is NULL, so in the size-query case, 'left' underflows to a huge size_t value. As a result, nfs4_listxattr_nfs4_user() treats the NULL buffer as a real one, leading to a NULL pointer dereference in _copy_from_pages().

security_inode_listsecurity() does not return the number of bytes it added to the list, so the code derived it as
'size - error - left'. That is also wrong in the size-query case:
the generic_listxattr() contribution is only subtracted from 'left' when a buffer is present. Thus, the query result comes up short by exactly that contribution (e.g., "system.nfs4_acl" on a mount with ACL support), and a caller that allocates the returned size gets -ERANGE on the subsequent call.

Declare 'left' as ssize_t, use a scratch copy to measure security hook consumption, and only decrement 'left' if a buffer is present.

Fixes f71ece9712b7 ("security,fs,nfs,net: update security_inode_listsecurity() interface")

---
Changes in v2:
- Use a scratch variable to track security label size directly, replacing the old formula that undercounted the size-query case.
- Drop the now-unneeded NULL-buffer special case for nfs4_listxattr_nfs4_user().
- Retitled from "fix nfs4_listxattr NULL pointer dereference"
(the same accounting bug caused both the oops and the undercount).
v1: https://lore.kernel.org/linux-nfs/[email protected]/

Quoted 2 lines
 fs/nfs/nfs4proc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

[CC'd the LSM and SELinux lists for visibility]

Unfortunately my testing was unsuccessful due to an NFS problem that started with the v7.2 merge window that I haven't had the time to bisect yet. Assuming the NFS folks are okay with this change, I figure they will want to send it up to Linus via their tree, if not let me know and I can send this up via the LSM tree.

Quoted 34 lines
fs/nfs/nfs4proc.c +7 -3
index 1360409d8de9..a3415082d610 100644
@@ -10585,7 +10585,8 @@ const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
 static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
 {
        ssize_t error, error2, error3;
-       size_t left = size;
+       ssize_t left = size;
+       ssize_t left2;
 
        error = generic_listxattr(dentry, list, left);
        if (error < 0)
@@ -10595,10 +10596,13 @@ static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
                left -= error;
        }
 
-       error2 = security_inode_listsecurity(d_inode(dentry), &list, &left);
+       left2 = left;
+       error2 = security_inode_listsecurity(d_inode(dentry), &list, &left2);
        if (error2 < 0)
                return error2;
-       error2 = size - error - left;
+       error2 = left - left2;
+       if (list)
+               left -= error2;
 
        error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, left);
        if (error3 < 0)

base-commit: 6eb8711ece2ce27e52e327a5b7a628ed39b97f45 --
2.55.0

Signature · 1 line
paul-moore.com
maintainer
#5 lore raw

Re: [PATCH v2] NFSv4.2: fix nfs4_listxattr size accounting

Quoted 51 lines · Paul Moore
Quoted 46 lines · Achilles Gaikwad

A call to listxattr() with a buffer size of 0 returns the actual size of the buffer needed for a subsequent call. On an NFSv4.2 mount this triggers the following oops:

  [  399.768687] BUG: kernel NULL pointer dereference, address: 0000000000000000
  [  399.768705] RIP: 0010:_copy_from_pages+0x44/0xe0
  [  399.768722] Call Trace:
  [  399.768723]  nfs4_xattr_alloc_entry+0x1bf/0x1e0
  [  399.768730]  nfs4_xattr_cache_set_list+0x43/0x1f0
  [  399.768731]  nfs4_listxattr+0x21f/0x250
  [  399.768733]  vfs_listxattr+0x55/0xa0
  [  399.768736]  listxattr+0x23/0x160
  [  399.768737]  path_listxattrat+0xba/0x1e0
  [  399.768739]  do_syscall_64+0xe2/0x680

security_inode_listsecurity() (via the xattr_list_one() helper) now decrements the remaining size even when the buffer pointer is NULL, so in the size-query case, 'left' underflows to a huge size_t value. As a result, nfs4_listxattr_nfs4_user() treats the NULL buffer as a real one, leading to a NULL pointer dereference in _copy_from_pages().

security_inode_listsecurity() does not return the number of bytes it added to the list, so the code derived it as
'size - error - left'. That is also wrong in the size-query case:
the generic_listxattr() contribution is only subtracted from 'left' when a buffer is present. Thus, the query result comes up short by exactly that contribution (e.g., "system.nfs4_acl" on a mount with ACL support), and a caller that allocates the returned size gets -ERANGE on the subsequent call.

Declare 'left' as ssize_t, use a scratch copy to measure security hook consumption, and only decrement 'left' if a buffer is present.

Fixes f71ece9712b7 ("security,fs,nfs,net: update security_inode_listsecurity() interface")

---
Changes in v2:
- Use a scratch variable to track security label size directly, replacing the old formula that undercounted the size-query case.
- Drop the now-unneeded NULL-buffer special case for nfs4_listxattr_nfs4_user().
- Retitled from "fix nfs4_listxattr NULL pointer dereference"
(the same accounting bug caused both the oops and the undercount).
v1: https://lore.kernel.org/linux-nfs/[email protected]/

Quoted 2 lines
 fs/nfs/nfs4proc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
Quoted 7 lines

[CC'd the LSM and SELinux lists for visibility]

Unfortunately my testing was unsuccessful due to an NFS problem that started with the v7.2 merge window that I haven't had the time to bisect yet. Assuming the NFS folks are okay with this change, I figure they will want to send it up to Linus via their tree, if not let me know and I can send this up via the LSM tree.

Yeah, we'll send it through the NFS tree. I'll be curious to hear what problem you're hitting, and what patch is the culprit once you do that bisect!

Anna

Quoted 40 lines
Quoted 34 lines
fs/nfs/nfs4proc.c +7 -3
index 1360409d8de9..a3415082d610 100644
@@ -10585,7 +10585,8 @@ const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
 static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
 {
        ssize_t error, error2, error3;
-       size_t left = size;
+       ssize_t left = size;
+       ssize_t left2;
 
        error = generic_listxattr(dentry, list, left);
        if (error < 0)
@@ -10595,10 +10596,13 @@ static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
                left -= error;
        }
 
-       error2 = security_inode_listsecurity(d_inode(dentry), &list, &left);
+       left2 = left;
+       error2 = security_inode_listsecurity(d_inode(dentry), &list, &left2);
        if (error2 < 0)
                return error2;
-       error2 = size - error - left;
+       error2 = left - left2;
+       if (list)
+               left -= error2;
 
        error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, left);
        if (error3 < 0)

base-commit: 6eb8711ece2ce27e52e327a5b7a628ed39b97f45 --
2.55.0

Signature · 1 line
paul-moore.com
maintainer
#6 lore raw

Re: [PATCH v2] NFSv4.2: fix nfs4_listxattr size accounting

Quoted 54 lines · Anna Schumaker
Quoted 53 lines · Paul Moore
Quoted 46 lines · Achilles Gaikwad

A call to listxattr() with a buffer size of 0 returns the actual size of the buffer needed for a subsequent call. On an NFSv4.2 mount this triggers the following oops:

  [  399.768687] BUG: kernel NULL pointer dereference, address: 0000000000000000
  [  399.768705] RIP: 0010:_copy_from_pages+0x44/0xe0
  [  399.768722] Call Trace:
  [  399.768723]  nfs4_xattr_alloc_entry+0x1bf/0x1e0
  [  399.768730]  nfs4_xattr_cache_set_list+0x43/0x1f0
  [  399.768731]  nfs4_listxattr+0x21f/0x250
  [  399.768733]  vfs_listxattr+0x55/0xa0
  [  399.768736]  listxattr+0x23/0x160
  [  399.768737]  path_listxattrat+0xba/0x1e0
  [  399.768739]  do_syscall_64+0xe2/0x680

security_inode_listsecurity() (via the xattr_list_one() helper) now decrements the remaining size even when the buffer pointer is NULL, so in the size-query case, 'left' underflows to a huge size_t value. As a result, nfs4_listxattr_nfs4_user() treats the NULL buffer as a real one, leading to a NULL pointer dereference in _copy_from_pages().

security_inode_listsecurity() does not return the number of bytes it added to the list, so the code derived it as
'size - error - left'. That is also wrong in the size-query case:
the generic_listxattr() contribution is only subtracted from 'left' when a buffer is present. Thus, the query result comes up short by exactly that contribution (e.g., "system.nfs4_acl" on a mount with ACL support), and a caller that allocates the returned size gets -ERANGE on the subsequent call.

Declare 'left' as ssize_t, use a scratch copy to measure security hook consumption, and only decrement 'left' if a buffer is present.

Fixes f71ece9712b7 ("security,fs,nfs,net: update security_inode_listsecurity() interface")

---
Changes in v2:
- Use a scratch variable to track security label size directly, replacing the old formula that undercounted the size-query case.
- Drop the now-unneeded NULL-buffer special case for nfs4_listxattr_nfs4_user().
- Retitled from "fix nfs4_listxattr NULL pointer dereference"
(the same accounting bug caused both the oops and the undercount).
v1: https://lore.kernel.org/linux-nfs/[email protected]/

Quoted 2 lines
 fs/nfs/nfs4proc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

[CC'd the LSM and SELinux lists for visibility]

Quoted 7 lines
Quoted 5 lines

Unfortunately my testing was unsuccessful due to an NFS problem that started with the v7.2 merge window that I haven't had the time to bisect yet. Assuming the NFS folks are okay with this change, I figure they will want to send it up to Linus via their tree, if not let me know and I can send this up via the LSM tree.

Yeah, we'll send it through the NFS tree.

Thanks Anna.

Quoted 3 lines

I'll be curious to hear
what problem you're hitting, and what patch is the culprit once you do that bisect!

Yes, me too :)

I'm still working through a review backlog so it might be a bit before I have a chance, but in case anyone wants to test it out, it's easily reproduced using the selinux-testsuite and the NFS tests:

https://github.com/SELinuxProject/selinux-testsuite#nfs

Signature · 1 line
paul-moore.com
maintainer
#7 lore raw

Re: [PATCH v2] NFSv4.2: fix nfs4_listxattr size accounting

Quoted 70 lines · Paul Moore
Quoted 54 lines · Anna Schumaker
Quoted 53 lines · Paul Moore
Quoted 46 lines · Achilles Gaikwad

A call to listxattr() with a buffer size of 0 returns the actual size of the buffer needed for a subsequent call. On an NFSv4.2 mount this triggers the following oops:

  [  399.768687] BUG: kernel NULL pointer dereference, address: 0000000000000000
  [  399.768705] RIP: 0010:_copy_from_pages+0x44/0xe0
  [  399.768722] Call Trace:
  [  399.768723]  nfs4_xattr_alloc_entry+0x1bf/0x1e0
  [  399.768730]  nfs4_xattr_cache_set_list+0x43/0x1f0
  [  399.768731]  nfs4_listxattr+0x21f/0x250
  [  399.768733]  vfs_listxattr+0x55/0xa0
  [  399.768736]  listxattr+0x23/0x160
  [  399.768737]  path_listxattrat+0xba/0x1e0
  [  399.768739]  do_syscall_64+0xe2/0x680

security_inode_listsecurity() (via the xattr_list_one() helper) now decrements the remaining size even when the buffer pointer is NULL, so in the size-query case, 'left' underflows to a huge size_t value. As a result, nfs4_listxattr_nfs4_user() treats the NULL buffer as a real one, leading to a NULL pointer dereference in _copy_from_pages().

security_inode_listsecurity() does not return the number of bytes it added to the list, so the code derived it as
'size - error - left'. That is also wrong in the size-query case:
the generic_listxattr() contribution is only subtracted from 'left' when a buffer is present. Thus, the query result comes up short by exactly that contribution (e.g., "system.nfs4_acl" on a mount with ACL support), and a caller that allocates the returned size gets -ERANGE on the subsequent call.

Declare 'left' as ssize_t, use a scratch copy to measure security hook consumption, and only decrement 'left' if a buffer is present.

Fixes f71ece9712b7 ("security,fs,nfs,net: update security_inode_listsecurity() interface")

---
Changes in v2:
- Use a scratch variable to track security label size directly, replacing the old formula that undercounted the size-query case.
- Drop the now-unneeded NULL-buffer special case for nfs4_listxattr_nfs4_user().
- Retitled from "fix nfs4_listxattr NULL pointer dereference"
(the same accounting bug caused both the oops and the undercount).
v1: https://lore.kernel.org/linux-nfs/[email protected]/

Quoted 2 lines
 fs/nfs/nfs4proc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

[CC'd the LSM and SELinux lists for visibility]

Quoted 7 lines
Quoted 5 lines

Unfortunately my testing was unsuccessful due to an NFS problem that started with the v7.2 merge window that I haven't had the time to bisect yet. Assuming the NFS folks are okay with this change, I figure they will want to send it up to Linus via their tree, if not let me know and I can send this up via the LSM tree.

Yeah, we'll send it through the NFS tree.

Thanks Anna.

Quoted 3 lines

I'll be curious to hear
what problem you're hitting, and what patch is the culprit once you do that bisect!

Quoted 7 lines

Yes, me too :)

I'm still working through a review backlog so it might be a bit before I have a chance, but in case anyone wants to test it out, it's easily reproduced using the selinux-testsuite and the NFS tests:

https://github.com/SELinuxProject/selinux-testsuite#nfs

They seem to pass for me with and without the patch (they don't exercise listxattr AFAIK).
This was on the current selinux/dev branch, v7.2-rc1 based.

maintainer
#8 lore raw

Re: [PATCH v2] NFSv4.2: fix nfs4_listxattr size accounting

Quoted 77 lines · Stephen Smalley
Quoted 76 lines · Paul Moore
Quoted 54 lines · Anna Schumaker
Quoted 53 lines · Paul Moore
Quoted 46 lines · Achilles Gaikwad

A call to listxattr() with a buffer size of 0 returns the actual size of the buffer needed for a subsequent call. On an NFSv4.2 mount this triggers the following oops:

  [  399.768687] BUG: kernel NULL pointer dereference, address: 0000000000000000
  [  399.768705] RIP: 0010:_copy_from_pages+0x44/0xe0
  [  399.768722] Call Trace:
  [  399.768723]  nfs4_xattr_alloc_entry+0x1bf/0x1e0
  [  399.768730]  nfs4_xattr_cache_set_list+0x43/0x1f0
  [  399.768731]  nfs4_listxattr+0x21f/0x250
  [  399.768733]  vfs_listxattr+0x55/0xa0
  [  399.768736]  listxattr+0x23/0x160
  [  399.768737]  path_listxattrat+0xba/0x1e0
  [  399.768739]  do_syscall_64+0xe2/0x680

security_inode_listsecurity() (via the xattr_list_one() helper) now decrements the remaining size even when the buffer pointer is NULL, so in the size-query case, 'left' underflows to a huge size_t value. As a result, nfs4_listxattr_nfs4_user() treats the NULL buffer as a real one, leading to a NULL pointer dereference in _copy_from_pages().

security_inode_listsecurity() does not return the number of bytes it added to the list, so the code derived it as
'size - error - left'. That is also wrong in the size-query case:
the generic_listxattr() contribution is only subtracted from 'left' when a buffer is present. Thus, the query result comes up short by exactly that contribution (e.g., "system.nfs4_acl" on a mount with ACL support), and a caller that allocates the returned size gets -ERANGE on the subsequent call.

Declare 'left' as ssize_t, use a scratch copy to measure security hook consumption, and only decrement 'left' if a buffer is present.

Fixes f71ece9712b7 ("security,fs,nfs,net: update security_inode_listsecurity() interface")

---
Changes in v2:
- Use a scratch variable to track security label size directly, replacing the old formula that undercounted the size-query case.
- Drop the now-unneeded NULL-buffer special case for nfs4_listxattr_nfs4_user().
- Retitled from "fix nfs4_listxattr NULL pointer dereference"
(the same accounting bug caused both the oops and the undercount).
v1: https://lore.kernel.org/linux-nfs/[email protected]/

Quoted 2 lines
 fs/nfs/nfs4proc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

[CC'd the LSM and SELinux lists for visibility]

Quoted 7 lines
Quoted 5 lines

Unfortunately my testing was unsuccessful due to an NFS problem that started with the v7.2 merge window that I haven't had the time to bisect yet. Assuming the NFS folks are okay with this change, I figure they will want to send it up to Linus via their tree, if not let me know and I can send this up via the LSM tree.

Yeah, we'll send it through the NFS tree.

Thanks Anna.

Quoted 3 lines

I'll be curious to hear
what problem you're hitting, and what patch is the culprit once you do that bisect!

Yes, me too :)

I'm still working through a review backlog so it might be a bit before I have a chance, but in case anyone wants to test it out, it's easily reproduced using the selinux-testsuite and the NFS tests:

Quoted 5 lines
Quoted 1 line

https://github.com/SELinuxProject/selinux-testsuite#nfs

They seem to pass for me with and without the patch (they don't exercise listxattr AFAIK).
This was on the current selinux/dev branch, v7.2-rc1 based.

They work for me on vanilla v7.1 and fail somewhere before vanilla v7.2-rc1 (still bisecting).

I wonder if there is an interaction problem with a recent userspace update. What distro/userspace are you running for your tests? I'm doing my testing on a relatively recent Rawhide.

Signature · 1 line
paul-moore.com
maintainer
#9 lore raw

Re: [PATCH v2] NFSv4.2: fix nfs4_listxattr size accounting

Quoted 86 lines · Paul Moore
Quoted 77 lines · Stephen Smalley
Quoted 76 lines · Paul Moore
Quoted 54 lines · Anna Schumaker
Quoted 53 lines · Paul Moore
Quoted 46 lines · Achilles Gaikwad

A call to listxattr() with a buffer size of 0 returns the actual size of the buffer needed for a subsequent call. On an NFSv4.2 mount this triggers the following oops:

  [  399.768687] BUG: kernel NULL pointer dereference, address: 0000000000000000
  [  399.768705] RIP: 0010:_copy_from_pages+0x44/0xe0
  [  399.768722] Call Trace:
  [  399.768723]  nfs4_xattr_alloc_entry+0x1bf/0x1e0
  [  399.768730]  nfs4_xattr_cache_set_list+0x43/0x1f0
  [  399.768731]  nfs4_listxattr+0x21f/0x250
  [  399.768733]  vfs_listxattr+0x55/0xa0
  [  399.768736]  listxattr+0x23/0x160
  [  399.768737]  path_listxattrat+0xba/0x1e0
  [  399.768739]  do_syscall_64+0xe2/0x680

security_inode_listsecurity() (via the xattr_list_one() helper) now decrements the remaining size even when the buffer pointer is NULL, so in the size-query case, 'left' underflows to a huge size_t value. As a result, nfs4_listxattr_nfs4_user() treats the NULL buffer as a real one, leading to a NULL pointer dereference in _copy_from_pages().

security_inode_listsecurity() does not return the number of bytes it added to the list, so the code derived it as
'size - error - left'. That is also wrong in the size-query case:
the generic_listxattr() contribution is only subtracted from 'left' when a buffer is present. Thus, the query result comes up short by exactly that contribution (e.g., "system.nfs4_acl" on a mount with ACL support), and a caller that allocates the returned size gets -ERANGE on the subsequent call.

Declare 'left' as ssize_t, use a scratch copy to measure security hook consumption, and only decrement 'left' if a buffer is present.

Fixes f71ece9712b7 ("security,fs,nfs,net: update security_inode_listsecurity() interface")

---
Changes in v2:
- Use a scratch variable to track security label size directly, replacing the old formula that undercounted the size-query case.
- Drop the now-unneeded NULL-buffer special case for nfs4_listxattr_nfs4_user().
- Retitled from "fix nfs4_listxattr NULL pointer dereference"
(the same accounting bug caused both the oops and the undercount).
v1: https://lore.kernel.org/linux-nfs/[email protected]/

Quoted 2 lines
 fs/nfs/nfs4proc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

[CC'd the LSM and SELinux lists for visibility]

Quoted 7 lines
Quoted 5 lines

Unfortunately my testing was unsuccessful due to an NFS problem that started with the v7.2 merge window that I haven't had the time to bisect yet. Assuming the NFS folks are okay with this change, I figure they will want to send it up to Linus via their tree, if not let me know and I can send this up via the LSM tree.

Yeah, we'll send it through the NFS tree.

Thanks Anna.

Quoted 3 lines

I'll be curious to hear
what problem you're hitting, and what patch is the culprit once you do that bisect!

Yes, me too :)

I'm still working through a review backlog so it might be a bit before I have a chance, but in case anyone wants to test it out, it's easily reproduced using the selinux-testsuite and the NFS tests:

Quoted 5 lines
Quoted 1 line

https://github.com/SELinuxProject/selinux-testsuite#nfs

They seem to pass for me with and without the patch (they don't exercise listxattr AFAIK).
This was on the current selinux/dev branch, v7.2-rc1 based.

Quoted 6 lines

They work for me on vanilla v7.1 and fail somewhere before vanilla v7.2-rc1 (still bisecting).

I wonder if there is an interaction problem with a recent userspace update. What distro/userspace are you running for your tests? I'm doing my testing on a relatively recent Rawhide.

I was on F44, so yes, it could be a difference in e.g. coreutils or other userspace on rawhide that is tickling this particular bug.

maintainer
#10 lore raw

Re: [PATCH v2] NFSv4.2: fix nfs4_listxattr size accounting

Quoted 89 lines · Stephen Smalley
Quoted 88 lines · Paul Moore
Quoted 77 lines · Stephen Smalley
Quoted 76 lines · Paul Moore
Quoted 54 lines · Anna Schumaker
Quoted 53 lines · Paul Moore
Quoted 46 lines · Achilles Gaikwad

A call to listxattr() with a buffer size of 0 returns the actual size of the buffer needed for a subsequent call. On an NFSv4.2 mount this triggers the following oops:

  [  399.768687] BUG: kernel NULL pointer dereference, address: 0000000000000000
  [  399.768705] RIP: 0010:_copy_from_pages+0x44/0xe0
  [  399.768722] Call Trace:
  [  399.768723]  nfs4_xattr_alloc_entry+0x1bf/0x1e0
  [  399.768730]  nfs4_xattr_cache_set_list+0x43/0x1f0
  [  399.768731]  nfs4_listxattr+0x21f/0x250
  [  399.768733]  vfs_listxattr+0x55/0xa0
  [  399.768736]  listxattr+0x23/0x160
  [  399.768737]  path_listxattrat+0xba/0x1e0
  [  399.768739]  do_syscall_64+0xe2/0x680

security_inode_listsecurity() (via the xattr_list_one() helper) now decrements the remaining size even when the buffer pointer is NULL, so in the size-query case, 'left' underflows to a huge size_t value. As a result, nfs4_listxattr_nfs4_user() treats the NULL buffer as a real one, leading to a NULL pointer dereference in _copy_from_pages().

security_inode_listsecurity() does not return the number of bytes it added to the list, so the code derived it as
'size - error - left'. That is also wrong in the size-query case:
the generic_listxattr() contribution is only subtracted from 'left' when a buffer is present. Thus, the query result comes up short by exactly that contribution (e.g., "system.nfs4_acl" on a mount with ACL support), and a caller that allocates the returned size gets -ERANGE on the subsequent call.

Declare 'left' as ssize_t, use a scratch copy to measure security hook consumption, and only decrement 'left' if a buffer is present.

Fixes f71ece9712b7 ("security,fs,nfs,net: update security_inode_listsecurity() interface")

---
Changes in v2:
- Use a scratch variable to track security label size directly, replacing the old formula that undercounted the size-query case.
- Drop the now-unneeded NULL-buffer special case for nfs4_listxattr_nfs4_user().
- Retitled from "fix nfs4_listxattr NULL pointer dereference"
(the same accounting bug caused both the oops and the undercount).
v1: https://lore.kernel.org/linux-nfs/[email protected]/

Quoted 2 lines
 fs/nfs/nfs4proc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

[CC'd the LSM and SELinux lists for visibility]

Quoted 7 lines
Quoted 5 lines

Unfortunately my testing was unsuccessful due to an NFS problem that started with the v7.2 merge window that I haven't had the time to bisect yet. Assuming the NFS folks are okay with this change, I figure they will want to send it up to Linus via their tree, if not let me know and I can send this up via the LSM tree.

Yeah, we'll send it through the NFS tree.

Thanks Anna.

Quoted 3 lines

I'll be curious to hear
what problem you're hitting, and what patch is the culprit once you do that bisect!

Yes, me too :)

I'm still working through a review backlog so it might be a bit before I have a chance, but in case anyone wants to test it out, it's easily reproduced using the selinux-testsuite and the NFS tests:

Quoted 5 lines
Quoted 1 line

https://github.com/SELinuxProject/selinux-testsuite#nfs

They seem to pass for me with and without the patch (they don't exercise listxattr AFAIK).
This was on the current selinux/dev branch, v7.2-rc1 based.

They work for me on vanilla v7.1 and fail somewhere before vanilla v7.2-rc1 (still bisecting).

Quoted 6 lines
Quoted 3 lines

I wonder if there is an interaction problem with a recent userspace update. What distro/userspace are you running for your tests? I'm doing my testing on a relatively recent Rawhide.

I was on F44, so yes, it could be a difference in e.g. coreutils or other userspace on rawhide that is tickling this particular bug.

I haven't had a chance to look into this yet, but the git bisect just produced the commit below as the offending commit:

commit 01c2305795a3b6b164df48e72b12022a68fd60c1
Author: Jeff Layton <[email protected]>
Date: Wed Mar 25 10:40:32 2026 -0400

nfsd: add netlink upcall for the nfsd.fh cache

Add netlink-based cache upcall support for the expkey (nfsd.fh) cache, following the same pattern as the existing svc_export netlink support.

Add expkey to the cache-type enum, a new expkey attribute-set with client, fsidtype, fsid, negative, expiry, and path fields, and the expkey-get-reqs / expkey-set-reqs operations to the nfsd YAML spec and generated headers.

Implement nfsd_nl_expkey_get_reqs_dumpit() which snapshots pending expkey cache requests and sends each entry's seqno, client name, fsidtype, and fsid over netlink.

Implement nfsd_nl_expkey_set_reqs_doit() which parses expkey cache responses from userspace (client, fsidtype, fsid, expiry, and path or negative flag) and updates the cache via svc_expkey_lookup() / svc_expkey_update().

Wire up the expkey_notify() callback in svc_expkey_cache_template so cache misses trigger NFSD_CMD_CACHE_NOTIFY multicast events with NFSD_CACHE_TYPE_EXPKEY.

Signature · 1 line
paul-moore.com
maintainer
#11 lore raw

Re: [PATCH v2] NFSv4.2: fix nfs4_listxattr size accounting

Quoted 98 lines · Paul Moore
Quoted 89 lines · Stephen Smalley
Quoted 88 lines · Paul Moore
Quoted 77 lines · Stephen Smalley
Quoted 76 lines · Paul Moore
Quoted 54 lines · Anna Schumaker
Quoted 53 lines · Paul Moore
Quoted 46 lines · Achilles Gaikwad

A call to listxattr() with a buffer size of 0 returns the actual size of the buffer needed for a subsequent call. On an NFSv4.2 mount this triggers the following oops:

  [  399.768687] BUG: kernel NULL pointer dereference, address: 0000000000000000
  [  399.768705] RIP: 0010:_copy_from_pages+0x44/0xe0
  [  399.768722] Call Trace:
  [  399.768723]  nfs4_xattr_alloc_entry+0x1bf/0x1e0
  [  399.768730]  nfs4_xattr_cache_set_list+0x43/0x1f0
  [  399.768731]  nfs4_listxattr+0x21f/0x250
  [  399.768733]  vfs_listxattr+0x55/0xa0
  [  399.768736]  listxattr+0x23/0x160
  [  399.768737]  path_listxattrat+0xba/0x1e0
  [  399.768739]  do_syscall_64+0xe2/0x680

security_inode_listsecurity() (via the xattr_list_one() helper) now decrements the remaining size even when the buffer pointer is NULL, so in the size-query case, 'left' underflows to a huge size_t value. As a result, nfs4_listxattr_nfs4_user() treats the NULL buffer as a real one, leading to a NULL pointer dereference in _copy_from_pages().

security_inode_listsecurity() does not return the number of bytes it added to the list, so the code derived it as
'size - error - left'. That is also wrong in the size-query case:
the generic_listxattr() contribution is only subtracted from 'left' when a buffer is present. Thus, the query result comes up short by exactly that contribution (e.g., "system.nfs4_acl" on a mount with ACL support), and a caller that allocates the returned size gets -ERANGE on the subsequent call.

Declare 'left' as ssize_t, use a scratch copy to measure security hook consumption, and only decrement 'left' if a buffer is present.

Fixes f71ece9712b7 ("security,fs,nfs,net: update security_inode_listsecurity() interface")

---
Changes in v2:
- Use a scratch variable to track security label size directly, replacing the old formula that undercounted the size-query case.
- Drop the now-unneeded NULL-buffer special case for nfs4_listxattr_nfs4_user().
- Retitled from "fix nfs4_listxattr NULL pointer dereference"
(the same accounting bug caused both the oops and the undercount).
v1: https://lore.kernel.org/linux-nfs/[email protected]/

Quoted 2 lines
 fs/nfs/nfs4proc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

[CC'd the LSM and SELinux lists for visibility]

Quoted 7 lines
Quoted 5 lines

Unfortunately my testing was unsuccessful due to an NFS problem that started with the v7.2 merge window that I haven't had the time to bisect yet. Assuming the NFS folks are okay with this change, I figure they will want to send it up to Linus via their tree, if not let me know and I can send this up via the LSM tree.

Yeah, we'll send it through the NFS tree.

Thanks Anna.

Quoted 3 lines

I'll be curious to hear
what problem you're hitting, and what patch is the culprit once you do that bisect!

Yes, me too :)

I'm still working through a review backlog so it might be a bit before I have a chance, but in case anyone wants to test it out, it's easily reproduced using the selinux-testsuite and the NFS tests:

Quoted 5 lines
Quoted 1 line

https://github.com/SELinuxProject/selinux-testsuite#nfs

They seem to pass for me with and without the patch (they don't exercise listxattr AFAIK).
This was on the current selinux/dev branch, v7.2-rc1 based.

They work for me on vanilla v7.1 and fail somewhere before vanilla v7.2-rc1 (still bisecting).

Quoted 6 lines
Quoted 3 lines

I wonder if there is an interaction problem with a recent userspace update. What distro/userspace are you running for your tests? I'm doing my testing on a relatively recent Rawhide.

I was on F44, so yes, it could be a difference in e.g. coreutils or other userspace on rawhide that is tickling this particular bug.

Quoted 6 lines

I haven't had a chance to look into this yet, but the git bisect just produced the commit below as the offending commit:

   commit 01c2305795a3b6b164df48e72b12022a68fd60c1
   Author: Jeff Layton <[email protected]>
   Date:   Wed Mar 25 10:40:32 2026 -0400

Ooops, nevermind, scratch that - I still have one more kernel to test.

Signature · 1 line
paul-moore.com
maintainer
#12 lore raw

Re: [PATCH v2] NFSv4.2: fix nfs4_listxattr size accounting

Quoted 100 lines · Paul Moore
Quoted 98 lines · Paul Moore
Quoted 95 lines · Stephen Smalley
Quoted 85 lines · Paul Moore
Quoted 77 lines · Stephen Smalley
Quoted 76 lines · Paul Moore
Quoted 54 lines · Anna Schumaker
Quoted 53 lines · Paul Moore
Quoted 46 lines · Achilles Gaikwad

A call to listxattr() with a buffer size of 0 returns the actual size of the buffer needed for a subsequent call. On an NFSv4.2 mount this triggers the following oops:

  [  399.768687] BUG: kernel NULL pointer dereference, address: 0000000000000000
  [  399.768705] RIP: 0010:_copy_from_pages+0x44/0xe0
  [  399.768722] Call Trace:
  [  399.768723]  nfs4_xattr_alloc_entry+0x1bf/0x1e0
  [  399.768730]  nfs4_xattr_cache_set_list+0x43/0x1f0
  [  399.768731]  nfs4_listxattr+0x21f/0x250
  [  399.768733]  vfs_listxattr+0x55/0xa0
  [  399.768736]  listxattr+0x23/0x160
  [  399.768737]  path_listxattrat+0xba/0x1e0
  [  399.768739]  do_syscall_64+0xe2/0x680

security_inode_listsecurity() (via the xattr_list_one() helper) now decrements the remaining size even when the buffer pointer is NULL, so in the size-query case, 'left' underflows to a huge size_t value. As a result, nfs4_listxattr_nfs4_user() treats the NULL buffer as a real one, leading to a NULL pointer dereference in _copy_from_pages().

security_inode_listsecurity() does not return the number of bytes it added to the list, so the code derived it as
'size - error - left'. That is also wrong in the size-query case:
the generic_listxattr() contribution is only subtracted from 'left' when a buffer is present. Thus, the query result comes up short by exactly that contribution (e.g., "system.nfs4_acl" on a mount with ACL support), and a caller that allocates the returned size gets -ERANGE on the subsequent call.

Declare 'left' as ssize_t, use a scratch copy to measure security hook consumption, and only decrement 'left' if a buffer is present.

Fixes f71ece9712b7 ("security,fs,nfs,net: update security_inode_listsecurity() interface")

---
Changes in v2:
- Use a scratch variable to track security label size directly, replacing the old formula that undercounted the size-query case.
- Drop the now-unneeded NULL-buffer special case for nfs4_listxattr_nfs4_user().
- Retitled from "fix nfs4_listxattr NULL pointer dereference"
(the same accounting bug caused both the oops and the undercount).
v1: https://lore.kernel.org/linux-nfs/[email protected]/

Quoted 2 lines
 fs/nfs/nfs4proc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

[CC'd the LSM and SELinux lists for visibility]

Quoted 7 lines
Quoted 5 lines

Unfortunately my testing was unsuccessful due to an NFS problem that started with the v7.2 merge window that I haven't had the time to bisect yet. Assuming the NFS folks are okay with this change, I figure they will want to send it up to Linus via their tree, if not let me know and I can send this up via the LSM tree.

Yeah, we'll send it through the NFS tree.

Thanks Anna.

Quoted 3 lines

I'll be curious to hear
what problem you're hitting, and what patch is the culprit once you do that bisect!

Yes, me too :)

I'm still working through a review backlog so it might be a bit before I have a chance, but in case anyone wants to test it out, it's easily reproduced using the selinux-testsuite and the NFS tests:

Quoted 5 lines
Quoted 1 line

https://github.com/SELinuxProject/selinux-testsuite#nfs

They seem to pass for me with and without the patch (they don't exercise listxattr AFAIK).
This was on the current selinux/dev branch, v7.2-rc1 based.

Quoted 6 lines

They work for me on vanilla v7.1 and fail somewhere before vanilla v7.2-rc1 (still bisecting).

I wonder if there is an interaction problem with a recent userspace update. What distro/userspace are you running for your tests? I'm doing my testing on a relatively recent Rawhide.

I was on F44, so yes, it could be a difference in e.g. coreutils or other userspace on rawhide that is tickling this particular bug.

Quoted 8 lines
Quoted 6 lines

I haven't had a chance to look into this yet, but the git bisect just produced the commit below as the offending commit:

   commit 01c2305795a3b6b164df48e72b12022a68fd60c1
   Author: Jeff Layton <[email protected]>
   Date:   Wed Mar 25 10:40:32 2026 -0400

Ooops, nevermind, scratch that - I still have one more kernel to test.

... and scratch that, the offending commit was that one.

commit 01c2305795a3b6b164df48e72b12022a68fd60c1
Author: Jeff Layton <[email protected]>
Date: Wed Mar 25 10:40:32 2026 -0400

nfsd: add netlink upcall for the nfsd.fh cache

Add netlink-based cache upcall support for the expkey (nfsd.fh) cache, following the same pattern as the existing svc_export netlink support.

Add expkey to the cache-type enum, a new expkey attribute-set with client, fsidtype, fsid, negative, expiry, and path fields, and the expkey-get-reqs / expkey-set-reqs operations to the nfsd YAML spec and generated headers.

Implement nfsd_nl_expkey_get_reqs_dumpit() which snapshots pending expkey cache requests and sends each entry's seqno, client name, fsidtype, and fsid over netlink.

Implement nfsd_nl_expkey_set_reqs_doit() which parses expkey cache responses from userspace (client, fsidtype, fsid, expiry, and path or negative flag) and updates the cache via svc_expkey_lookup() / svc_expkey_update().

Wire up the expkey_notify() callback in svc_expkey_cache_template so cache misses trigger NFSD_CMD_CACHE_NOTIFY multicast events with NFSD_CACHE_TYPE_EXPKEY.

Signature · 1 line
paul-moore.com
maintainer
#13 lore raw

Re: [PATCH v2] NFSv4.2: fix nfs4_listxattr size accounting

Quoted 26 lines · Paul Moore

... and scratch that, the offending commit was that one.

commit 01c2305795a3b6b164df48e72b12022a68fd60c1
Author: Jeff Layton <[email protected]>
Date: Wed Mar 25 10:40:32 2026 -0400

nfsd: add netlink upcall for the nfsd.fh cache

Add netlink-based cache upcall support for the expkey (nfsd.fh) cache, following the same pattern as the existing svc_export netlink support.

Add expkey to the cache-type enum, a new expkey attribute-set with client, fsidtype, fsid, negative, expiry, and path fields, and the expkey-get-reqs / expkey-set-reqs operations to the nfsd YAML spec and generated headers.

Implement nfsd_nl_expkey_get_reqs_dumpit() which snapshots pending expkey cache requests and sends each entry's seqno, client name, fsidtype, and fsid over netlink.

Implement nfsd_nl_expkey_set_reqs_doit() which parses expkey cache responses from userspace (client, fsidtype, fsid, expiry, and path or negative flag) and updates the cache via svc_expkey_lookup() / svc_expkey_update().

Quoted 6 lines

Wire up the expkey_notify() callback in svc_expkey_cache_template so cache misses trigger NFSD_CMD_CACHE_NOTIFY multicast events with NFSD_CACHE_TYPE_EXPKEY.

Playing around with it some this morning on a current Fedora Rawhide system, I can reproduce the problem with a simple command line:

% mount -t nfs localhost:/mnt/test /mnt/nfs_test mount.nfs: Connection refused for localhost:/mnt/test on /mnt/nfs_test

... adding an explicit "vers={4,4.1,4.2}" has no effect; versions 2 and 3 are no supported on my kernel builds. There is nothing obvious in dmesg. I've run with SELinux both in permissive mode and disabled and encountered the same problem. This doesn't appear to be related to SELinux, it may simply be that we are the first ones to hit this.

As there was some earlier discussion about this being a wonky interaction with userspace, here are some of the relevant packages on my system:

nfs-common-utils-2.9.1-4.rc4.fc45.x86_64
nfs-client-utils-2.9.1-4.rc4.fc45.x86_64
nfsv4-client-utils-2.9.1-4.rc4.fc45.x86_64
nfs-utils-2.9.1-4.rc4.fc45.x86_64

My next step is to try disabling portions of the NFS file handle cache upcall to see if that is the issue, but it would be nice if the NFS devs could take a look at this too. I'm happy to test things out or answer any questions about my test system.

Signature · 1 line
paul-moore.com
#14 lore raw

Re: [PATCH v2] NFSv4.2: fix nfs4_listxattr size accounting

Quoted 55 lines · Paul Moore
Quoted 26 lines · Paul Moore

... and scratch that, the offending commit was that one.

commit 01c2305795a3b6b164df48e72b12022a68fd60c1
Author: Jeff Layton <[email protected]>
Date: Wed Mar 25 10:40:32 2026 -0400

nfsd: add netlink upcall for the nfsd.fh cache

Add netlink-based cache upcall support for the expkey (nfsd.fh) cache, following the same pattern as the existing svc_export netlink support.

Add expkey to the cache-type enum, a new expkey attribute-set with client, fsidtype, fsid, negative, expiry, and path fields, and the expkey-get-reqs / expkey-set-reqs operations to the nfsd YAML spec and generated headers.

Implement nfsd_nl_expkey_get_reqs_dumpit() which snapshots pending expkey cache requests and sends each entry's seqno, client name, fsidtype, and fsid over netlink.

Implement nfsd_nl_expkey_set_reqs_doit() which parses expkey cache responses from userspace (client, fsidtype, fsid, expiry, and path or negative flag) and updates the cache via svc_expkey_lookup() / svc_expkey_update().

Quoted 6 lines

Wire up the expkey_notify() callback in svc_expkey_cache_template so cache misses trigger NFSD_CMD_CACHE_NOTIFY multicast events with NFSD_CACHE_TYPE_EXPKEY.

Playing around with it some this morning on a current Fedora Rawhide system, I can reproduce the problem with a simple command line:

% mount -t nfs localhost:/mnt/test /mnt/nfs_test mount.nfs: Connection refused for localhost:/mnt/test on /mnt/nfs_test

... adding an explicit "vers={4,4.1,4.2}" has no effect; versions 2 and 3 are no supported on my kernel builds. There is nothing obvious in dmesg. I've run with SELinux both in permissive mode and disabled and encountered the same problem. This doesn't appear to be related to SELinux, it may simply be that we are the first ones to hit this.

As there was some earlier discussion about this being a wonky interaction with userspace, here are some of the relevant packages on my system:

nfs-common-utils-2.9.1-4.rc4.fc45.x86_64
nfs-client-utils-2.9.1-4.rc4.fc45.x86_64
nfsv4-client-utils-2.9.1-4.rc4.fc45.x86_64
nfs-utils-2.9.1-4.rc4.fc45.x86_64

Quoted 4 lines

My next step is to try disabling portions of the NFS file handle cache upcall to see if that is the issue, but it would be nice if the NFS devs could take a look at this too. I'm happy to test things out or answer any questions about my test system.

Pardon the dumb question, but are you positive your NFS server is running? No errors from 'systemctl status nfs-server.service' or 'systemctl status nfs-mountd.service'? A connection refused error typically indicates the server isn't running.

What if you add 'no-netlink=1' to the mountd stanza in /etc/nfs.conf and restart nfs-server.service?

FWIW the netlink upcall requires CAP_NET_ADMIN, which is blocked by the current selinux-policy on rawhide (and I think it's a dontaudit rule)... but you said you've disabled SELinux and reproduced your problem, so I'm scratching my head. Plus the symptom I ran into was the mount command hanging, not a 'connection refused' error. At any rate I filed
https://github.com/fedora-selinux/selinux-policy/pull/3278 to update the selinux-policy (no movement on that yet) and the most recent mountd patch improves the fallback to the old proc interface, but I don't think it's been added to Fedora yet either.

-Scott

Quoted 4 lines
Signature · 2 lines
-- 
paul-moore.com
maintainer
#15 lore raw

Re: [PATCH v2] NFSv4.2: fix nfs4_listxattr size accounting

Quoted 56 lines · Scott Mayhew
Quoted 55 lines · Paul Moore
Quoted 26 lines · Paul Moore

... and scratch that, the offending commit was that one.

commit 01c2305795a3b6b164df48e72b12022a68fd60c1
Author: Jeff Layton <[email protected]>
Date: Wed Mar 25 10:40:32 2026 -0400

nfsd: add netlink upcall for the nfsd.fh cache

Add netlink-based cache upcall support for the expkey (nfsd.fh) cache, following the same pattern as the existing svc_export netlink support.

Add expkey to the cache-type enum, a new expkey attribute-set with client, fsidtype, fsid, negative, expiry, and path fields, and the expkey-get-reqs / expkey-set-reqs operations to the nfsd YAML spec and generated headers.

Implement nfsd_nl_expkey_get_reqs_dumpit() which snapshots pending expkey cache requests and sends each entry's seqno, client name, fsidtype, and fsid over netlink.

Implement nfsd_nl_expkey_set_reqs_doit() which parses expkey cache responses from userspace (client, fsidtype, fsid, expiry, and path or negative flag) and updates the cache via svc_expkey_lookup() / svc_expkey_update().

Quoted 6 lines

Wire up the expkey_notify() callback in svc_expkey_cache_template so cache misses trigger NFSD_CMD_CACHE_NOTIFY multicast events with NFSD_CACHE_TYPE_EXPKEY.

Playing around with it some this morning on a current Fedora Rawhide system, I can reproduce the problem with a simple command line:

% mount -t nfs localhost:/mnt/test /mnt/nfs_test mount.nfs: Connection refused for localhost:/mnt/test on /mnt/nfs_test

... adding an explicit "vers={4,4.1,4.2}" has no effect; versions 2 and 3 are no supported on my kernel builds. There is nothing obvious in dmesg. I've run with SELinux both in permissive mode and disabled and encountered the same problem. This doesn't appear to be related to SELinux, it may simply be that we are the first ones to hit this.

As there was some earlier discussion about this being a wonky interaction with userspace, here are some of the relevant packages on my system:

nfs-common-utils-2.9.1-4.rc4.fc45.x86_64
nfs-client-utils-2.9.1-4.rc4.fc45.x86_64
nfsv4-client-utils-2.9.1-4.rc4.fc45.x86_64
nfs-utils-2.9.1-4.rc4.fc45.x86_64

Quoted 7 lines
Quoted 4 lines

My next step is to try disabling portions of the NFS file handle cache upcall to see if that is the issue, but it would be nice if the NFS devs could take a look at this too. I'm happy to test things out or answer any questions about my test system.

Pardon the dumb question, but are you positive your NFS server is running?

I'm slightly embarrassed to admit that your question wasn't as dumb as one might have thought :)

While my bisection testing used the selinux-testsuite which ensures the NFS server starts, when I tried to create a simple reproducer to share with the non-SELinux crowd I neglected to verify that the NFS server was running, the directory, was exported, etc. My apologies for the confusion. However, the problem was real, even if my reproducer and error message were junk.

Quoted 2 lines

FWIW the netlink upcall requires CAP_NET_ADMIN, which is blocked by the current selinux-policy on rawhide (and I think it's a dontaudit rule)...

As a quick test I added a quick hack to my policy (allow rule below) and everything appears to be working again. Thanks for the pointer!

allow nfsd_t nfsd_t:capability { net_admin };

Signature · 1 line
paul-moore.com