public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] [v2] smb: avoid field overflow warning
@ 2023-06-19  8:19 Arnd Bergmann
  2023-06-19 12:26 ` Tom Talpey
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2023-06-19  8:19 UTC (permalink / raw)
  To: Namjae Jeon, Steve French
  Cc: Arnd Bergmann, Sergey Senozhatsky, Tom Talpey, Nathan Chancellor,
	Nick Desaulniers, Tom Rix, Christian Brauner, Ronnie Sahlberg,
	Hyunchul Lee, linux-cifs, linux-kernel, llvm

From: Arnd Bergmann <arnd@arndb.de>

clang warns about a possible field overflow in a memcpy:

In file included from fs/smb/server/smb_common.c:7:
include/linux/fortify-string.h:583:4: error: call to '__write_overflow_field' declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]
                        __write_overflow_field(p_size_field, size);

It appears to interpret the "&out[baselen + 4]" as referring to a single
byte of the character array, while the equivalen "out + baselen + 4" is
seen as an offset into the array.

I don't see that kind of warning elsewhere, so just go with the simple
rework.

Fixes: e2f34481b24db ("cifsd: add server-side procedures for SMB3")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
----
v2: fix typo in array length, and make sure it still addresses the warning
---
 fs/smb/server/smb_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/smb/server/smb_common.c b/fs/smb/server/smb_common.c
index a7e81067bc991..39c6c8d7d0623 100644
--- a/fs/smb/server/smb_common.c
+++ b/fs/smb/server/smb_common.c
@@ -536,7 +536,7 @@ int ksmbd_extract_shortname(struct ksmbd_conn *conn, const char *longname,
 	out[baselen + 3] = PERIOD;
 
 	if (dot_present)
-		memcpy(&out[baselen + 4], extension, 4);
+		memcpy(out + baselen + 4, extension, 4);
 	else
 		out[baselen + 4] = '\0';
 	smbConvertToUTF16((__le16 *)shortname, out, PATH_MAX,
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] [v2] smb: avoid field overflow warning
  2023-06-19  8:19 [PATCH] [v2] smb: avoid field overflow warning Arnd Bergmann
@ 2023-06-19 12:26 ` Tom Talpey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Talpey @ 2023-06-19 12:26 UTC (permalink / raw)
  To: Arnd Bergmann, Namjae Jeon, Steve French
  Cc: Arnd Bergmann, Sergey Senozhatsky, Nathan Chancellor,
	Nick Desaulniers, Tom Rix, Christian Brauner, Ronnie Sahlberg,
	Hyunchul Lee, linux-cifs, linux-kernel, llvm

On 6/19/2023 4:19 AM, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> clang warns about a possible field overflow in a memcpy:
> 
> In file included from fs/smb/server/smb_common.c:7:
> include/linux/fortify-string.h:583:4: error: call to '__write_overflow_field' declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]
>                          __write_overflow_field(p_size_field, size);
> 
> It appears to interpret the "&out[baselen + 4]" as referring to a single
> byte of the character array, while the equivalen "out + baselen + 4" is
> seen as an offset into the array.
> 
> I don't see that kind of warning elsewhere, so just go with the simple
> rework.
> 
> Fixes: e2f34481b24db ("cifsd: add server-side procedures for SMB3")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ----
> v2: fix typo in array length, and make sure it still addresses the warning
> ---
>   fs/smb/server/smb_common.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/smb/server/smb_common.c b/fs/smb/server/smb_common.c
> index a7e81067bc991..39c6c8d7d0623 100644
> --- a/fs/smb/server/smb_common.c
> +++ b/fs/smb/server/smb_common.c
> @@ -536,7 +536,7 @@ int ksmbd_extract_shortname(struct ksmbd_conn *conn, const char *longname,
>   	out[baselen + 3] = PERIOD;
>   
>   	if (dot_present)
> -		memcpy(&out[baselen + 4], extension, 4);
> +		memcpy(out + baselen + 4, extension, 4);
>   	else
>   		out[baselen + 4] = '\0';
>   	smbConvertToUTF16((__le16 *)shortname, out, PATH_MAX,

It'd be really confusing to have the other two out[baselen + foo] = bar
in the lines above and below.

Can this be fixed more clearly with a new pointer, like
	char *q = &out[baselen + 4];
	memcpy(q, extension, 4);
??

Tom.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-19 12:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-19  8:19 [PATCH] [v2] smb: avoid field overflow warning Arnd Bergmann
2023-06-19 12:26 ` Tom Talpey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox