smb/client: fix memory leaks
Subsystems (2)
v2 cover smb/client: fix memory leaks
From: ChenXiaoSong <[email protected]>
v1->v2:
- Add "Reported-by: Paulo Alcantara <[email protected]>"
- Patch #02
- Add "Reviewed-by: Pali Rohár <[email protected]>"
- Update the commit message description
Steve, the patch #02 has already been merged into cifs-2.6.git for-next. Please replace it with the updated version.
For detailed information, please see the link: https://chenxiaosong.com/en/smb-buildbot.html (I will ensure this link is always accessible).
v1:
- smb/client: fix memory leak in SendReceive(): https://lore.kernel.org/linux-cifs/[email protected]/
- smb/client: fix memory leak in smb2_open_file(): https://lore.kernel.org/linux-cifs/[email protected]/
ChenXiaoSong (2):
smb/client: fix memory leak in SendReceive()
smb/client: fix memory leak in smb2_open_file()
fs/smb/client/smb1transport.c | 4 +++- fs/smb/client/smb2file.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
Signature · 1 line
2.52.0
PATCH v2 1/2 smb/client: fix memory leak in SendReceive()
From: ChenXiaoSong <[email protected]>
Reproducer:
1. server: supports SMB1, directories are exported read-only
2. client: mount -t cifs -o vers=1.0 //${server_ip}/export /mnt
3. client: dd if=/dev/zero of=/mnt/file bs=512 count=1000 oflag=direct
4. client: umount /mnt
5. client: sleep 1
6. client: modprobe -r cifs
The error message is as follows:
=============================================================================
BUG cifs_small_rq (Not tainted): Objects remaining on __kmem_cache_shutdown()
-----------------------------------------------------------------------------
Object 0x00000000d34491e6 @offset=896
Object 0x00000000bde9fab3 @offset=4480
Object 0x00000000104a1f70 @offset=6272
Object 0x0000000092a51bb5 @offset=7616
Object 0x000000006714a7db @offset=13440
...
WARNING: mm/slub.c:1251 at __kmem_cache_shutdown+0x379/0x3f0, CPU#7: modprobe/712 ... Call Trace: <TASK> kmem_cache_destroy+0x69/0x160 cifs_destroy_request_bufs+0x39/0x40 [cifs] cleanup_module+0x43/0xfc0 [cifs] __se_sys_delete_module+0x1d5/0x300 __x64_sys_delete_module+0x1a/0x30 x64_sys_call+0x2299/0x2ff0 do_syscall_64+0x6e/0x270 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+0x39/0x40 [cifs] WARNING: mm/slab_common.c:532 at kmem_cache_destroy+0x142/0x160, CPU#7: modprobe/712
--- fs/smb/client/smb1transport.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/smb/client/smb1transport.c +3 -1
@@ -252,13 +252,15 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, rc =cifs_send_recv (xid, ses, ses->server, &rqst, &resp_buf_type, flags, &resp_iov);if (rc <0 ) -return rc; + goto out;if (out_buf) { *pbytes_returned = resp_iov.iov_len;if (resp_iov.iov_len)memcpy (out_buf, resp_iov.iov_base, resp_iov.iov_len); } + +out:free_rsp_buf (resp_buf_type, resp_iov.iov_base);return rc; }
Signature · 1 line
2.52.0
PATCH v2 2/2 smb/client: fix memory leak in smb2_open_file()
In reply to [email protected]From: ChenXiaoSong <[email protected]>
Reproducer:
1. server: directories are exported read-only
2. client: mount -t cifs //${server_ip}/export /mnt
3. client: dd if=/dev/zero of=/mnt/file bs=512 count=1000 oflag=direct
4. client: umount /mnt
5. client: sleep 1
6. client: 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
Re: [PATCH v2 1/2] smb/client: fix memory leak in SendReceive()
In reply to [email protected]merged both into cifs-2.6.git for-next but this smb1 patch has dependencies on other patches for next merge window so might have been better to rebase on mainline so we could send sooner (although that would also require changing at least one other patch in for-next).
Quoted 72 lines · On Mon, Feb 2, 2026 at 2:25 AM <[email protected]> wrote:
From: ChenXiaoSong <[email protected]>
Reproducer:
1. server: supports SMB1, directories are exported read-only
2. client: mount -t cifs -o vers=1.0 //${server_ip}/export /mnt
3. client: dd if=/dev/zero of=/mnt/file bs=512 count=1000 oflag=direct
4. client: umount /mnt
5. client: sleep 1
6. client: modprobe -r cifsThe error message is as follows:
=============================================================================
BUGcifs_small_rq(Not tainted): Objects remaining on__kmem_cache_shutdown()
-----------------------------------------------------------------------------Object
0x00000000d34491e6@offset=896
Object0x00000000bde9fab3@offset=4480
Object0x00000000104a1f70@offset=6272
Object0x0000000092a51bb5@offset=7616
Object0x000000006714a7db@offset=13440
...WARNING: mm/slub.c:1251 at __kmem_cache_shutdown+0x379/0x3f0, CPU#7: modprobe/712 ... Call Trace: <TASK> kmem_cache_destroy+0x69/0x160 cifs_destroy_request_bufs+0x39/0x40 [cifs] cleanup_module+0x43/0xfc0 [cifs] __se_sys_delete_module+0x1d5/0x300 __x64_sys_delete_module+0x1a/0x30 x64_sys_call+0x2299/0x2ff0 do_syscall_64+0x6e/0x270 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+0x39/0x40 [cifs] WARNING: mm/slab_common.c:532 at kmem_cache_destroy+0x142/0x160, CPU#7: modprobe/712Link https://lore.kernel.org/linux-cifs/[email protected]/T/#mf14808c144448b715f711ce5f0477a071f08eaf6 open hereFixes 6be09580df5c ("cifs: Make smb1's SendReceive() wrap cifs_send_recv()")Reported-by Paulo Alcantara <[email protected]>Signed-off-by ChenXiaoSong <[email protected]>--- fs/smb/client/smb1transport.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/smb/client/smb1transport.c +3
-2@@ -252,13 +252,15 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, rc =cifs_send_recv (xid, ses, ses->server, &rqst, &resp_buf_type, flags, &resp_iov);if (rc <0 ) -return rc; + goto out;if (out_buf) { *pbytes_returned = resp_iov.iov_len;if (resp_iov.iov_len)memcpy (out_buf, resp_iov.iov_base, resp_iov.iov_len); } + +out:free_rsp_buf (resp_buf_type, resp_iov.iov_base);return rc; } --2.52.0
Signature · 3 lines
Thanks, Steve
Re: [PATCH v2 1/2] smb/client: fix memory leak in SendReceive()
Should I send new version rebased on mainline? In that case, some of David's patches for the next merge window need further changes.
Thanks,
ChenXiaoSong <[email protected]>
Quoted 4 lines · Steve French
merged both into cifs-2.6.git for-next but this smb1 patch has dependencies on other patches for next merge window so might have been better to rebase on mainline so we could send sooner (although that would also require changing at least one other patch in for-next).