netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [v2] SUNRPC: fix a memleak in gss_import_v2_context
@ 2024-01-12  8:45 Zhipeng Lu
  2024-01-12 13:23 ` Jeff Layton
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Zhipeng Lu @ 2024-01-12  8:45 UTC (permalink / raw)
  To: alexious
  Cc: Chuck Lever, Jeff Layton, Neil Brown, Olga Kornievskaia, Dai Ngo,
	Tom Talpey, Trond Myklebust, Anna Schumaker, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simo Sorce,
	Steve Dickson, Kevin Coffman, linux-nfs, netdev, linux-kernel

The ctx->mech_used.data allocated by kmemdup is not freed in neither
gss_import_v2_context nor it only caller radeon_driver_open_kms.
Thus, this patch reform the last call of gss_import_v2_context to the
gss_krb5_import_ctx_v2, preventing the memleak while keepping the return
formation.

Fixes: 47d848077629 ("gss_krb5: handle new context format from gssd")
Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
---
Changelog:

v2: add non-error case
---
 net/sunrpc/auth_gss/gss_krb5_mech.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/net/sunrpc/auth_gss/gss_krb5_mech.c b/net/sunrpc/auth_gss/gss_krb5_mech.c
index e31cfdf7eadc..5e6f90d73858 100644
--- a/net/sunrpc/auth_gss/gss_krb5_mech.c
+++ b/net/sunrpc/auth_gss/gss_krb5_mech.c
@@ -398,6 +398,7 @@ gss_import_v2_context(const void *p, const void *end, struct krb5_ctx *ctx,
 	u64 seq_send64;
 	int keylen;
 	u32 time32;
+	int ret;
 
 	p = simple_get_bytes(p, end, &ctx->flags, sizeof(ctx->flags));
 	if (IS_ERR(p))
@@ -450,8 +451,16 @@ gss_import_v2_context(const void *p, const void *end, struct krb5_ctx *ctx,
 	}
 	ctx->mech_used.len = gss_kerberos_mech.gm_oid.len;
 
-	return gss_krb5_import_ctx_v2(ctx, gfp_mask);
+	ret = gss_krb5_import_ctx_v2(ctx, gfp_mask);
+	if (ret) {
+		p = ERR_PTR(ret);
+		goto out_free;
+	};
 
+	return 0;
+
+out_free:
+	kfree(ctx->mech_used.data);
 out_err:
 	return PTR_ERR(p);
 }
-- 
2.34.1


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

* Re: [PATCH] [v2] SUNRPC: fix a memleak in gss_import_v2_context
  2024-01-12  8:45 [PATCH] [v2] SUNRPC: fix a memleak in gss_import_v2_context Zhipeng Lu
@ 2024-01-12 13:23 ` Jeff Layton
  2024-01-12 19:24 ` Jakub Kicinski
  2024-01-15 11:09 ` Simon Horman
  2 siblings, 0 replies; 8+ messages in thread
From: Jeff Layton @ 2024-01-12 13:23 UTC (permalink / raw)
  To: Zhipeng Lu
  Cc: Chuck Lever, Neil Brown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
	Trond Myklebust, Anna Schumaker, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simo Sorce, Steve Dickson,
	Kevin Coffman, linux-nfs, netdev, linux-kernel

On Fri, 2024-01-12 at 16:45 +0800, Zhipeng Lu wrote:
> The ctx->mech_used.data allocated by kmemdup is not freed in neither
> gss_import_v2_context nor it only caller radeon_driver_open_kms.


I'm not sure what this has to do with the radeon driver? The changelog
probably needs to be revised.

