Skip to content

Commit 94965de

Browse files
committed
NFSv4.2: fix nfs4_listxattr kernel BUG at mm/usercopy.c:102
jira LE-1907 cve CVE-2024-26870 Rebuild_History Non-Buildable kernel-4.18.0-553.16.1.el8_10 commit-author Jorge Mora <[email protected]> commit 251a658 A call to listxattr() with a buffer size = 0 returns the actual size of the buffer needed for a subsequent call. When size > 0, nfs4_listxattr() does not return an error because either generic_listxattr() or nfs4_listxattr_nfs4_label() consumes exactly all the bytes then size is 0 when calling nfs4_listxattr_nfs4_user() which then triggers the following kernel BUG: [ 99.403778] kernel BUG at mm/usercopy.c:102! [ 99.404063] Internal error: Oops - BUG: 00000000f2000800 [#1] SMP [ 99.408463] CPU: 0 PID: 3310 Comm: python3 Not tainted 6.6.0-61.fc40.aarch64 #1 [ 99.415827] Call trace: [ 99.415985] usercopy_abort+0x70/0xa0 [ 99.416227] __check_heap_object+0x134/0x158 [ 99.416505] check_heap_object+0x150/0x188 [ 99.416696] __check_object_size.part.0+0x78/0x168 [ 99.416886] __check_object_size+0x28/0x40 [ 99.417078] listxattr+0x8c/0x120 [ 99.417252] path_listxattr+0x78/0xe0 [ 99.417476] __arm64_sys_listxattr+0x28/0x40 [ 99.417723] invoke_syscall+0x78/0x100 [ 99.417929] el0_svc_common.constprop.0+0x48/0xf0 [ 99.418186] do_el0_svc+0x24/0x38 [ 99.418376] el0_svc+0x3c/0x110 [ 99.418554] el0t_64_sync_handler+0x120/0x130 [ 99.418788] el0t_64_sync+0x194/0x198 [ 99.418994] Code: aa0003e3 d000a3e0 91310000 97f49bdb (d4210000) Issue is reproduced when generic_listxattr() returns 'system.nfs4_acl', thus calling lisxattr() with size = 16 will trigger the bug. Add check on nfs4_listxattr() to return ERANGE error when it is called with size > 0 and the return value is greater than size. Fixes: 012a211 ("NFSv4.2: hook in the user extended attribute handlers") Signed-off-by: Jorge Mora <[email protected]> Reviewed-by: Benjamin Coddington <[email protected]> Signed-off-by: Trond Myklebust <[email protected]> (cherry picked from commit 251a658) Signed-off-by: Jonathan Maple <[email protected]>
1 parent 3113497 commit 94965de

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

fs/nfs/nfs4proc.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10435,29 +10435,33 @@ const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
1043510435
static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size)
1043610436
{
1043710437
ssize_t error, error2, error3;
10438+
size_t left = size;
1043810439

10439-
error = generic_listxattr(dentry, list, size);
10440+
error = generic_listxattr(dentry, list, left);
1044010441
if (error < 0)
1044110442
return error;
1044210443
if (list) {
1044310444
list += error;
10444-
size -= error;
10445+
left -= error;
1044510446
}
1044610447

10447-
error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size);
10448+
error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, left);
1044810449
if (error2 < 0)
1044910450
return error2;
1045010451

1045110452
if (list) {
1045210453
list += error2;
10453-
size -= error2;
10454+
left -= error2;
1045410455
}
1045510456

10456-
error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, size);
10457+
error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, left);
1045710458
if (error3 < 0)
1045810459
return error3;
1045910460

10460-
return error + error2 + error3;
10461+
error += error2 + error3;
10462+
if (size && error > size)
10463+
return -ERANGE;
10464+
return error;
1046110465
}
1046210466

1046310467
static const struct inode_operations nfs4_dir_inode_operations = {

0 commit comments

Comments
 (0)