Skip to contentSkip to conversation

smb: fix invalid username check in smb3_fs_context_parse_param()

PATCH In review Yiqi Sun 2 participants 2 messages Nov 11, 2025

Subsystems (2)
lore
Share & tools
lore

Yiqi Sun

author
#0 lore raw

PATCH 1/1 smb: fix invalid username check in smb3_fs_context_parse_param()

Since the maximum return value of strnlen(..., CIFS_MAX_USERNAME_LEN) is CIFS_MAX_USERNAME_LEN, length check in smb3_fs_context_parse_param() is always FALSE and invalid.

Fix the comparison in if statement.

---
 fs/smb/client/fs_context.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/fs_context.c +1 -1
index 59ccc2229ab3..d2cf1f60416a 100644
@@ -1470,7 +1470,7 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
 			break;
 		}
 
-		if (strnlen(param->string, CIFS_MAX_USERNAME_LEN) >
+		if (strnlen(param->string, CIFS_MAX_USERNAME_LEN) ==
 		    CIFS_MAX_USERNAME_LEN) {
 			pr_warn("username too long\n");
 			goto cifs_parse_mount_err;
Signature · 1 line
2.34.1
#1 lore raw

tentatively applied to for-next pending review and testing

Quoted 29 lines · Yiqi Sun

Since the maximum return value of strnlen(..., CIFS_MAX_USERNAME_LEN) is CIFS_MAX_USERNAME_LEN, length check in smb3_fs_context_parse_param() is always FALSE and invalid.

Fix the comparison in if statement.

---
 fs/smb/client/fs_context.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/fs_context.c +1 -2
index 59ccc2229ab3..d2cf1f60416a 100644
@@ -1470,7 +1470,7 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
                        break;
                }
 
-               if (strnlen(param->string, CIFS_MAX_USERNAME_LEN) >
+               if (strnlen(param->string, CIFS_MAX_USERNAME_LEN) ==
                    CIFS_MAX_USERNAME_LEN) {
                        pr_warn("username too long\n");
                        goto cifs_parse_mount_err;
--

2.34.1

Signature · 3 lines
Thanks,

Steve