Skip to content

Commit

Permalink
xen/gntalloc: Replace UAPI 1-element array
Browse files Browse the repository at this point in the history
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].

Link: KSPP#113 [1]
Cc: Juergen Gross <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Oleksandr Tyshchenko <[email protected]>
Cc: Gustavo A. R. Silva <[email protected]>
Cc: [email protected]
Signed-off-by: Kees Cook <[email protected]>
Reviewed-by: Gustavo A. R. Silva <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Juergen Gross <[email protected]>
  • Loading branch information
kees authored and jgross1 committed Feb 13, 2024
1 parent b0f2f82 commit bf58022
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion drivers/xen/gntalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion include/uapi/xen/gntalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bf58022

Please sign in to comment.