Skip to content

Commit 962a991

Browse files
Bharath VedarthamDominique Martinet
authored andcommitted
9p/cache.c: Fix memory leak in v9fs_cache_session_get_cookie
v9fs_cache_session_get_cookie assigns a random cachetag to v9ses->cachetag, if the cachetag is not assigned previously. v9fs_random_cachetag allocates memory to v9ses->cachetag with kmalloc and uses scnprintf to fill it up with a cachetag. But if scnprintf fails, v9ses->cachetag is not freed in the current code causing a memory leak. Fix this by freeing v9ses->cachetag it v9fs_random_cachetag fails. This was reported by syzbot, the link to the report is below: https://syzkaller.appspot.com/bug?id=f012bdf297a7a4c860c38a88b44fbee43fd9bbf3 Link: http://lkml.kernel.org/r/20190522194519.GA5313@bharath12345-Inspiron-5559 Reported-by: [email protected] Signed-off-by: Bharath Vedartham <[email protected]> Signed-off-by: Dominique Martinet <[email protected]>
1 parent 0ce772f commit 962a991

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/9p/cache.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses)
5151
if (!v9ses->cachetag) {
5252
if (v9fs_random_cachetag(v9ses) < 0) {
5353
v9ses->fscache = NULL;
54+
kfree(v9ses->cachetag);
55+
v9ses->cachetag = NULL;
5456
return;
5557
}
5658
}

0 commit comments

Comments
 (0)