LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2] 9p/cache.c: Fix memory leak in v9fs_cache_session_get_cookie
@ 2019-05-22 19:45 Bharath Vedartham
  2019-05-22 19:47 ` Dominique Martinet
  0 siblings, 1 reply; 3+ messages in thread
From: Bharath Vedartham @ 2019-05-22 19:45 UTC (permalink / raw)
  To: ericvh, asmadeus, lucho; +Cc: linux-kernel, v9fs-developer, linux.bhar

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

Reported-by: syzbot+3a030a73b6c1e9833815@syzkaller.appspotmail.com
Signed-off-by: Bharath Vedartham <linux.bhar@gmail.com>

---
Changes since v2
	- Made v9ses->cachetag NULL after freeing to avoid any
	  side effects.
---
 fs/9p/cache.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/9p/cache.c b/fs/9p/cache.c
index 9eb3470..baf72da 100644
--- a/fs/9p/cache.c
+++ b/fs/9p/cache.c
@@ -66,6 +66,8 @@ void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses)
 	if (!v9ses->cachetag) {
 		if (v9fs_random_cachetag(v9ses) < 0) {
 			v9ses->fscache = NULL;
+			kfree(v9ses->cachetag);
+			v9ses->cachetag = NULL; 
 			return;
 		}
 	}
-- 
2.7.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] 9p/cache.c: Fix memory leak in v9fs_cache_session_get_cookie
  2019-05-22 19:45 [PATCH v2] 9p/cache.c: Fix memory leak in v9fs_cache_session_get_cookie Bharath Vedartham
@ 2019-05-22 19:47 ` Dominique Martinet
  2019-05-22 19:50   ` Bharath Vedartham
  0 siblings, 1 reply; 3+ messages in thread
From: Dominique Martinet @ 2019-05-22 19:47 UTC (permalink / raw)
  To: Bharath Vedartham; +Cc: ericvh, lucho, linux-kernel, v9fs-developer

Bharath Vedartham wrote on Thu, May 23, 2019:
> 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
> 
> Reported-by: syzbot+3a030a73b6c1e9833815@syzkaller.appspotmail.com
> Signed-off-by: Bharath Vedartham <linux.bhar@gmail.com>


Thanks!

I'm on limited internet right now but will run tests and queue this up tomorrow

-- 
Dominique

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] 9p/cache.c: Fix memory leak in v9fs_cache_session_get_cookie
  2019-05-22 19:47 ` Dominique Martinet
@ 2019-05-22 19:50   ` Bharath Vedartham
  0 siblings, 0 replies; 3+ messages in thread
From: Bharath Vedartham @ 2019-05-22 19:50 UTC (permalink / raw)
  To: Dominique Martinet; +Cc: ericvh, lucho, linux-kernel, v9fs-developer

Cool! Thanks!

Thank you,
Bharath

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-05-22 19:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-22 19:45 [PATCH v2] 9p/cache.c: Fix memory leak in v9fs_cache_session_get_cookie Bharath Vedartham
2019-05-22 19:47 ` Dominique Martinet
2019-05-22 19:50   ` Bharath Vedartham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).