diff mbox

[V9fs-developer] 9p: fix a potential cachetag leak in v9fs_session_close

Message ID 1481710447-25527-1-git-send-email-liq3ea@gmail.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Li Qiang Dec. 14, 2016, 10:14 a.m. UTC
If the call of fscache_acquire_cookie() function return NULL in
v9fs_cache_session_get_cookie() the 'v9ses->cachetag' will not be
freed, thus leading a memory leak issue. Free it no mattter
'v9ses->fscache' is NULL or not.

Suggested-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Li Qiang <liq3ea@gmail.com>
---
 fs/9p/v9fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Greg Kurz Dec. 14, 2016, 10:50 a.m. UTC | #1
On Wed, 14 Dec 2016 05:14:07 -0500
Li Qiang <liq3ea@gmail.com> wrote:

> If the call of fscache_acquire_cookie() function return NULL in
> v9fs_cache_session_get_cookie() the 'v9ses->cachetag' will not be
> freed, thus leading a memory leak issue. Free it no mattter
> 'v9ses->fscache' is NULL or not.
> 
> Suggested-by: Greg Kurz <groug@kaod.org>
> Signed-off-by: Li Qiang <liq3ea@gmail.com>
> ---

It looks like the v9ses->fscache check is not needed at all,
since v9fs_cache_session_put_cookie() passes it to
fscache_relinquish_cookie() which checks it is not NULL with
fscache_cookie_valid()... also it creates a discrepancy in
that v9fs_cache_session_get_cookie() prints a 'get cookie 0x0'
debug message, but there is no corresponding 'put cookie 0x0'
since v9fs_cache_session_put_cookie() isn't called in this case.

Anyway, this is a different issue that can be addressed in a follow-up
patch and shouldn't not hold up the current fix, so:

Reviewed-by: Greg Kurz <groug@kaod.org>

>  fs/9p/v9fs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
> index fac421a..34c4627 100644
> --- a/fs/9p/v9fs.c
> +++ b/fs/9p/v9fs.c
> @@ -439,9 +439,9 @@ void v9fs_session_close(struct v9fs_session_info *v9ses)
>  	}
>  
>  #ifdef CONFIG_9P_FSCACHE
> +	kfree(v9ses->cachetag);
>  	if (v9ses->fscache) {
>  		v9fs_cache_session_put_cookie(v9ses);
> -		kfree(v9ses->cachetag);
>  	}
>  #endif
>  	kfree(v9ses->uname);


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
diff mbox

Patch

diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
index fac421a..34c4627 100644
--- a/fs/9p/v9fs.c
+++ b/fs/9p/v9fs.c
@@ -439,9 +439,9 @@  void v9fs_session_close(struct v9fs_session_info *v9ses)
 	}
 
 #ifdef CONFIG_9P_FSCACHE
+	kfree(v9ses->cachetag);
 	if (v9ses->fscache) {
 		v9fs_cache_session_put_cookie(v9ses);
-		kfree(v9ses->cachetag);
 	}
 #endif
 	kfree(v9ses->uname);