Skip to content

Commit 67b3da8

Browse files
ChenXiaoSongsmfrench
authored andcommitted
smb/client: fix memory leak in SendReceive()
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 Link: https://lore.kernel.org/linux-cifs/[email protected]/T/#mf14808c144448b715f711ce5f0477a071f08eaf6 Fixes: 6be0958 ("cifs: Make smb1's SendReceive() wrap cifs_send_recv()") Reported-by: Paulo Alcantara <[email protected]> Reviewed-by: Paulo Alcantara (Red Hat) <[email protected]> Reviewed-by: David Howells <[email protected]> Signed-off-by: ChenXiaoSong <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent e3a4363 commit 67b3da8

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

fs/smb/client/cifstransport.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,15 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
251251
rc = cifs_send_recv(xid, ses, ses->server,
252252
&rqst, &resp_buf_type, flags, &resp_iov);
253253
if (rc < 0)
254-
return rc;
254+
goto out;
255255

256256
if (out_buf) {
257257
*pbytes_returned = resp_iov.iov_len;
258258
if (resp_iov.iov_len)
259259
memcpy(out_buf, resp_iov.iov_base, resp_iov.iov_len);
260260
}
261+
262+
out:
261263
free_rsp_buf(resp_buf_type, resp_iov.iov_base);
262264
return rc;
263265
}

0 commit comments

Comments
 (0)