2022-12-09 02:21:49

by Konstantin Meskhidze

[permalink] [raw]
Subject: [PATCH] fs: NFSv4.1: Fix memory leakage

This commit fixes potential memory leakage of 'calldata' memory chunk
in _nfs41_proc_sequence() function.

Signed-off-by: Konstantin Meskhidze <[email protected]>
---
fs/nfs/nfs4proc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 86ed5c0142c3..b7aa66167341 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -9416,8 +9416,10 @@ static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp,
task_setup_data.callback_data = calldata;

ret = rpc_run_task(&task_setup_data);
- if (IS_ERR(ret))
+ if (IS_ERR(ret)) {
+ kfree(calldata);
goto out_err;
+ }
return ret;
out_put_clp:
nfs_put_client(clp);
--
2.25.1


2022-12-09 12:41:33

by Benjamin Coddington

[permalink] [raw]
Subject: Re: [PATCH] NFSv4.1: Fix memory leakage

On 8 Dec 2022, at 21:18, Konstantin Meskhidze wrote:

> This commit fixes potential memory leakage of 'calldata' memory chunk
> in _nfs41_proc_sequence() function.
>
> Signed-off-by: Konstantin Meskhidze <[email protected]>
> ---
> fs/nfs/nfs4proc.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
> index 86ed5c0142c3..b7aa66167341 100644
> --- a/fs/nfs/nfs4proc.c
> +++ b/fs/nfs/nfs4proc.c
> @@ -9416,8 +9416,10 @@ static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp,
> task_setup_data.callback_data = calldata;
>
> ret = rpc_run_task(&task_setup_data);
> - if (IS_ERR(ret))
> + if (IS_ERR(ret)) {
> + kfree(calldata);
> goto out_err;
> + }
> return ret;
> out_put_clp:
> nfs_put_client(clp);
> --
> 2.25.1

Did you observe this leak, or find it by code inspecton?

I don't think there's a leak here because there's no way rpc_run_task() can
return an error withouth also doing rpc_call_ops->rpc_release, which should
free the calldata.

Ben

2022-12-09 14:53:56

by Trond Myklebust

[permalink] [raw]
Subject: Re: [PATCH] NFSv4.1: Fix memory leakage



> On Dec 9, 2022, at 07:29, Benjamin Coddington <[email protected]> wrote:
>
> On 8 Dec 2022, at 21:18, Konstantin Meskhidze wrote:
>
>> This commit fixes potential memory leakage of 'calldata' memory chunk
>> in _nfs41_proc_sequence() function.
>>
>> Signed-off-by: Konstantin Meskhidze <[email protected]>
>> ---
>> fs/nfs/nfs4proc.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
>> index 86ed5c0142c3..b7aa66167341 100644
>> --- a/fs/nfs/nfs4proc.c
>> +++ b/fs/nfs/nfs4proc.c
>> @@ -9416,8 +9416,10 @@ static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp,
>> task_setup_data.callback_data = calldata;
>>
>> ret = rpc_run_task(&task_setup_data);
>> - if (IS_ERR(ret))
>> + if (IS_ERR(ret)) {
>> + kfree(calldata);
>> goto out_err;
>> + }
>> return ret;
>> out_put_clp:
>> nfs_put_client(clp);
>> --
>> 2.25.1
>
> Did you observe this leak, or find it by code inspecton?
>
> I don't think there's a leak here because there's no way rpc_run_task() can
> return an error withouth also doing rpc_call_ops->rpc_release, which should
> free the calldata.

Correct. We will not be applying this patch.
_________________________________
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]