Skip to contentSkip to conversation

xen/gntalloc: Replace UAPI 1-element array

PATCH In review Kees Cook 2 participants 2 messages Feb 6, 2024 Xen hypervisor interface

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 xen/gntalloc: Replace UAPI 1-element array

Without changing the structure size (since it is UAPI), add a proper flexible array member, and reference it in the kernel so that it will not be trip the array-bounds sanitizer[1].

Cc Juergen Gross <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Oleksandr Tyshchenko <[email protected]>
Cc Gustavo A. R. Silva <[email protected]>
---
 drivers/xen/gntalloc.c      | 2 +-
 include/uapi/xen/gntalloc.h | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/xen/gntalloc.c +1 -1
index 26ffb8755ffb..f93f73ecefee 100644
@@ -317,7 +317,7 @@ static long gntalloc_ioctl_alloc(struct gntalloc_file_private_data *priv,
 		rc = -EFAULT;
 		goto out_free;
 	}
-	if (copy_to_user(arg->gref_ids, gref_ids,
+	if (copy_to_user(arg->gref_ids_flex, gref_ids,
 			sizeof(gref_ids[0]) * op.count)) {
 		rc = -EFAULT;
 		goto out_free;
include/uapi/xen/gntalloc.h +4 -1
index 48d2790ef928..3109282672f3 100644
@@ -31,7 +31,10 @@ struct ioctl_gntalloc_alloc_gref {
 	__u64 index;
 	/* The grant references of the newly created grant, one per page */
 	/* Variable size, depending on count */
-	__u32 gref_ids[1];
+	union {
+		__u32 gref_ids[1];
+		__DECLARE_FLEX_ARRAY(__u32, gref_ids_flex);
+	};
 };
 
 #define GNTALLOC_FLAG_WRITABLE 1
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Kees Cook

Without changing the structure size (since it is UAPI), add a proper flexible array member, and reference it in the kernel so that it will not be trip the array-bounds sanitizer[1].

Cc Juergen Gross <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Oleksandr Tyshchenko <[email protected]>
Cc Gustavo A. R. Silva <[email protected]>

Thanks!
--
Gustavo

Quoted 34 lines
---
  drivers/xen/gntalloc.c      | 2 +-
  include/uapi/xen/gntalloc.h | 5 ++++-
  2 files changed, 5 insertions(+), 2 deletions(-)
drivers/xen/gntalloc.c +1 -1
index 26ffb8755ffb..f93f73ecefee 100644
@@ -317,7 +317,7 @@ static long gntalloc_ioctl_alloc(struct gntalloc_file_private_data *priv,
  		rc = -EFAULT;
  		goto out_free;
  	}
-	if (copy_to_user(arg->gref_ids, gref_ids,
+	if (copy_to_user(arg->gref_ids_flex, gref_ids,
  			sizeof(gref_ids[0]) * op.count)) {
  		rc = -EFAULT;
  		goto out_free;
include/uapi/xen/gntalloc.h +4 -1
index 48d2790ef928..3109282672f3 100644
@@ -31,7 +31,10 @@ struct ioctl_gntalloc_alloc_gref {
  	__u64 index;
  	/* The grant references of the newly created grant, one per page */
  	/* Variable size, depending on count */
-	__u32 gref_ids[1];
+	union {
+		__u32 gref_ids[1];
+		__DECLARE_FLEX_ARRAY(__u32, gref_ids_flex);
+	};
  };
 
  #define GNTALLOC_FLAG_WRITABLE 1