LKML Archive on
help / color / mirror / Atom feed
From: Dominique Martinet <>
To: Bharath Vedartham <>
Subject: Re: [PATCH] 9p/cache.c: Fix memory leak in v9fs_cache_session_get_cookie
Date: Wed, 22 May 2019 21:21:29 +0200	[thread overview]
Message-ID: <20190522192129.GA30941@nautica> (raw)
In-Reply-To: <20190522191655.GA4657@bharath12345-Inspiron-5559>

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:
> Reported-by: 
> Signed-off-by: Bharath Vedartham <>
> ---
>  fs/9p/cache.c | 1 +
>  1 file changed, 1 insertion(+)
> diff --git a/fs/9p/cache.c b/fs/9p/cache.c
> index 9eb3470..4463b91 100644
> --- a/fs/9p/cache.c
> +++ b/fs/9p/cache.c
> @@ -66,6 +66,7 @@ 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);

I would also reset v9ses->cachetag to NULL just in case,
v9fs_cache_session_get_cookie will use v9ses->cachetag as it is if it is
not null and you were leaving an invalid pointer there

I do not see any reason it could be called multiple times but
v9fs_cache_session_get_cookie does not return any error (void function)
so something later on could try to use that cachetag incorrectly later


      reply	other threads:[~2019-05-22 20:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-22 19:16 Bharath Vedartham
2019-05-22 19:21 ` Dominique Martinet [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190522192129.GA30941@nautica \ \ \ \ \ \ \
    --subject='Re: [PATCH] 9p/cache.c: Fix memory leak in v9fs_cache_session_get_cookie' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).