xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libxl/arm: Fix build on arm64 + acpi w/ gcc 8.2
@ 2018-08-14 20:38 Christopher Clark
  2018-08-14 22:16 ` Stefano Stabellini
  2018-08-15  7:21 ` Wei Liu
  0 siblings, 2 replies; 5+ messages in thread
From: Christopher Clark @ 2018-08-14 20:38 UTC (permalink / raw)
  To: xen-devel; +Cc: wei.liu2, julien.grall, sstabellini, ian.jackson

Add zero-padding to #defined ACPI table strings that are copied. 
Provides sufficient characters to satisfy the length required to
fully populate the destination and prevent array-bounds warnings.

Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com>
---

Please add this patch to the backport list for the next minor 4.11
release.

Prior to this: gcc 8.2 objects to memcpy past bounds:

| libxl_arm_acpi.c: In function 'make_acpi_header':
| libxl_arm_acpi.c:208:5: error: 'memcpy' forming offset [5, 6] is out
of the bounds [0, 4] [-Werror=array-bounds]
|      memcpy(h->oem_id, ACPI_OEM_ID, sizeof(h->oem_id));
|      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| libxl_arm_acpi.c:209:5: error: 'memcpy' forming offset [5, 8] is out
of the bounds [0, 4] [-Werror=array-bounds]
|      memcpy(h->oem_table_id, ACPI_OEM_TABLE_ID,
sizeof(h->oem_table_id));
|
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| libxl_arm_acpi.c:211:5: error: 'memcpy' forming offset 4 is out of the
bounds [0, 3] [-Werror=array-bounds]
|      memcpy(h->asl_compiler_id, ACPI_ASL_COMPILER_ID,
|      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|             sizeof(h->asl_compiler_id));
|             ~~~~~~~~~~~~~~~~~~~~~~~~~~~
| In function 'make_acpi_rsdp.isra.4',
|     inlined from 'libxl__prepare_acpi' at libxl_arm_acpi.c:389:5:
| libxl_arm_acpi.c:193:5: error: 'memcpy' forming offset [5, 6] is out
of the bounds [0, 4] [-Werror=array-bounds]
|      memcpy(rsdp->oem_id, ACPI_OEM_ID, sizeof(rsdp->oem_id));
|      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 tools/libxl/libxl_arm_acpi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 636f724..eeca1de 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -48,9 +48,9 @@ extern const unsigned char dsdt_anycpu_arm[];
 _hidden
 extern const int dsdt_anycpu_arm_len;
 
-#define ACPI_OEM_ID "Xen"
-#define ACPI_OEM_TABLE_ID "ARM"
-#define ACPI_ASL_COMPILER_ID "XL"
+#define ACPI_OEM_ID "Xen\0\0"
+#define ACPI_OEM_TABLE_ID "ARM\0\0\0\0"
+#define ACPI_ASL_COMPILER_ID "XL\0"
 
 enum {
     RSDP,
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] libxl/arm: Fix build on arm64 + acpi w/ gcc 8.2
  2018-08-14 20:38 [PATCH] libxl/arm: Fix build on arm64 + acpi w/ gcc 8.2 Christopher Clark
@ 2018-08-14 22:16 ` Stefano Stabellini
  2018-08-15  7:21 ` Wei Liu
  1 sibling, 0 replies; 5+ messages in thread
From: Stefano Stabellini @ 2018-08-14 22:16 UTC (permalink / raw)
  To: Christopher Clark
  Cc: xen-devel, julien.grall, sstabellini, ian.jackson, wei.liu2

