Skip to contentSkip to conversation

vboxsf: Use flexible arrays for trailing string member

PATCH Applied Kees Cook 3 participants 5 messages Jul 20, 2023 – Aug 8, 2023

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 vboxsf: Use flexible arrays for trailing string member

The declaration of struct shfl_string used trailing fake flexible arrays for the string member. This was tripping FORTIFY_SOURCE since commit df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3"). Replace the utf8 and utf16 members with actual flexible arrays, drop the unused ucs2 member, and retriain a 2 byte padding to keep the structure size the same.

---
 fs/vboxsf/shfl_hostintf.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/vboxsf/shfl_hostintf.h +3 -3
index aca829062c12..069a019c9247 100644
@@ -68,9 +68,9 @@ struct shfl_string {
 
 	/** UTF-8 or UTF-16 string. Nul terminated. */
 	union {
-		u8 utf8[2];
-		u16 utf16[1];
-		u16 ucs2[1]; /* misnomer, use utf16. */
+		u8 legacy_padding[2];
+		DECLARE_FLEX_ARRAY(u8, utf8);
+		DECLARE_FLEX_ARRAY(u16, utf16);
 	} string;
 };
 VMMDEV_ASSERT_SIZE(shfl_string, 6);
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Kees, Larry,

Quoted 10 lines · Kees Cook

The declaration of struct shfl_string used trailing fake flexible arrays for the string member. This was tripping FORTIFY_SOURCE since commit df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3"). Replace the utf8 and utf16 members with actual flexible arrays, drop the unused ucs2 member, and retriain a 2 byte padding to keep the structure size the same.

Kees, Larry thank you for fixing this while I was on vacation.

The patch looks good to me:

Kees, I'm the vboxsf maintainer and it would be easiest for me if you can include this in a future 6.5 fixes pull-request to Linus if that is possible ?

Regards,

Hans

Quoted 21 lines
---
 fs/vboxsf/shfl_hostintf.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/vboxsf/shfl_hostintf.h +3 -3
index aca829062c12..069a019c9247 100644
@@ -68,9 +68,9 @@ struct shfl_string {
 
 	/** UTF-8 or UTF-16 string. Nul terminated. */
 	union {
-		u8 utf8[2];
-		u16 utf16[1];
-		u16 ucs2[1]; /* misnomer, use utf16. */
+		u8 legacy_padding[2];
+		DECLARE_FLEX_ARRAY(u8, utf8);
+		DECLARE_FLEX_ARRAY(u16, utf16);
 	} string;
 };
 VMMDEV_ASSERT_SIZE(shfl_string, 6);
author Applied
#2 lore raw
In reply to Kees Cook
Quoted 8 lines · Kees Cook

The declaration of struct shfl_string used trailing fake flexible arrays for the string member. This was tripping FORTIFY_SOURCE since commit df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3"). Replace the utf8 and utf16 members with actual flexible arrays, drop the unused ucs2 member, and retriain a 2 byte padding to keep the structure size the same.

[...]

Applied to for-linus/hardening, thanks!

[1/1] vboxsf: Use flexible arrays for trailing string member

      https://git.kernel.org/kees/c/a8f014ec6a21

Best regards,

Signature · 1 line
Kees Cook
author
#4 lore raw
In reply to Larry Finger
Quoted 12 lines · Larry Finger
Quoted 11 lines · Kees Cook
Quoted 8 lines · Kees Cook

The declaration of struct shfl_string used trailing fake flexible arrays for the string member. This was tripping FORTIFY_SOURCE since commit df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3"). Replace the utf8 and utf16 members with actual flexible arrays, drop the unused ucs2 member, and retriain a 2 byte padding to keep the structure size the same.

[...]

Quoted 8 lines
Quoted 4 lines

Applied to for-linus/hardening, thanks!

[1/1] vboxsf: Use flexible arrays for trailing string member

       https://git.kernel.org/kees/c/a8f014ec6a21

Kees,

This patch has not been applied to kernel 6.5-rc5. Is there some problem?

Hi! Sorry, I was waiting for linux-next testing, and then got distracted on Friday. I will send the PR to Linus today.

Thanks for the poke!

-Kees

Signature · 1 line
Kees Cook
#3 lore raw
In reply to Kees Cook
Quoted 9 lines · Kees Cook
Quoted 7 lines · Kees Cook

The declaration of struct shfl_string used trailing fake flexible arrays for the string member. This was tripping FORTIFY_SOURCE since commit df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3"). Replace the utf8 and utf16 members with actual flexible arrays, drop the unused ucs2 member, and retriain a 2 byte padding to keep the structure size the same.

Quoted 6 lines
Quoted 1 line

[...]

Applied to for-linus/hardening, thanks!

[1/1] vboxsf: Use flexible arrays for trailing string member

       https://git.kernel.org/kees/c/a8f014ec6a21

Kees,

This patch has not been applied to kernel 6.5-rc5. Is there some problem?

Larry