Skip to content

Commit 46617a2

Browse files
z00467499john-cabaj
authored andcommitted
cifs: Fix pages leak when writedata alloc failed in cifs_write_from_iter()
BugLink: https://bugs.launchpad.net/bugs/2036450 There is a kmemleak when writedata alloc failed: unreferenced object 0xffff888175ae4000 (size 4096): comm "dd", pid 19419, jiffies 4296028749 (age 739.396s) hex dump (first 32 bytes): 80 02 b0 04 00 ea ff ff c0 02 b0 04 00 ea ff ff ................ 80 22 4c 04 00 ea ff ff c0 22 4c 04 00 ea ff ff ."L......"L..... backtrace: [<0000000072fdbb86>] __kmalloc_node+0x50/0x150 [<0000000039faf56f>] __iov_iter_get_pages_alloc+0x605/0xdd0 [<00000000f862a9d4>] iov_iter_get_pages_alloc2+0x3b/0x80 [<000000008f226067>] cifs_write_from_iter+0x2ae/0xe40 [<000000001f78f2f1>] __cifs_writev+0x337/0x5c0 [<00000000257fcef5>] vfs_write+0x503/0x690 [<000000008778a238>] ksys_write+0xb9/0x150 [<00000000ed82047c>] do_syscall_64+0x35/0x80 [<000000003365551d>] entry_SYSCALL_64_after_hwframe+0x46/0xb0 __iov_iter_get_pages_alloc+0x605/0xdd0 is: want_pages_array at lib/iov_iter.c:1304 (inlined by) __iov_iter_get_pages_alloc at lib/iov_iter.c:1457 If writedata allocate failed, the pages and pagevec should be cleanup. Fixes: 8c5f9c1 ("CIFS: Add support for direct I/O write") Reviewed-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Zhang Xiaoxu <[email protected]> Signed-off-by: Steve French <[email protected]> (cherry picked from commit f950c85) Signed-off-by: Tim Gardner <[email protected]>
1 parent 2a1cbc8 commit 46617a2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

fs/cifs/file.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3298,6 +3298,9 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from,
32983298
cifs_uncached_writev_complete);
32993299
if (!wdata) {
33003300
rc = -ENOMEM;
3301+
for (i = 0; i < nr_pages; i++)
3302+
put_page(pagevec[i]);
3303+
kvfree(pagevec);
33013304
add_credits_and_wake_if(server, credits, 0);
33023305
break;
33033306
}

0 commit comments

Comments
 (0)