> Thus, this patch reform the last call of gss_import_v2_context to the
> gss_krb5_import_ctx_v2, preventing the memleak while keepping the return
> formation.
> 
> Fixes: 47d848077629 ("gss_krb5: handle new context format from gssd")
> Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
> ---
> Changelog:
> 
> v2: add non-error case
> ---
>  net/sunrpc/auth_gss/gss_krb5_mech.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/net/sunrpc/auth_gss/gss_krb5_mech.c b/net/sunrpc/auth_gss/gss_krb5_mech.c
> index e31cfdf7eadc..5e6f90d73858 100644
> --- a/net/sunrpc/auth_gss/gss_krb5_mech.c
> +++ b/net/sunrpc/auth_gss/gss_krb5_mech.c
> @@ -398,6 +398,7 @@ gss_import_v2_context(const void *p, const void *end, struct krb5_ctx *ctx,
>  	u64 seq_send64;
>  	int keylen;
>  	u32 time32;
> +	int ret;
>  
>  	p = simple_get_bytes(p, end, &ctx->flags, sizeof(ctx->flags));
>  	if (IS_ERR(p))
> @@ -450,8 +451,16 @@ gss_import_v2_context(const void *p, const void *end, struct krb5_ctx *ctx,
>  	}
>  	ctx->mech_used.len = gss_kerberos_mech.gm_oid.len;
>  
> -	return gss_krb5_import_ctx_v2(ctx, gfp_mask);
> +	ret = gss_krb5_import_ctx_v2(ctx, gfp_mask);
> +	if (ret) {
> +		p = ERR_PTR(ret);
> +		goto out_free;
> +	};
>  
> +	return 0;
> +
> +out_free:
> +	kfree(ctx->mech_used.data);
>  out_err:
>  	return PTR_ERR(p);
>  }

Nice catch!

Reviewed-by: Jeff Layton <jlayton@kernel.org>

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

* Re: [PATCH] [v2] SUNRPC: fix a memleak in gss_import_v2_context
  2024-01-12  8:45 [PATCH] [v2] SUNRPC: fix a memleak in gss_import_v2_context Zhipeng Lu
  2024-01-12 13:23 ` Jeff Layton
@ 2024-01-12 19:24 ` Jakub Kicinski
  2024-01-12 19:27   ` Chuck Lever III
  2024-01-15 11:09 ` Simon Horman
  2 siblings, 1 reply; 8+ messages in thread
From: Jakub Kicinski @ 2024-01-12 19:24 UTC (permalink / raw)
  To: Zhipeng Lu
  Cc: Chuck Lever, Jeff Layton, Neil Brown, Olga Kornievskaia, Dai Ngo,
	Tom Talpey, Trond Myklebust, Anna Schumaker, David S. Miller,
	Eric Dumazet, Paolo Abeni, Simo Sorce, Steve Dickson,
	Kevin Coffman, linux-nfs, netdev, linux-kernel

On Fri, 12 Jan 2024 16:45:38 +0800 Zhipeng Lu wrote:
> +	if (ret) {
> +		p = ERR_PTR(ret);
> +		goto out_free;
> +	};

cocci says:

net/sunrpc/auth_gss/gss_krb5_mech.c:458:2-3: Unneeded semicolon
-- 
pw-bot: nap

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

* Re: [PATCH] [v2] SUNRPC: fix a memleak in gss_import_v2_context
  2024-01-12 19:24 ` Jakub Kicinski
@ 2024-01-12 19:27   ` Chuck Lever III
  2024-01-12 20:01     ` Jakub Kicinski
  0 siblings, 1 reply; 8+ messages in thread
From: Chuck Lever III @ 2024-01-12 19:27 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Zhipeng Lu, Jeff Layton, Neil Brown, Olga Kornievskaia, Dai Ngo,
	Tom Talpey, Trond Myklebust, Anna Schumaker, David S. Miller,
	Eric Dumazet, Paolo Abeni, Simo Sorce, Steve Dickson,
	Kevin Coffman, Linux NFS Mailing List,
	open list:NETWORKING [GENERAL], linux-kernel@vger.kernel.org



> On Jan 12, 2024, at 2:24 PM, Jakub Kicinski <kuba@kernel.org> wrote:
> 
> On Fri, 12 Jan 2024 16:45:38 +0800 Zhipeng Lu wrote:
>> + if (ret) {
>> + p = ERR_PTR(ret);
>> + goto out_free;
>> + };
> 
> cocci says:
> 
> net/sunrpc/auth_gss/gss_krb5_mech.c:458:2-3: Unneeded semicolon

I planned to take this patch via NFSD's "for v6.9" branch.
I can remove that semicolon. Thanks!

--
Chuck Lever



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

* Re: [PATCH] [v2] SUNRPC: fix a memleak in gss_import_v2_context
  2024-01-12 19:27   ` Chuck Lever III
