Skip to content

Commit 4153d78

Browse files
z00467499smfrench
authored andcommitted
cifs: Fix pages array leak when writedata alloc failed in cifs_writedata_alloc()
There is a memory leak when writedata alloc failed: unreferenced object 0xffff888192364000 (size 8192): comm "sync", pid 22839, jiffies 4297313967 (age 60.230s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [<0000000027de0814>] __kmalloc+0x4d/0x150 [<00000000b21e81ab>] cifs_writepages+0x35f/0x14a0 [<0000000076f7d20e>] do_writepages+0x10a/0x360 [<00000000d6a36edc>] filemap_fdatawrite_wbc+0x95/0xc0 [<000000005751a323>] __filemap_fdatawrite_range+0xa7/0xe0 [<0000000088afb0ca>] file_write_and_wait_range+0x66/0xb0 [<0000000063dbc443>] cifs_strict_fsync+0x80/0x5f0 [<00000000c4624754>] __x64_sys_fsync+0x40/0x70 [<000000002c0dc744>] do_syscall_64+0x35/0x80 [<0000000052f46bee>] entry_SYSCALL_64_after_hwframe+0x46/0xb0 cifs_writepages+0x35f/0x14a0 is: kmalloc_array at include/linux/slab.h:628 (inlined by) kcalloc at include/linux/slab.h:659 (inlined by) cifs_writedata_alloc at fs/cifs/file.c:2438 (inlined by) wdata_alloc_and_fillpages at fs/cifs/file.c:2527 (inlined by) cifs_writepages at fs/cifs/file.c:2705 If writedata alloc failed in cifs_writedata_alloc(), the pages array should be freed. Fixes: 8e7360f ("CIFS: Add support for direct pages in wdata") Signed-off-by: Zhang Xiaoxu <[email protected]> Reviewed-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 247f34f commit 4153d78

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

fs/cifs/file.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,12 +2434,16 @@ cifs_writev_complete(struct work_struct *work)
24342434
struct cifs_writedata *
24352435
cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete)
24362436
{
2437+
struct cifs_writedata *writedata = NULL;
24372438
struct page **pages =
24382439
kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS);
2439-
if (pages)
2440-
return cifs_writedata_direct_alloc(pages, complete);
2440+
if (pages) {
2441+
writedata = cifs_writedata_direct_alloc(pages, complete);
2442+
if (!writedata)
2443+
kvfree(pages);
2444+
}
24412445

2442-
return NULL;
2446+
return writedata;
24432447
}
24442448

24452449
struct cifs_writedata *

0 commit comments

Comments
 (0)