smb/client: fix memory leak in smb2_open_file()
Subsystems (2)
PATCH 1/1 smb/client: fix memory leak in smb2_open_file()
From: ChenXiaoSong <[email protected]>
Reproducer:
1. On server, set the permissions of the shared directory to read-only
2. mount -t cifs //${server_ip}/export /mnt
4. dd if=/dev/zero of=/mnt/file bs=512 count=1000 oflag=direct
5. umount /mnt
6. sleep 1
7. modprobe -r cifs
The error message is as follows:
=============================================================================
BUG cifs_small_rq (Not tainted): Objects remaining on __kmem_cache_shutdown()
-----------------------------------------------------------------------------
Object 0x00000000d47521be @offset=14336
...
WARNING: mm/slub.c:1251 at __kmem_cache_shutdown+0x34e/0x440, CPU#0: modprobe/1577 ... Call Trace: <TASK> kmem_cache_destroy+0x94/0x190 cifs_destroy_request_bufs+0x3e/0x50 [cifs] cleanup_module+0x4e/0x540 [cifs] __se_sys_delete_module+0x278/0x400 __x64_sys_delete_module+0x5f/0x70 x64_sys_call+0x2299/0x2ff0 do_syscall_64+0x89/0x350 entry_SYSCALL_64_after_hwframe+0x76/0x7e ... kmem_cache_destroy cifs_small_rq: Slab cache still has objects when called from cifs_destroy_request_bufs+0x3e/0x50 [cifs] WARNING: mm/slab_common.c:532 at kmem_cache_destroy+0x16b/0x190, CPU#0: modprobe/1577
--- fs/smb/client/smb2file.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/smb2file.c +1 -0
@@ -178,6 +178,7 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, rc =SMB2_open (xid, oparms, smb2_path, &smb2_oplock, smb2_data,NULL , &err_iov, &err_buftype);if (rc == -EACCES && retry_without_read_attributes) { +free_rsp_buf (err_buftype, err_iov.iov_base); oparms->desired_access &= ~FILE_READ_ATTRIBUTES ; rc =SMB2_open (xid, oparms, smb2_path, &smb2_oplock, smb2_data,NULL , &err_iov, &err_buftype);
Signature · 1 line
2.52.0
Hello,
Thank you for looking at this issue and preparing a fix.
Quoted 10 lines · On Sunday 01 February 2026 08:10:17 [email protected] wrote:
From: ChenXiaoSong <[email protected]>
Reproducer:
1. On server, set the permissions of the shared directory to read-only
2. mount -t cifs //${server_ip}/export /mnt
4. dd if=/dev/zero of=/mnt/file bs=512 count=1000 oflag=direct
5. umount /mnt
6. sleep 1
7. modprobe -r cifs
Another possible trigger could be to pre-create file on the server and remove write permissions for the caller. Then opening it for write access will also trigger the fallback path, which also fails.
Quoted 46 lines
The error message is as follows:
=============================================================================
BUGcifs_small_rq(Not tainted): Objects remaining on__kmem_cache_shutdown()
-----------------------------------------------------------------------------Object
0x00000000d47521be@offset=14336
...WARNING: mm/slub.c:1251 at __kmem_cache_shutdown+0x34e/0x440, CPU#0: modprobe/1577 ... Call Trace: <TASK> kmem_cache_destroy+0x94/0x190 cifs_destroy_request_bufs+0x3e/0x50 [cifs] cleanup_module+0x4e/0x540 [cifs] __se_sys_delete_module+0x278/0x400 __x64_sys_delete_module+0x5f/0x70 x64_sys_call+0x2299/0x2ff0 do_syscall_64+0x89/0x350 entry_SYSCALL_64_after_hwframe+0x76/0x7e ... kmem_cache_destroy cifs_small_rq: Slab cache still has objects when called from cifs_destroy_request_bufs+0x3e/0x50 [cifs] WARNING: mm/slab_common.c:532 at kmem_cache_destroy+0x16b/0x190, CPU#0: modprobe/1577Link https://lore.kernel.org/linux-cifs/[email protected]/T/#mf14808c144448b715f711ce5f0477a071f08eaf6 open hereFixes e255612b5ed9 ("cifs: Add fallback for SMB2 CREATE without FILE_READ_ATTRIBUTES")Signed-off-by ChenXiaoSong <[email protected]>--- fs/smb/client/smb2file.c | 1 + 1 file changed, 1 insertion(+)fs/smb/client/smb2file.c +1
-0@@ -178,6 +178,7 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, rc =SMB2_open (xid, oparms, smb2_path, &smb2_oplock, smb2_data,NULL , &err_iov, &err_buftype);if (rc == -EACCES && retry_without_read_attributes) { +free_rsp_buf (err_buftype, err_iov.iov_base); oparms->desired_access &= ~FILE_READ_ATTRIBUTES ; rc =SMB2_open (xid, oparms, smb2_path, &smb2_oplock, smb2_data,NULL , &err_iov, &err_buftype);Signature · 1 line
2.52.0
This change looks good, the second SMB2_open() is reusing &err_iov and &err_buftype, so they need to be properly released before reuse.
Good catch.
Added to cifs-2.6.git for-next
This fixes the problem for smb2 and later (next will be to fix it for smb1).
Quoted 58 lines · On Sun, Feb 1, 2026 at 2:11 AM <[email protected]> wrote:
From: ChenXiaoSong <[email protected]>
Reproducer:
1. On server, set the permissions of the shared directory to read-only
2. mount -t cifs //${server_ip}/export /mnt
4. dd if=/dev/zero of=/mnt/file bs=512 count=1000 oflag=direct
5. umount /mnt
6. sleep 1
7. modprobe -r cifsThe error message is as follows:
=============================================================================
BUGcifs_small_rq(Not tainted): Objects remaining on__kmem_cache_shutdown()
-----------------------------------------------------------------------------Object
0x00000000d47521be@offset=14336
...WARNING: mm/slub.c:1251 at __kmem_cache_shutdown+0x34e/0x440, CPU#0: modprobe/1577 ... Call Trace: <TASK> kmem_cache_destroy+0x94/0x190 cifs_destroy_request_bufs+0x3e/0x50 [cifs] cleanup_module+0x4e/0x540 [cifs] __se_sys_delete_module+0x278/0x400 __x64_sys_delete_module+0x5f/0x70 x64_sys_call+0x2299/0x2ff0 do_syscall_64+0x89/0x350 entry_SYSCALL_64_after_hwframe+0x76/0x7e ... kmem_cache_destroy cifs_small_rq: Slab cache still has objects when called from cifs_destroy_request_bufs+0x3e/0x50 [cifs] WARNING: mm/slab_common.c:532 at kmem_cache_destroy+0x16b/0x190, CPU#0: modprobe/1577Link https://lore.kernel.org/linux-cifs/[email protected]/T/#mf14808c144448b715f711ce5f0477a071f08eaf6 open hereFixes e255612b5ed9 ("cifs: Add fallback for SMB2 CREATE without FILE_READ_ATTRIBUTES")Signed-off-by ChenXiaoSong <[email protected]>--- fs/smb/client/smb2file.c | 1 + 1 file changed, 1 insertion(+)fs/smb/client/smb2file.c +1
-1@@ -178,6 +178,7 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, rc =SMB2_open (xid, oparms, smb2_path, &smb2_oplock, smb2_data,NULL , &err_iov, &err_buftype);if (rc == -EACCES && retry_without_read_attributes) { +free_rsp_buf (err_buftype, err_iov.iov_base); oparms->desired_access &= ~FILE_READ_ATTRIBUTES ; rc =SMB2_open (xid, oparms, smb2_path, &smb2_oplock, smb2_data,NULL , &err_iov, &err_buftype); --2.52.0
Signature · 3 lines
Thanks, Steve
I don't see the smb1 rmmod failure in 6.18 kernel but do see it in 6.19-rc5.
Quoted 72 lines · Steve French
Good catch.
Added to cifs-2.6.git for-next
This fixes the problem for smb2 and later (next will be to fix it for smb1).
Quoted 56 lines · On Sun, Feb 1, 2026 at 2:11 AM <[email protected]> wrote:
From: ChenXiaoSong <[email protected]>
Reproducer:
1. On server, set the permissions of the shared directory to read-only
2. mount -t cifs //${server_ip}/export /mnt
4. dd if=/dev/zero of=/mnt/file bs=512 count=1000 oflag=direct
5. umount /mnt
6. sleep 1
7. modprobe -r cifsThe error message is as follows:
=============================================================================
BUGcifs_small_rq(Not tainted): Objects remaining on__kmem_cache_shutdown()
-----------------------------------------------------------------------------Object
0x00000000d47521be@offset=14336
...WARNING: mm/slub.c:1251 at __kmem_cache_shutdown+0x34e/0x440, CPU#0: modprobe/1577 ... Call Trace: <TASK> kmem_cache_destroy+0x94/0x190 cifs_destroy_request_bufs+0x3e/0x50 [cifs] cleanup_module+0x4e/0x540 [cifs] __se_sys_delete_module+0x278/0x400 __x64_sys_delete_module+0x5f/0x70 x64_sys_call+0x2299/0x2ff0 do_syscall_64+0x89/0x350 entry_SYSCALL_64_after_hwframe+0x76/0x7e ... kmem_cache_destroy cifs_small_rq: Slab cache still has objects when called from cifs_destroy_request_bufs+0x3e/0x50 [cifs] WARNING: mm/slab_common.c:532 at kmem_cache_destroy+0x16b/0x190, CPU#0: modprobe/1577Link https://lore.kernel.org/linux-cifs/[email protected]/T/#mf14808c144448b715f711ce5f0477a071f08eaf6 open hereFixes e255612b5ed9 ("cifs: Add fallback for SMB2 CREATE without FILE_READ_ATTRIBUTES")Signed-off-by ChenXiaoSong <[email protected]>--- fs/smb/client/smb2file.c | 1 + 1 file changed, 1 insertion(+)fs/smb/client/smb2file.c +1
-1@@ -178,6 +178,7 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, rc =SMB2_open (xid, oparms, smb2_path, &smb2_oplock, smb2_data,NULL , &err_iov, &err_buftype);if (rc == -EACCES && retry_without_read_attributes) { +free_rsp_buf (err_buftype, err_iov.iov_base); oparms->desired_access &= ~FILE_READ_ATTRIBUTES ; rc =SMB2_open (xid, oparms, smb2_path, &smb2_oplock, smb2_data,NULL , &err_iov, &err_buftype); --Quoted 2 lines
2.52.0
--
Thanks,Steve
Signature · 3 lines
Thanks, Steve
Quoted 35 lines · [email protected] writes:
From: ChenXiaoSong <[email protected]>
Reproducer:
1. On server, set the permissions of the shared directory to read-only
2. mount -t cifs //${server_ip}/export /mnt
4. dd if=/dev/zero of=/mnt/file bs=512 count=1000 oflag=direct
5. umount /mnt
6. sleep 1
7. modprobe -r cifsThe error message is as follows:
=============================================================================
BUGcifs_small_rq(Not tainted): Objects remaining on__kmem_cache_shutdown()
-----------------------------------------------------------------------------Object
0x00000000d47521be@offset=14336
...WARNING: mm/slub.c:1251 at __kmem_cache_shutdown+0x34e/0x440, CPU#0: modprobe/1577 ... Call Trace: <TASK> kmem_cache_destroy+0x94/0x190 cifs_destroy_request_bufs+0x3e/0x50 [cifs] cleanup_module+0x4e/0x540 [cifs] __se_sys_delete_module+0x278/0x400 __x64_sys_delete_module+0x5f/0x70 x64_sys_call+0x2299/0x2ff0 do_syscall_64+0x89/0x350 entry_SYSCALL_64_after_hwframe+0x76/0x7e ... kmem_cache_destroy cifs_small_rq: Slab cache still has objects when called from cifs_destroy_request_bufs+0x3e/0x50 [cifs] WARNING: mm/slab_common.c:532 at kmem_cache_destroy+0x16b/0x190, CPU#0: modprobe/1577
Quoted 6 lines
Link https://lore.kernel.org/linux-cifs/[email protected]/T/#mf14808c144448b715f711ce5f0477a071f08eaf6 open hereFixes e255612b5ed9 ("cifs: Add fallback for SMB2 CREATE without FILE_READ_ATTRIBUTES")Signed-off-by ChenXiaoSong <[email protected]>--- fs/smb/client/smb2file.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/smb2file.c int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, · line 181
Quoted 5 lines · [email protected] wrote:
fs/smb/client/smb2file.c +1
-0@@ -178,6 +178,7 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, rc =SMB2_open (xid, oparms, smb2_path, &smb2_oplock, smb2_data,NULL , &err_iov, &err_buftype);if (rc == -EACCES && retry_without_read_attributes) { +free_rsp_buf (err_buftype, err_iov.iov_base);
Since err_iov is going to get used again, it might be worth NULL'ing the pointer out here.
fs/smb/client/smb2file.c int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, · line 184
Quoted 3 lines
fs/smb/client/smb2file.c +0
-0oparms->desired_access &= ~FILE_READ_ATTRIBUTES ; rc =SMB2_open (xid, oparms, smb2_path, &smb2_oplock, smb2_data,NULL , &err_iov, &err_buftype);
David