On Tue, 14 Aug 2018, Christopher Clark wrote:
> Add zero-padding to #defined ACPI table strings that are copied. 
> Provides sufficient characters to satisfy the length required to
> fully populate the destination and prevent array-bounds warnings.
> 
> Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com>
> ---
> 
> Please add this patch to the backport list for the next minor 4.11
> release.
> 
> Prior to this: gcc 8.2 objects to memcpy past bounds:
> 
> | libxl_arm_acpi.c: In function 'make_acpi_header':
> | libxl_arm_acpi.c:208:5: error: 'memcpy' forming offset [5, 6] is out
> of the bounds [0, 4] [-Werror=array-bounds]
> |      memcpy(h->oem_id, ACPI_OEM_ID, sizeof(h->oem_id));
> |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> | libxl_arm_acpi.c:209:5: error: 'memcpy' forming offset [5, 8] is out
> of the bounds [0, 4] [-Werror=array-bounds]
> |      memcpy(h->oem_table_id, ACPI_OEM_TABLE_ID,
> sizeof(h->oem_table_id));
> |
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> | libxl_arm_acpi.c:211:5: error: 'memcpy' forming offset 4 is out of the
> bounds [0, 3] [-Werror=array-bounds]
> |      memcpy(h->asl_compiler_id, ACPI_ASL_COMPILER_ID,
> |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> |             sizeof(h->asl_compiler_id));
> |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~
> | In function 'make_acpi_rsdp.isra.4',
> |     inlined from 'libxl__prepare_acpi' at libxl_arm_acpi.c:389:5:
> | libxl_arm_acpi.c:193:5: error: 'memcpy' forming offset [5, 6] is out
> of the bounds [0, 4] [-Werror=array-bounds]
> |      memcpy(rsdp->oem_id, ACPI_OEM_ID, sizeof(rsdp->oem_id));
> |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
>  tools/libxl/libxl_arm_acpi.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
> index 636f724..eeca1de 100644
> --- a/tools/libxl/libxl_arm_acpi.c
> +++ b/tools/libxl/libxl_arm_acpi.c
> @@ -48,9 +48,9 @@ extern const unsigned char dsdt_anycpu_arm[];
>  _hidden
>  extern const int dsdt_anycpu_arm_len;
>  
> -#define ACPI_OEM_ID "Xen"
> -#define ACPI_OEM_TABLE_ID "ARM"
> -#define ACPI_ASL_COMPILER_ID "XL"
> +#define ACPI_OEM_ID "Xen\0\0"
> +#define ACPI_OEM_TABLE_ID "ARM\0\0\0\0"
> +#define ACPI_ASL_COMPILER_ID "XL\0"
>  
>  enum {
>      RSDP,

Thank you for the patch! These changes should fix the errors.
Alternatively, changing the three memcpy's in the following way would
also work:

  memcpy(rsdp->oem_id, ACPI_OEM_ID, sizeof(ACPI_OEM_ID));

I don't have an opinion on which way is best so:

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libxl/arm: Fix build on arm64 + acpi w/ gcc 8.2
  2018-08-14 20:38 [PATCH] libxl/arm: Fix build on arm64 + acpi w/ gcc 8.2 Christopher Clark
  2018-08-14 22:16 ` Stefano Stabellini
@ 2018-08-15  7:21 ` Wei Liu
  2018-08-16 20:22   ` [PATCH v2] " Christopher Clark
  1 sibling, 1 reply; 5+ messages in thread
From: Wei Liu @ 2018-08-15  7:21 UTC (permalink / raw)
  To: Christopher Clark
  Cc: xen-devel, julien.grall, sstabellini, ian.jackson, wei.liu2

On Tue, Aug 14, 2018 at 01:38:09PM -0700, Christopher Clark wrote:
> Add zero-padding to #defined ACPI table strings that are copied. 
> Provides sufficient characters to satisfy the length required to
> fully populate the destination and prevent array-bounds warnings.
> 
> Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com>
> ---
> 
> Please add this patch to the backport list for the next minor 4.11
> release.
> 
> Prior to this: gcc 8.2 objects to memcpy past bounds:
> 
> | libxl_arm_acpi.c: In function 'make_acpi_header':
> | libxl_arm_acpi.c:208:5: error: 'memcpy' forming offset [5, 6] is out
> of the bounds [0, 4] [-Werror=array-bounds]
> |      memcpy(h->oem_id, ACPI_OEM_ID, sizeof(h->oem_id));
> |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Please add BUILD_BUG_ON to check the size of oem_id and ACPI_OEM_ID are
actually the same.

> | libxl_arm_acpi.c:209:5: error: 'memcpy' forming offset [5, 8] is out
> of the bounds [0, 4] [-Werror=array-bounds]
> |      memcpy(h->oem_table_id, ACPI_OEM_TABLE_ID,
> sizeof(h->oem_table_id));
> |
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> | libxl_arm_acpi.c:211:5: error: 'memcpy' forming offset 4 is out of the
> bounds [0, 3] [-Werror=array-bounds]
> |      memcpy(h->asl_compiler_id, ACPI_ASL_COMPILER_ID,
> |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> |             sizeof(h->asl_compiler_id));
> |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~
> | In function 'make_acpi_rsdp.isra.4',
> |     inlined from 'libxl__prepare_acpi' at libxl_arm_acpi.c:389:5:
> | libxl_arm_acpi.c:193:5: error: 'memcpy' forming offset [5, 6] is out
> of the bounds [0, 4] [-Werror=array-bounds]
> |      memcpy(rsdp->oem_id, ACPI_OEM_ID, sizeof(rsdp->oem_id));
> |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
>  tools/libxl/libxl_arm_acpi.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
> index 636f724..eeca1de 100644
> --- a/tools/libxl/libxl_arm_acpi.c
> +++ b/tools/libxl/libxl_arm_acpi.c
> @@ -48,9 +48,9 @@ extern const unsigned char dsdt_anycpu_arm[];
>  _hidden
>  extern const int dsdt_anycpu_arm_len;
>  
> -#define ACPI_OEM_ID "Xen"
> -#define ACPI_OEM_TABLE_ID "ARM"
> -#define ACPI_ASL_COMPILER_ID "XL"
> +#define ACPI_OEM_ID "Xen\0\0"
> +#define ACPI_OEM_TABLE_ID "ARM\0\0\0\0"
> +#define ACPI_ASL_COMPILER_ID "XL\0"
>  
>  enum {
>      RSDP,
> -- 
> 2.7.4
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] libxl/arm: Fix build on arm64 + acpi w/ gcc 8.2
  2018-08-15  7:21 ` Wei Liu
@ 2018-08-16 20:22   ` Christopher Clark
  2018-08-17  7:36     ` Wei Liu
  0 siblings, 1 reply; 5+ messages in thread
From: Christopher Clark @ 2018-08-16 20:22 UTC (permalink / raw)
  To: xen-devel; +Cc: wei.liu2, julien.grall, sstabellini, ian.jackson

Add zero-padding to #defined ACPI table strings that are copied.
Provides sufficient characters to satisfy the length required to
fully populate the destination and prevent array-bounds warnings.
Add BUILD_BUG_ON sizeof checks for compile-time length checking.

Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
v2: add BUILD_BUG_ON length checks, requested by Wei.

v1: Please add this patch to the backport list for the next minor
    4.11 release.

Prior to this: gcc 8.2 objects to memcpy past bounds:

| libxl_arm_acpi.c: In function 'make_acpi_header':
| libxl_arm_acpi.c:208:5: error: 'memcpy' forming offset [5, 6] is out
of the bounds [0, 4] [-Werror=array-bounds]
|      memcpy(h->oem_id, ACPI_OEM_ID, sizeof(h->oem_id));
|      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| libxl_arm_acpi.c:209:5: error: 'memcpy' forming offset [5, 8] is out
of the bounds [0, 4] [-Werror=array-bounds]
|      memcpy(h->oem_table_id, ACPI_OEM_TABLE_ID,
sizeof(h->oem_table_id));
|
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| libxl_arm_acpi.c:211:5: error: 'memcpy' forming offset 4 is out of the
bounds [0, 3] [-Werror=array-bounds]
|      memcpy(h->asl_compiler_id, ACPI_ASL_COMPILER_ID,
|      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|             sizeof(h->asl_compiler_id));
|             ~~~~~~~~~~~~~~~~~~~~~~~~~~~
| In function 'make_acpi_rsdp.isra.4',
|     inlined from 'libxl__prepare_acpi' at libxl_arm_acpi.c:389:5:
| libxl_arm_acpi.c:193:5: error: 'memcpy' forming offset [5, 6] is out
of the bounds [0, 4] [-Werror=array-bounds]
|      memcpy(rsdp->oem_id, ACPI_OEM_ID, sizeof(rsdp->oem_id));
|      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 tools/libxl/libxl_arm_acpi.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 636f724..ba874c3 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -48,9 +48,9 @@ extern const unsigned char dsdt_anycpu_arm[];
 _hidden
 extern const int dsdt_anycpu_arm_len;
 
-#define ACPI_OEM_ID "Xen"
-#define ACPI_OEM_TABLE_ID "ARM"
-#define ACPI_ASL_COMPILER_ID "XL"
+#define ACPI_OEM_ID "Xen\0\0"
+#define ACPI_OEM_TABLE_ID "ARM\0\0\0\0"
+#define ACPI_ASL_COMPILER_ID "XL\0"
 
 enum {
     RSDP,
@@ -190,6 +190,7 @@ static void make_acpi_rsdp(libxl__gc *gc, struct xc_dom_image *dom,
     struct acpi_table_rsdp *rsdp = (void *)dom->acpi_modules[0].data + offset;
 
     memcpy(rsdp->signature, "RSD PTR ", sizeof(rsdp->signature));
+    BUILD_BUG_ON(sizeof(ACPI_OEM_ID) != sizeof(rsdp->oem_id));
     memcpy(rsdp->oem_id, ACPI_OEM_ID, sizeof(rsdp->oem_id));
     rsdp->length = acpitables[RSDP].size;
     rsdp->revision = 0x02;
@@ -205,9 +206,12 @@ static void make_acpi_header(struct acpi_table_header *h, const char *sig,
     memcpy(h->signature, sig, 4);
     h->length = len;
     h->revision = rev;
+    BUILD_BUG_ON(sizeof(ACPI_OEM_ID) != sizeof(h->oem_id));
     memcpy(h->oem_id, ACPI_OEM_ID, sizeof(h->oem_id));
+    BUILD_BUG_ON(sizeof(ACPI_OEM_TABLE_ID) != sizeof(h->oem_table_id));
     memcpy(h->oem_table_id, ACPI_OEM_TABLE_ID, sizeof(h->oem_table_id));
     h->oem_revision = 0;
+    BUILD_BUG_ON(sizeof(ACPI_ASL_COMPILER_ID) != sizeof(h->asl_compiler_id));
     memcpy(h->asl_compiler_id, ACPI_ASL_COMPILER_ID,
            sizeof(h->asl_compiler_id));
     h->asl_compiler_revision = 0;
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] libxl/arm: Fix build on arm64 + acpi w/ gcc 8.2
  2018-08-16 20:22   ` [PATCH v2] " Christopher Clark
@ 2018-08-17  7:36     ` Wei Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Wei Liu @ 2018-08-17  7:36 UTC (permalink / raw)
  To: Christopher Clark
  Cc: xen-devel, julien.grall, sstabellini, ian.jackson, wei.liu2

On Thu, Aug 16, 2018 at 01:22:41PM -0700, Christopher Clark wrote:
> Add zero-padding to #defined ACPI table strings that are copied.
> Provides sufficient characters to satisfy the length required to
> fully populate the destination and prevent array-bounds warnings.
> Add BUILD_BUG_ON sizeof checks for compile-time length checking.
> 
> Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com>
> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>

Acked-by: Wei Liu <wei.liu2@citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-08-17  7:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-14 20:38 [PATCH] libxl/arm: Fix build on arm64 + acpi w/ gcc 8.2 Christopher Clark
2018-08-14 22:16 ` Stefano Stabellini
2018-08-15  7:21 ` Wei Liu
2018-08-16 20:22   ` [PATCH v2] " Christopher Clark
2018-08-17  7:36     ` Wei Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).