Skip to content

Commit f4be404

Browse files
keesgregkh
authored andcommitted
smb: Work around Clang __bdos() type confusion
[ Upstream commit 8deb05c ] Recent versions of Clang gets confused about the possible size of the "user" allocation, and CONFIG_FORTIFY_SOURCE ends up emitting a warning[1]: repro.c:126:4: warning: call to '__write_overflow_field' declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Wattribute-warning] 126 | __write_overflow_field(p_size_field, size); | ^ for this memset(): int len; __le16 *user; ... len = ses->user_name ? strlen(ses->user_name) : 0; user = kmalloc(2 + (len * 2), GFP_KERNEL); ... if (len) { ... } else { memset(user, '\0', 2); } While Clang works on this bug[2], switch to using a direct assignment, which avoids memset() entirely which both simplifies the code and silences the false positive warning. (Making "len" size_t also silences the warning, but the direct assignment seems better.) Reported-by: Nathan Chancellor <[email protected]> Closes: ClangBuiltLinux/linux#1966 [1] Link: llvm/llvm-project#77813 [2] Cc: Steve French <[email protected]> Cc: Paulo Alcantara <[email protected]> Cc: Ronnie Sahlberg <[email protected]> Cc: Shyam Prasad N <[email protected]> Cc: Tom Talpey <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Steve French <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent e587101 commit f4be404

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/smb/client/cifsencrypt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
572572
len = cifs_strtoUTF16(user, ses->user_name, len, nls_cp);
573573
UniStrupr(user);
574574
} else {
575-
memset(user, '\0', 2);
575+
*(u16 *)user = 0;
576576
}
577577

578578
rc = crypto_shash_update(ses->server->secmech.hmacmd5,

0 commit comments

Comments
 (0)