Skip to contentSkip to conversation

virt: vbox: struct vmmdev_hgcm_pagelist: Replace 1-element array with flexible array

PATCH Applied Kees Cook 2 participants 3 messages Jul 10, 2024 – Aug 22, 2024 Virtual box guest device driver

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 virt: vbox: struct vmmdev_hgcm_pagelist: Replace 1-element array with flexible array

Replace the deprecated[1] use of a 1-element array in
struct vmmdev_hgcm_pagelist with a modern flexible array. As this is UAPI, we cannot trivially change the size of the struct, so use a union to retain the old first element's size, but switch "pages" to a flexible array.

No binary differences are present after this conversion.

---
Cc: Hans de Goede <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: "Gustavo A. R. Silva" <[email protected]>
Cc: [email protected]

---
 include/uapi/linux/vbox_vmmdev_types.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/uapi/linux/vbox_vmmdev_types.h +4 -1
index f8a8d6b3c521..6073858d52a2 100644
@@ -282,7 +282,10 @@ struct vmmdev_hgcm_pagelist {
 	__u32 flags;             /** VMMDEV_HGCM_F_PARM_*. */
 	__u16 offset_first_page; /** Data offset in the first page. */
 	__u16 page_count;        /** Number of pages. */
-	__u64 pages[1];          /** Page addresses. */
+	union {
+		__u64 unused;	/** Deprecated place-holder for first "pages" entry. */
+		__DECLARE_FLEX_ARRAY(__u64, pages); /** Page addresses. */
+	};
 };
 VMMDEV_ASSERT_SIZE(vmmdev_hgcm_pagelist, 4 + 2 + 2 + 8);
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Kees Cook

Replace the deprecated[1] use of a 1-element array in
struct vmmdev_hgcm_pagelist with a modern flexible array. As this is UAPI, we cannot trivially change the size of the struct, so use a union to retain the old first element's size, but switch "pages" to a flexible array.

No binary differences are present after this conversion.

Quoted 8 lines

---
Cc: Hans de Goede <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: "Gustavo A. R. Silva" <[email protected]>
Cc: [email protected]

Thanks
--
Gustavo

Quoted 20 lines
---
  include/uapi/linux/vbox_vmmdev_types.h | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
include/uapi/linux/vbox_vmmdev_types.h +4 -1
index f8a8d6b3c521..6073858d52a2 100644
@@ -282,7 +282,10 @@ struct vmmdev_hgcm_pagelist {
  	__u32 flags;             /** VMMDEV_HGCM_F_PARM_*. */
  	__u16 offset_first_page; /** Data offset in the first page. */
  	__u16 page_count;        /** Number of pages. */
-	__u64 pages[1];          /** Page addresses. */
+	union {
+		__u64 unused;	/** Deprecated place-holder for first "pages" entry. */
+		__DECLARE_FLEX_ARRAY(__u64, pages); /** Page addresses. */
+	};
  };
  VMMDEV_ASSERT_SIZE(vmmdev_hgcm_pagelist, 4 + 2 + 2 + 8);
 
author Applied
#2 lore raw
In reply to Kees Cook
Quoted 9 lines · Kees Cook

Replace the deprecated[1] use of a 1-element array in
struct vmmdev_hgcm_pagelist with a modern flexible array. As this is UAPI, we cannot trivially change the size of the struct, so use a union to retain the old first element's size, but switch "pages" to a flexible array.

No binary differences are present after this conversion.

[...]

Applied to for-next/hardening, thanks!

[1/1] virt: vbox: struct vmmdev_hgcm_pagelist: Replace 1-element array with flexible array

      https://git.kernel.org/kees/c/5ac86f0ed04b

Take care,

Signature · 1 line
Kees Cook