linux/fs/nfs
Achilles Gaikwad e053b624f5 NFSv4.2: fix nfs4_listxattr size accounting
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: f71ece9712 ("security,fs,nfs,net: update security_inode_listsecurity() interface")
Suggested-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Achilles Gaikwad <achillesgaikwad@gmail.com>
Reviewed-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Anna Schumaker <anna.schumaker@hammerspace.com>
2026-07-31 13:27:25 -04:00
..
blocklayout NFS client updates for Linux 7.1 2026-04-24 14:20:03 -07:00
filelayout pNFS/filelayout: fix cheking if a layout is striped 2026-06-08 10:21:55 -04:00
flexfilelayout NFSv4/flexfiles: honor FF_FLAGS_NO_IO_THRU_MDS in pg_get_mirror_count_write 2026-06-08 12:06:41 -04:00
cache_lib.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
cache_lib.h
callback_proc.c NFSv4/pnfs: defer return_range callbacks until after inode unlock 2026-06-08 10:21:56 -04:00
callback_xdr.c nfs: use memcpy_and_pad in decode_fh 2026-04-22 08:53:23 -04:00
callback.c NFS Client Updates for Linux 7.0 2026-02-12 17:49:33 -08:00
callback.h NFS: Merge CONFIG_NFS_V4_1 with CONFIG_NFS_V4 2026-01-30 11:42:21 -05:00
client.c NFS Client Updates for Linux 7.2 2026-06-23 18:36:41 -07:00
delegation.c nfs: use nfsi->rwsem to protect traversal of the file lock list 2026-06-08 15:04:21 -04:00
delegation.h NFS: fix delayed delegation return handling 2026-01-30 16:49:15 -05:00
dir.c NFSv4: include MAY_WRITE in open permission mask for O_TRUNC 2026-07-08 14:42:02 -04:00
direct.c nfs: expose FMODE_NOWAIT for read-only files 2026-06-08 12:07:16 -04:00
dns_resolve.c sunrpc: rename sunrpc_cache_pipe_upcall_timeout() 2026-06-01 11:08:18 -04:00
dns_resolve.h
export.c nfs: replace NFS_FILEID() and nfsi->fileid with inode->i_ino 2026-06-08 10:21:54 -04:00
file.c nfs: expose FMODE_NOWAIT for read-only files 2026-06-08 12:07:16 -04:00
fs_context.c vfs: add FS_USERNS_DELEGATABLE flag and set it for NFS 2026-06-09 17:17:29 +02:00
fscache.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
fscache.h netfs: Drop the was_async arg from netfs_read_subreq_terminated() 2024-12-20 22:34:03 +01:00
getroot.c nfs: get rid of fake root dentries 2026-06-05 00:34:56 -04:00
inode.c NFS Client Updates for Linux 7.2 2026-06-23 18:36:41 -07:00
internal.h NFS: Charge unstable writes by request size, not folio size 2026-07-08 14:43:40 -04:00
io.c nfs: add nowait version of nfs_start_io_direct 2026-06-08 12:07:16 -04:00
iostat.h mm: add comments for allocation helpers explaining why they are macros 2024-07-12 15:52:20 -07:00
Kconfig NFS: Fix NFS KConfig typos 2026-02-27 15:42:14 -05:00
localio.c NFS: fix writeback in presence of errors 2026-04-22 08:53:23 -04:00
Makefile NFS: Merge CONFIG_NFS_V4_1 with CONFIG_NFS_V4 2026-01-30 11:42:21 -05:00
mount_clnt.c NFS: Remove unused function nfs_umount 2025-07-14 15:20:28 -07:00
namespace.c nfs: Implement fileattr_get for case sensitivity 2026-05-11 16:50:29 +02:00
netns.h NFS: Merge CONFIG_NFS_V4_1 with CONFIG_NFS_V4 2026-01-30 11:42:21 -05:00
nfs.h NFS: Implement get_nfs_version() 2024-11-08 14:17:37 -05:00
nfs2super.c fs: nfs: add missing MODULE_DESCRIPTION() macros 2024-07-08 13:47:24 -04:00
nfs2xdr.c nfs/localio: add tracepoints for misaligned DIO READ and WRITE support 2025-09-30 16:10:30 -04:00
nfs3_fs.h
nfs3acl.c nfs: nfs3acl: drop useless assignment in nfs3_get_acl() 2025-04-27 23:25:44 -04:00
nfs3client.c pnfs: Set transport security policy to RPC_XPRTSEC_NONE unless using TLS 2025-11-10 10:32:28 -05:00
nfs3proc.c nfs: Implement fileattr_get for case sensitivity 2026-05-11 16:50:29 +02:00
nfs3super.c fs: nfs: add missing MODULE_DESCRIPTION() macros 2024-07-08 13:47:24 -04:00
nfs3xdr.c nfs: Implement fileattr_get for case sensitivity 2026-05-11 16:50:29 +02:00
nfs4_fs.h NFSv4: pass lease period in seconds to nfs4_set_lease_period() 2026-02-09 13:39:39 -05:00
nfs4client.c NFSv4.1: Apply session size limits on clone path 2026-04-13 14:56:09 -07:00
nfs4file.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
nfs4getroot.c NFSv4: Remove duplicate lookups, capability probes and fsinfo calls 2025-08-04 09:48:16 -07:00
nfs4idmap.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
nfs4idmap.h
nfs4namespace.c NFS: remove unused page and page2 in nfs4_replace_transport() 2026-05-27 15:12:23 +02:00
nfs4proc.c NFSv4.2: fix nfs4_listxattr size accounting 2026-07-31 13:27:25 -04:00
nfs4renewd.c NFSv4: limit lease period in nfs4_set_lease_period() 2026-02-09 13:39:39 -05:00
nfs4session.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
nfs4session.h NFS: Merge CONFIG_NFS_V4_1 with CONFIG_NFS_V4 2026-01-30 11:42:21 -05:00
nfs4state.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
nfs4super.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
nfs4sysctl.c treewide: const qualify ctl_tables where applicable 2025-01-28 13:48:37 +01:00
nfs4trace.c NFS: Merge CONFIG_NFS_V4_1 with CONFIG_NFS_V4 2026-01-30 11:42:21 -05:00
nfs4trace.h nfs: replace NFS_FILEID() and nfsi->fileid with inode->i_ino 2026-06-08 10:21:54 -04:00
nfs4xdr.c NFS: Merge CONFIG_NFS_V4_1 with CONFIG_NFS_V4 2026-01-30 11:42:21 -05:00
nfs40.h NFS: Move NFS v4.0 pathdown recovery into nfs40client.c 2026-01-30 11:42:20 -05:00
nfs40client.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
nfs40proc.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
nfs42.h NFS: Add support for fallocate(FALLOC_FL_ZERO_RANGE) 2025-05-28 17:17:13 -04:00
nfs42proc.c NFS: fix eof updates after NFSv4.2 fallocate/zero-range 2026-06-08 10:21:55 -04:00
nfs42xattr.c mm/list_lru: simplify the list_lru walk callback function 2024-11-11 17:22:26 -08:00
nfs42xdr.c nfs: update inode ctime after removexattr operation 2026-04-13 11:46:08 -07:00
nfsroot.c NFS: Fix an off by one in root_nfs_cat() 2024-03-09 09:14:51 -05:00
nfstrace.c
nfstrace.h nfs: replace NFS_FILEID() and nfsi->fileid with inode->i_ino 2026-06-08 10:21:54 -04:00
pagelist.c nfs: replace NFS_FILEID() and nfsi->fileid with inode->i_ino 2026-06-08 10:21:54 -04:00
pnfs_dev.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
pnfs_nfs.c NFS: Charge unstable writes by request size, not folio size 2026-07-08 14:43:40 -04:00
pnfs.c NFSv4/pnfs: defer return_range callbacks until after inode unlock 2026-06-08 10:21:56 -04:00
pnfs.h NFS: Merge CONFIG_NFS_V4_1 with CONFIG_NFS_V4 2026-01-30 11:42:21 -05:00
proc.c nfs: Implement fileattr_get for case sensitivity 2026-05-11 16:50:29 +02:00
read.c nfs: keep PG_UPTODATE clear after read errors in page groups 2026-06-08 12:06:41 -04:00
super.c NFS Client Updates for Linux 7.2 2026-06-23 18:36:41 -07:00
symlink.c nfs: Implement fileattr_get for case sensitivity 2026-05-11 16:50:29 +02:00
sysctl.c treewide: const qualify ctl_tables where applicable 2025-01-28 13:48:37 +01:00
sysfs.c NFSD 7.1 Release Notes 2026-04-20 10:44:02 -07:00
sysfs.h NFS: Add sysfs links to sunrpc clients for nfs_clients 2023-06-19 15:04:13 -04:00
unlink.c NFS Client Updates for Linux 7.2 2026-06-23 18:36:41 -07:00
write.c NFS: Charge unstable writes by request size, not folio size 2026-07-08 14:43:40 -04:00