@ 2024-01-12 20:01     ` Jakub Kicinski
  0 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2024-01-12 20:01 UTC (permalink / raw)
  To: Chuck Lever III
  Cc: Zhipeng Lu, Jeff Layton, Neil Brown, Olga Kornievskaia, Dai Ngo,
	Tom Talpey, Trond Myklebust, Anna Schumaker, David S. Miller,
	Eric Dumazet, Paolo Abeni, Simo Sorce, Steve Dickson,
	Kevin Coffman, Linux NFS Mailing List,
	open list:NETWORKING [GENERAL], linux-kernel@vger.kernel.org

On Fri, 12 Jan 2024 19:27:40 +0000 Chuck Lever III wrote:
> > cocci says:
> > 
> > net/sunrpc/auth_gss/gss_krb5_mech.c:458:2-3: Unneeded semicolon  
> 
> I planned to take this patch via NFSD's "for v6.9" branch.
> I can remove that semicolon. Thanks!

Sorry for the lack of clarity, I wasn't intending to take it.
The patch did get into our checking machinery and the warning 
was reported, so I figured why not say so on the list.
I'll mention the intentions more clearly next time!

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

* Re: [PATCH] [v2] SUNRPC: fix a memleak in gss_import_v2_context
  2024-01-12  8:45 [PATCH] [v2] SUNRPC: fix a memleak in gss_import_v2_context Zhipeng Lu
  2024-01-12 13:23 ` Jeff Layton
  2024-01-12 19:24 ` Jakub Kicinski
@ 2024-01-15 11:09 ` Simon Horman
  2024-01-15 14:23   ` Chuck Lever III
  2 siblings, 1 reply; 8+ messages in thread
From: Simon Horman @ 2024-01-15 11:09 UTC (permalink / raw)
  To: Zhipeng Lu
  Cc: Chuck Lever, Jeff Layton, Neil Brown, Olga Kornievskaia, Dai Ngo,
	Tom Talpey, Trond Myklebust, Anna Schumaker, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simo Sorce,
	Steve Dickson, Kevin Coffman, linux-nfs, netdev, linux-kernel

On Fri, Jan 12, 2024 at 04:45:38PM +0800, Zhipeng Lu wrote:
> The ctx->mech_used.data allocated by kmemdup is not freed in neither
> gss_import_v2_context nor it only caller radeon_driver_open_kms.

Should radeon_driver_open_kms be gss_krb5_import_sec_context?

Also, perhaps it is useful to write something like this:

... gss_krb5_import_sec_context, which frees ctx on error.

> Thus, this patch reform the last call of gss_import_v2_context to the
> gss_krb5_import_ctx_v2, preventing the memleak while keepping the return
> formation.
> 
> Fixes: 47d848077629 ("gss_krb5: handle new context format from gssd")
> Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>

Hi Zhipeng Lu,

Other than the comment above, I agree with your analysis.
And that although the problem has changed form slightly,
it was originally introduced by the cited commit.
I also agree that your fix.

...

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

* Re: [PATCH] [v2] SUNRPC: fix a memleak in gss_import_v2_context
  2024-01-15 11:09 ` Simon Horman
@ 2024-01-15 14:23   ` Chuck Lever III
  2024-01-17  7:44     ` alexious
  0 siblings, 1 reply; 8+ messages in thread
From: Chuck Lever III @ 2024-01-15 14:23 UTC (permalink / raw)
  To: Simon Horman, Zhipeng Lu
  Cc: Jeff Layton, Neil Brown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
	Trond Myklebust, Anna Schumaker, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simo Sorce, Steve Dickson,
	Kevin Coffman, Linux NFS Mailing List,
	open list:NETWORKING [GENERAL], Linux Kernel Mailing List



