fs: smb: client: Add missing check for kstrdup()
Subsystems (3)
PATCH 1/1 fs: smb: client: Add missing check for kstrdup()
Add check for kstrdup() in smb3_reconfigure in order to guarantee the success of allocation.
--- fs/smb/client/fs_context.c | 2 ++ 1 file changed, 2 insertions(+)
fs/smb/client/fs_context.c +2 -0
@@ -920,6 +920,8 @@ static int smb3_reconfigure(struct fs_context *fc) ses->password =kstrdup (ctx->password,GFP_KERNEL );kfree_sensitive (ses->password2); ses->password2 =kstrdup (ctx->password2,GFP_KERNEL ); +if (!ses->password || !ses->password2) +return ERR_PTR (rc); }STEAL_STRING (cifs_sb, ctx, domainname);STEAL_STRING (cifs_sb, ctx, nodename);
Signature · 1 line
2.25.1
Quoted 1 line
Add check for
kstrdup()insmb3_reconfigurein order to guarantee
checks? calls? ()
Quoted 1 line
the success of allocation.
I suggest to take further patch/code review concerns better into account.
…
Quoted 1 line
Signed-off-by Haoxiang Li <[email protected]>
Will requirements be reconsidered once more for the Developer's Certificate of Origin?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.10-rc6#n398
How do you think about to use a summary phrase like “Complete error handling in smb3_reconfigure()”?
…
fs/smb/client/fs_context.c static int smb3_reconfigure(struct fs_context *fc) · line 925
Quoted 8 lines
+++
b/fs/smb/client/fs_context.cfs/smb/client/fs_context.c +2
-0@@ -920,6 +920,8 @@ static int smb3_reconfigure(struct fs_context *fc) ses->password =kstrdup (ctx->password,GFP_KERNEL );kfree_sensitive (ses->password2); ses->password2 =kstrdup (ctx->password2,GFP_KERNEL ); +if (!ses->password || !ses->password2) +return ERR_PTR (rc); }
…
How do you think about to avoid also a memory leak here?
Regards,
Markus
PATCH v2 1/1 fs_context.c: smb3_reconfigure: Handle kstrdup failures for passwords
In smb3_reconfigure(), after duplicating ctx->password and ctx->password2 with kstrdup(), we need to check for allocation failures.
If ses->password allocation fails, return -ENOMEM. If ses->password2 allocation fails, free ses->password, set it to NULL, and return -ENOMEM.
---
V1 -> V2: Decoupled checks for ses->password and ses->password2. Ensured ses->password is freed and set to NULL if ses->password2 allocation fails. Corrected return value. Improved commit message.
fs/smb/client/fs_context.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/smb/client/fs_context.c +7 -0
@@ -920,8 +920,15 @@ static int smb3_reconfigure(struct fs_context *fc)else {kfree_sensitive (ses->password); ses->password =kstrdup (ctx->password,GFP_KERNEL ); +if (!ses->password) +return -ENOMEM ;kfree_sensitive (ses->password2); ses->password2 =kstrdup (ctx->password2,GFP_KERNEL ); +if (!ses->password2) { +kfree_sensitive (ses->password); + ses->password =NULL ; +return -ENOMEM ; + } }STEAL_STRING (cifs_sb, ctx, domainname);STEAL_STRING (cifs_sb, ctx, nodename);
Signature · 1 line
2.46.0
PATCH v3 1/1 smb: client: Handle kstrdup failures for passwords
In smb3_reconfigure(), after duplicating ctx->password and ctx->password2 with kstrdup(), we need to check for allocation failures.
If ses->password allocation fails, return -ENOMEM. If ses->password2 allocation fails, free ses->password, set it to NULL, and return -ENOMEM.
---
V2 -> V3: Adjust commit subject.
V1 -> V2: Decoupled checks for ses->password and ses->password2. Ensured ses->password is freed and set to NULL if ses->password2 allocation fails. Corrected return value. Improved commit message.
fs/smb/client/fs_context.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/smb/client/fs_context.c +7 -0
@@ -920,8 +920,15 @@ static int smb3_reconfigure(struct fs_context *fc)else {kfree_sensitive (ses->password); ses->password =kstrdup (ctx->password,GFP_KERNEL ); +if (!ses->password) +return -ENOMEM ;kfree_sensitive (ses->password2); ses->password2 =kstrdup (ctx->password2,GFP_KERNEL ); +if (!ses->password2) { +kfree_sensitive (ses->password); + ses->password =NULL ; +return -ENOMEM ; + } }STEAL_STRING (cifs_sb, ctx, domainname);STEAL_STRING (cifs_sb, ctx, nodename);
Signature · 1 line
2.46.0
Re: [PATCH v3] smb: client: Handle kstrdup failures for passwords
tentatively merged into cifs-2.6.git for-next pending review and more testing
Quoted 45 lines · Henrique Carvalho
In
smb3_reconfigure(), after duplicatingctx->passwordandctx->password2withkstrdup(), we need to check for allocation failures.If
ses->passwordallocation fails, return-ENOMEM. Ifses->password2allocation fails, freeses->password, set it to NULL, and return-ENOMEM.Fixes c1eb537bf456 ("cifs: allow changing password during remount")Signed-off-by Haoxiang Li <[email protected]>Signed-off-by Henrique Carvalho <[email protected]>---
V2 -> V3: Adjust commit subject.
V1 -> V2: Decoupled checks forses->passwordandses->password2. Ensuredses->passwordis freed and set to NULL ifses->password2allocation fails. Corrected return value. Improved commit message.fs/smb/client/fs_context.c | 7 +++++++ 1 file changed, 7 insertions(+)fs/smb/client/fs_context.c +7
-1@@ -920,8 +920,15 @@ static int smb3_reconfigure(struct fs_context *fc)else {kfree_sensitive (ses->password); ses->password =kstrdup (ctx->password,GFP_KERNEL ); +if (!ses->password) +return -ENOMEM ;kfree_sensitive (ses->password2); ses->password2 =kstrdup (ctx->password2,GFP_KERNEL ); +if (!ses->password2) { +kfree_sensitive (ses->password); + ses->password =NULL ; +return -ENOMEM ; + } }STEAL_STRING (cifs_sb, ctx, domainname);STEAL_STRING (cifs_sb, ctx, nodename); --2.46.0
Signature · 3 lines
Thanks, Steve
Re: [PATCH v3] smb: client: Handle kstrdup failures for passwords
In reply to Henrique Carvalho…
Quoted 1 line
Signed-off-by Haoxiang Li <[email protected]>
How relevant can such information still be according to requirements for the Developer's Certificate of Origin after different names were presented for such an email address?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.12-rc6#n396
https://lore.kernel.org/linux-kernel/?q=make24%40iscas.ac.cn
Regards,
Markus