Skip to content

Commit 9a5dd61

Browse files
decarvSteve French
authored andcommitted
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. Fixes: c1eb537 ("cifs: allow changing password during remount") Reviewed-by: David Howells <dhowells@redhat.com Signed-off-by: Haoxiang Li <make24@iscas.ac.cn> Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 42f7652 commit 9a5dd61

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fs/smb/client/fs_context.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,8 +920,15 @@ static int smb3_reconfigure(struct fs_context *fc)
920920
else {
921921
kfree_sensitive(ses->password);
922922
ses->password = kstrdup(ctx->password, GFP_KERNEL);
923+
if (!ses->password)
924+
return -ENOMEM;
923925
kfree_sensitive(ses->password2);
924926
ses->password2 = kstrdup(ctx->password2, GFP_KERNEL);
927+
if (!ses->password2) {
928+
kfree_sensitive(ses->password);
929+
ses->password = NULL;
930+
return -ENOMEM;
931+
}
925932
}
926933
STEAL_STRING(cifs_sb, ctx, domainname);
927934
STEAL_STRING(cifs_sb, ctx, nodename);

0 commit comments

Comments
 (0)