> On Jan 15, 2024, at 6:09 AM, Simon Horman <horms@kernel.org> wrote:
> 
> On Fri, Jan 12, 2024 at 04:45:38PM +0800, Zhipeng Lu wrote:
>> The ctx->mech_used.data allocated by kmemdup is not freed in neither
>> gss_import_v2_context nor it only caller radeon_driver_open_kms.
> 
> Should radeon_driver_open_kms be gss_krb5_import_sec_context?
> 
> Also, perhaps it is useful to write something like this:
> 
> ... gss_krb5_import_sec_context, which frees ctx on error.

If Zhipeng agrees to this suggestion, I can change the
patch description in my tree. A v3 is not necessary.


>> Thus, this patch reform the last call of gss_import_v2_context to the
>> gss_krb5_import_ctx_v2, preventing the memleak while keepping the return
>> formation.
>> 
>> Fixes: 47d848077629 ("gss_krb5: handle new context format from gssd")
>> Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
> 
> Hi Zhipeng Lu,
> 
> Other than the comment above, I agree with your analysis.
> And that although the problem has changed form slightly,
> it was originally introduced by the cited commit.
> I also agree that your fix.
> 
> ...

--
Chuck Lever



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

* Re: Re: [PATCH] [v2] SUNRPC: fix a memleak in gss_import_v2_context
  2024-01-15 14:23   ` Chuck Lever III
@ 2024-01-17  7:44     ` alexious
  0 siblings, 0 replies; 8+ messages in thread
From: alexious @ 2024-01-17  7:44 UTC (permalink / raw)
  To: Chuck Lever III
  Cc: Simon Horman, Jeff Layton, Neil Brown, Olga Kornievskaia, Dai Ngo,
	Tom Talpey, Trond Myklebust, Anna Schumaker, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simo Sorce,
	Steve Dickson, Kevin Coffman, Linux NFS Mailing List,
	open list:NETWORKING [GENERAL], Linux Kernel Mailing List


> > On Jan 15, 2024, at 6:09 AM, Simon Horman <horms@kernel.org> wrote:
> > 
> > On Fri, Jan 12, 2024 at 04:45:38PM +0800, Zhipeng Lu wrote:
> >> The ctx->mech_used.data allocated by kmemdup is not freed in neither
> >> gss_import_v2_context nor it only caller radeon_driver_open_kms.
> > 
> > Should radeon_driver_open_kms be gss_krb5_import_sec_context?
> > 
> > Also, perhaps it is useful to write something like this:
> > 
> > ... gss_krb5_import_sec_context, which frees ctx on error.

Yes, you are right, I proberly mixed up it to another patch :(.
And the first sentence of the patch description should be:

The ctx->mech_used.data allocated by kmemdup is not freed in neither
gss_import_v2_context nor it only caller gss_krb5_import_sec_context, 
which frees ctx on error.

> 
> If Zhipeng agrees to this suggestion, I can change the
> patch description in my tree. A v3 is not necessary.

Yes, I agree with Simon's suggestion and I give the corrected description 
above.

> 
> >> Thus, this patch reform the last call of gss_import_v2_context to the
> >> gss_krb5_import_ctx_v2, preventing the memleak while keepping the return
> >> formation.
> >> 
> >> Fixes: 47d848077629 ("gss_krb5: handle new context format from gssd")
> >> Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
> > 
> > Hi Zhipeng Lu,
> > 
> > Other than the comment above, I agree with your analysis.
> > And that although the problem has changed form slightly,
> > it was originally introduced by the cited commit.
> > I also agree that your fix.
> > 
> > ...
> 
> --
> Chuck Lever
> 
> 

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

end of thread, other threads:[~2024-01-17  7:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-12  8:45 [PATCH] [v2] SUNRPC: fix a memleak in gss_import_v2_context Zhipeng Lu
2024-01-12 13:23 ` Jeff Layton
2024-01-12 19:24 ` Jakub Kicinski
2024-01-12 19:27   ` Chuck Lever III
2024-01-12 20:01     ` Jakub Kicinski
2024-01-15 11:09 ` Simon Horman
2024-01-15 14:23   ` Chuck Lever III
2024-01-17  7:44     ` alexious

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