Skip to contentSkip to conversation

smb: avoid field overflow warning

PATCH Superseded Arnd Bergmann 3 participants 4 messages Jun 16, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 smb: avoid field overflow warning

From: Arnd Bergmann <[email protected]>

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")
---
 fs/smb/server/smb_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/server/smb_common.c +1 -1
index a7e81067bc991..e3273fa640b07 100644
@@ -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, 1);
 	else
 		out[baselen + 4] = '\0';
 	smbConvertToUTF16((__le16 *)shortname, out, PATH_MAX,
Signature · 1 line
2.39.2
maintainer
#1 lore raw

2023-06-16 18:07 GMT+09:00, Arnd Bergmann <[email protected]>:

Quoted 1 line

From: Arnd Bergmann <[email protected]>

Hi Arnd,

Quoted 28 lines

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")
---
 fs/smb/server/smb_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/server/smb_common.c +0 -0
index a7e81067bc991..e3273fa640b07 100644

fs/smb/server/smb_common.c int ksmbd_extract_shortname(struct ksmbd_conn *conn, · line 540

Quoted 6 lines
fs/smb/server/smb_common.c +1 -1
@@ -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, 1);

Is there any reason to change copy bytes from 4 bytes to 1 byte?

Thanks!

Quoted 7 lines
fs/smb/server/smb_common.c +0 -0
 	else
 		out[baselen + 4] = '\0';

smbConvertToUTF16((__le16 *)shortname, out, PATH_MAX,
--
2.39.2

#2 lore raw
Quoted 33 lines · Namjae Jeon

2023-06-16 18:07 GMT+09:00, Arnd Bergmann <[email protected]>:

Quoted 32 lines

From: Arnd Bergmann <[email protected]>

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")
---
 fs/smb/server/smb_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/server/smb_common.c +0 -0
index a7e81067bc991..e3273fa640b07 100644
@@ -536,7 +536,7 @@ int ksmbd_extract_shortname(struct ksmbd_conn *conn,
 const char *longname,
 	out[baselen + 3] = PERIOD;
 
Quoted 5 lines

fs/smb/server/smb_common.c int ksmbd_extract_shortname(struct ksmbd_conn *conn, const char *longname, · line 539

Quoted 3 lines
fs/smb/server/smb_common.c +1 -1
 	if (dot_present)
-		memcpy(&out[baselen + 4], extension, 4);
+		memcpy(out + baselen + 4, extension, 1);

Is there any reason to change copy bytes from 4 bytes to 1 byte?

No, that was an accident, this patch is wrong.

I have to revisit this one and check if my change actually still works after I change it back to the correct length.

Arnd

maintainer
#3 lore raw

2023-06-16 23:42 GMT+09:00, Arnd Bergmann <[email protected]>:

Quoted 41 lines · Namjae Jeon
Quoted 34 lines

2023-06-16 18:07 GMT+09:00, Arnd Bergmann <[email protected]>:

Quoted 33 lines

From: Arnd Bergmann <[email protected]>

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")
---
 fs/smb/server/smb_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/server/smb_common.c +0 -0
index a7e81067bc991..e3273fa640b07 100644
@@ -536,7 +536,7 @@ int ksmbd_extract_shortname(struct ksmbd_conn *conn,
 const char *longname,
 	out[baselen + 3] = PERIOD;
 
Quoted 5 lines

fs/smb/server/smb_common.c int ksmbd_extract_shortname(struct ksmbd_conn *conn, const char *longname, · line 539

Quoted 3 lines
fs/smb/server/smb_common.c +1 -1
 	if (dot_present)
-		memcpy(&out[baselen + 4], extension, 4);
+		memcpy(out + baselen + 4, extension, 1);

Is there any reason to change copy bytes from 4 bytes to 1 byte?

Quoted 4 lines

No, that was an accident, this patch is wrong.

I have to revisit this one and check if my change actually still works after I change it back to the correct length.

Okay:)
Thanks for your check!

Quoted 3 lines

Arnd