Skip to contentSkip to conversation

gpiolib: annotate struct acpi_gpio_mapping with __counted_by_ptr

PATCH Superseded Bill Wendling 6 participants 20 messages Sep 28 – Nov 9

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: annotate struct acpi_gpio_mapping with __counted_by_ptr

The 'data' pointer field in 'struct acpi_gpio_mapping' is associated with the 'size' field, which represents the number of elements of type 'struct acpi_gpio_params' allocated for 'data'.

To improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, annotate 'data' with the __counted_by_ptr attribute.

Analysis of allocation, assignment, and access points shows that the pointer is never accessed before the count is set, which guarantees that this annotation is safe and will not cause runtime panics or false-positive bounds checks.

---
 include/linux/gpio/consumer.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/gpio/consumer.h +1 -1
index fceeefd5f893..2b80cf7aa7e7 100644
@@ -667,7 +667,7 @@ struct acpi_gpio_params {
 
 struct acpi_gpio_mapping {
 	const char *name;
-	const struct acpi_gpio_params *data;
+	const struct acpi_gpio_params *data __counted_by_ptr(size);
 	unsigned int size;
 
 /* Ignore IoRestriction field */
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#1 lore raw
Quoted 26 lines · Bill Wendling

The 'data' pointer field in 'struct acpi_gpio_mapping' is associated with the 'size' field, which represents the number of elements of type 'struct acpi_gpio_params' allocated for 'data'.

To improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, annotate 'data' with the __counted_by_ptr attribute.

Analysis of allocation, assignment, and access points shows that the pointer is never accessed before the count is set, which guarantees that this annotation is safe and will not cause runtime panics or false-positive bounds checks.

---
 include/linux/gpio/consumer.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/gpio/consumer.h +0 -0
index fceeefd5f893..2b80cf7aa7e7 100644

include/linux/gpio/consumer.h struct acpi_gpio_params { · line 673

Quoted 8 lines
include/linux/gpio/consumer.h +1 -1
@@ -667,7 +667,7 @@ struct acpi_gpio_params {
 
 struct acpi_gpio_mapping {
        const char *name;
-       const struct acpi_gpio_params *data;
+       const struct acpi_gpio_params *data __counted_by_ptr(size);
        unsigned int size;
 
 /* Ignore IoRestriction field */

There's a problem with 'drivers/firmware/efi/libstub/Makefile'. Clang needs a compiler flag to support the "__counted_by_ptr" attribute referencing a field *after* the pointer, like in this patch. However, the Makefile blasts the flag away for x86 platforms. Below is a hack that copies the part of the top-level Makefile that adds the flag. I don't think that's a good solution. The comment in the driver's Makefile says that the stub code executes before the kernel does, which I assume is why a lot of the flags are blown away... In any event, I'm not sure how best to address this.

-bw

(quoted diff) +0 -0

b/drivers/firmware/efi/libstub/Makefile
index 77a2b2d74f3f..945674048d8f 100644

drivers/firmware/efi/libstub/Makefile +8 -1
@@ -19,6 +19,14 @@ cflags-$(CONFIG_X86)         += -m$(BITS)
-D__KERNEL__ $(CC_FLAGS_DIALECT) \
                                   -fno-asynchronous-unwind-tables \
                                   $(CLANG_FLAGS)
 
+ifeq ($(CONFIG_X86_32)$(CONFIG_X86_64),y)
+ifdef CONFIG_CC_IS_CLANG
+ifdef CONFIG_CC_HAS_COUNTED_BY_PTR
+cflags-y                       += -fexperimental-late-parse-attributes
+endif
+endif
+endif
+
 # arm64 uses the full KBUILD_CFLAGS so it's necessary to explicitly
 # disable the stackleak plugin

cflags-$(CONFIG_ARM64) += -fpie $(DISABLE_KSTACK_ERASE) \

maintainer
#2 lore raw
Quoted 34 lines · Bill Wendling
Quoted 33 lines · Bill Wendling

The 'data' pointer field in 'struct acpi_gpio_mapping' is associated with the 'size' field, which represents the number of elements of type 'struct acpi_gpio_params' allocated for 'data'.

To improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, annotate 'data' with the __counted_by_ptr attribute.

Analysis of allocation, assignment, and access points shows that the pointer is never accessed before the count is set, which guarantees that this annotation is safe and will not cause runtime panics or false-positive bounds checks.

---
 include/linux/gpio/consumer.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/gpio/consumer.h +1 -1
index fceeefd5f893..2b80cf7aa7e7 100644
@@ -667,7 +667,7 @@ struct acpi_gpio_params {
 
 struct acpi_gpio_mapping {
        const char *name;
-       const struct acpi_gpio_params *data;
+       const struct acpi_gpio_params *data __counted_by_ptr(size);
        unsigned int size;
 
Quoted 11 lines

include/linux/gpio/consumer.h struct acpi_gpio_params { · line 673

Quoted 1 line
include/linux/gpio/consumer.h +0 -0
 /* Ignore IoRestriction field */

There's a problem with 'drivers/firmware/efi/libstub/Makefile'. Clang needs a compiler flag to support the "__counted_by_ptr" attribute referencing a field *after* the pointer, like in this patch. However, the Makefile blasts the flag away for x86 platforms. Below is a hack that copies the part of the top-level Makefile that adds the flag. I don't think that's a good solution. The comment in the driver's Makefile says that the stub code executes before the kernel does, which I assume is why a lot of the flags are blown away... In any event, I'm not sure how best to address this.

But is this a problem with the current patch?

Does libefistub use <linux/gpio/consumer.h> in any way, shape or form?

Yours,
Linus Walleij

#3 lore raw
Quoted 47 lines · Linus Walleij
Quoted 34 lines · Bill Wendling
Quoted 33 lines · Bill Wendling

The 'data' pointer field in 'struct acpi_gpio_mapping' is associated with the 'size' field, which represents the number of elements of type 'struct acpi_gpio_params' allocated for 'data'.

To improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, annotate 'data' with the __counted_by_ptr attribute.

Analysis of allocation, assignment, and access points shows that the pointer is never accessed before the count is set, which guarantees that this annotation is safe and will not cause runtime panics or false-positive bounds checks.

---
 include/linux/gpio/consumer.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/gpio/consumer.h +1 -1
index fceeefd5f893..2b80cf7aa7e7 100644
@@ -667,7 +667,7 @@ struct acpi_gpio_params {
 
 struct acpi_gpio_mapping {
        const char *name;
-       const struct acpi_gpio_params *data;
+       const struct acpi_gpio_params *data __counted_by_ptr(size);
        unsigned int size;
 
Quoted 11 lines

include/linux/gpio/consumer.h struct acpi_gpio_params { · line 673

Quoted 1 line
include/linux/gpio/consumer.h +0 -0
 /* Ignore IoRestriction field */

There's a problem with 'drivers/firmware/efi/libstub/Makefile'. Clang needs a compiler flag to support the "__counted_by_ptr" attribute referencing a field *after* the pointer, like in this patch. However, the Makefile blasts the flag away for x86 platforms. Below is a hack that copies the part of the top-level Makefile that adds the flag. I don't think that's a good solution. The comment in the driver's Makefile says that the stub code executes before the kernel does, which I assume is why a lot of the flags are blown away... In any event, I'm not sure how best to address this.

Quoted 5 lines

But is this a problem with the current patch?

Does libefistub use <linux/gpio/consumer.h> in any way, shape or form?

It's being #included transitively:

In file included from drivers/firmware/efi/libstub/efi-stub-helper.c:12:
In file included from ./include/linux/efi.h:20:
In file included from ./include/linux/rtc.h:18:
In file included from ./include/linux/nvmem-provider.h:16:
./include/linux/gpio/consumer.h:670:55: error: use of undeclared identifier 'size'; did you
mean 'ksize'?

  670 |         const struct acpi_gpio_params *data __counted_by_ptr(size);
      |                                                              ^~~~
      |                                                              ksize

././include/linux/compiler_types.h:392:64: note: expanded from macro '__counted_by_ptr'
392 | #define __counted_by_ptr(member)
__attribute__((__counted_by__(member)))

      |
       ^~~~~~

./include/linux/slab.h:602:8: note: 'ksize' declared here
602 | size_t ksize(const void *objp);
| ^

Quoted 2 lines

Yours,
Linus Walleij

maintainer
#4 lore raw
Quoted 69 lines · Bill Wendling
Quoted 47 lines · Linus Walleij
Quoted 34 lines · Bill Wendling
Quoted 33 lines · Bill Wendling

The 'data' pointer field in 'struct acpi_gpio_mapping' is associated with the 'size' field, which represents the number of elements of type 'struct acpi_gpio_params' allocated for 'data'.

To improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, annotate 'data' with the __counted_by_ptr attribute.

Analysis of allocation, assignment, and access points shows that the pointer is never accessed before the count is set, which guarantees that this annotation is safe and will not cause runtime panics or false-positive bounds checks.

---
 include/linux/gpio/consumer.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/gpio/consumer.h +1 -1
index fceeefd5f893..2b80cf7aa7e7 100644
@@ -667,7 +667,7 @@ struct acpi_gpio_params {
 
 struct acpi_gpio_mapping {
        const char *name;
-       const struct acpi_gpio_params *data;
+       const struct acpi_gpio_params *data __counted_by_ptr(size);
        unsigned int size;
 
Quoted 11 lines

include/linux/gpio/consumer.h struct acpi_gpio_params { · line 673

Quoted 1 line
include/linux/gpio/consumer.h +0 -0
 /* Ignore IoRestriction field */

There's a problem with 'drivers/firmware/efi/libstub/Makefile'. Clang needs a compiler flag to support the "__counted_by_ptr" attribute referencing a field *after* the pointer, like in this patch. However, the Makefile blasts the flag away for x86 platforms. Below is a hack that copies the part of the top-level Makefile that adds the flag. I don't think that's a good solution. The comment in the driver's Makefile says that the stub code executes before the kernel does, which I assume is why a lot of the flags are blown away... In any event, I'm not sure how best to address this.

Quoted 5 lines

But is this a problem with the current patch?

Does libefistub use <linux/gpio/consumer.h> in any way, shape or form?

It's being #included transitively:

In file included from drivers/firmware/efi/libstub/efi-stub-helper.c:12:
In file included from ./include/linux/efi.h:20:
In file included from ./include/linux/rtc.h:18:
In file included from ./include/linux/nvmem-provider.h:16:
./include/linux/gpio/consumer.h:670:55: error: use of undeclared identifier 'size'; did you
mean 'ksize'?

  670 |         const struct acpi_gpio_params *data __counted_by_ptr(size);
      |                                                              ^~~~
      |                                                              ksize

././include/linux/compiler_types.h:392:64: note: expanded from macro '__counted_by_ptr'
392 | #define __counted_by_ptr(member)
__attribute__((__counted_by__(member)))

Quoted 5 lines
      |
       ^~~~~~

./include/linux/slab.h:602:8: note: 'ksize' declared here
602 | size_t ksize(const void *objp);
| ^

Hm I see.

Certainly Jeremy or Ard will have an idea about how to solve this, so paging them in.

Yours,
Linus Walleij

maintainer
#5 lore raw
Quoted 76 lines · Linus Walleij
Quoted 69 lines · Bill Wendling
Quoted 47 lines · Linus Walleij
Quoted 34 lines · Bill Wendling
Quoted 33 lines · Bill Wendling

The 'data' pointer field in 'struct acpi_gpio_mapping' is associated with the 'size' field, which represents the number of elements of type 'struct acpi_gpio_params' allocated for 'data'.

To improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, annotate 'data' with the __counted_by_ptr attribute.

Analysis of allocation, assignment, and access points shows that the pointer is never accessed before the count is set, which guarantees that this annotation is safe and will not cause runtime panics or false-positive bounds checks.

---
 include/linux/gpio/consumer.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/gpio/consumer.h +1 -1
index fceeefd5f893..2b80cf7aa7e7 100644
@@ -667,7 +667,7 @@ struct acpi_gpio_params {
 
 struct acpi_gpio_mapping {
        const char *name;
-       const struct acpi_gpio_params *data;
+       const struct acpi_gpio_params *data __counted_by_ptr(size);
        unsigned int size;
 
Quoted 11 lines

include/linux/gpio/consumer.h struct acpi_gpio_params { · line 673

Quoted 1 line
include/linux/gpio/consumer.h +0 -0
 /* Ignore IoRestriction field */

There's a problem with 'drivers/firmware/efi/libstub/Makefile'. Clang needs a compiler flag to support the "__counted_by_ptr" attribute referencing a field *after* the pointer, like in this patch. However, the Makefile blasts the flag away for x86 platforms. Below is a hack that copies the part of the top-level Makefile that adds the flag. I don't think that's a good solution. The comment in the driver's Makefile says that the stub code executes before the kernel does, which I assume is why a lot of the flags are blown away... In any event, I'm not sure how best to address this.

Quoted 5 lines

But is this a problem with the current patch?

Does libefistub use <linux/gpio/consumer.h> in any way, shape or form?

It's being #included transitively:

In file included from drivers/firmware/efi/libstub/efi-stub-helper.c:12:
In file included from ./include/linux/efi.h:20:
In file included from ./include/linux/rtc.h:18:
In file included from ./include/linux/nvmem-provider.h:16:
./include/linux/gpio/consumer.h:670:55: error: use of undeclared identifier 'size'; did you
mean 'ksize'?

  670 |         const struct acpi_gpio_params *data __counted_by_ptr(size);
      |                                                              ^~~~
      |                                                              ksize

././include/linux/compiler_types.h:392:64: note: expanded from macro '__counted_by_ptr'
392 | #define __counted_by_ptr(member)
__attribute__((__counted_by__(member)))

Quoted 5 lines
      |
       ^~~~~~

./include/linux/slab.h:602:8: note: 'ksize' declared here
602 | size_t ksize(const void *objp);
| ^

Quoted 5 lines

Hm I see.

Certainly Jeremy or Ard will have an idea about how to solve this, so paging them in.

libstub code never executes in the context of the kernel, but only in the context of the boot firmware. Generally, we disable instrumentation there that has a significant runtime component, basically because we cannot crash or panic the kernel before we have even booted it.

Can we just #define __counted_by_ptr(...) to nothing when building from that Makefile?

#15 lore raw

PATCH v2 1/1 gpiolib: annotate struct acpi_gpio_mapping with __counted_by_ptr

In reply to Bill Wendling

The 'data' pointer field in 'struct acpi_gpio_mapping' is associated with the 'size' field, which represents the number of elements of type 'struct acpi_gpio_params' allocated for 'data'.

To improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, annotate 'data' with the __counted_by_ptr attribute.

Analysis of allocation, assignment, and access points shows that the pointer is never accessed before the count is set, which guarantees that this annotation is safe and will not cause runtime panics or false-positive bounds checks.

---
v2: Undefine "__counted_by" and "__counted_by_ptr" in the EFI stub
library as it doesn't need it and Clang is missing a flag to enable them.

---
 drivers/firmware/efi/libstub/alignedmem.c      | 8 ++++++++
 drivers/firmware/efi/libstub/efi-stub-helper.c | 8 ++++++++
 drivers/firmware/efi/libstub/file.c            | 8 ++++++++
 drivers/firmware/efi/libstub/gop.c             | 8 ++++++++
 drivers/firmware/efi/libstub/mem.c             | 8 ++++++++
 drivers/firmware/efi/libstub/pci.c             | 8 ++++++++
 drivers/firmware/efi/libstub/printk.c          | 8 ++++++++
 drivers/firmware/efi/libstub/random.c          | 8 ++++++++
 drivers/firmware/efi/libstub/randomalloc.c     | 8 ++++++++
 drivers/firmware/efi/libstub/secureboot.c      | 9 +++++++++
 drivers/firmware/efi/libstub/smbios.c          | 8 ++++++++
 drivers/firmware/efi/libstub/tpm.c             | 9 +++++++++
 drivers/firmware/efi/libstub/x86-5lvl.c        | 9 +++++++++
 drivers/firmware/efi/libstub/x86-stub.c        | 8 ++++++++
 include/linux/gpio/consumer.h                  | 2 +-
 15 files changed, 116 insertions(+), 1 deletion(-)
drivers/firmware/efi/libstub/alignedmem.c +8 -0
index 31928bd87e0f..36248a13f15b 100644
@@ -1,5 +1,13 @@
 // SPDX-License-Identifier: GPL-2.0
 
+/*
+ * The EFI stub doesn't execute in the context of the kernel, only in the
+ * context of boot firmware, which isn't the time or place to crash the kernel.
+ * Therefore, disable the __counted_by__ attribute.
+ */
+#undef __counted_by
+#undef __counted_by_ptr
+
 #include <linux/efi.h>
 #include <asm/efi.h>
 
drivers/firmware/efi/libstub/efi-stub-helper.c +8 -0
index 8e43eb3f418b..a97d086a76a1 100644
@@ -7,6 +7,14 @@
  * Copyright 2011 Intel Corporation; author Matt Fleming
  */
 
+/*
+ * The EFI stub doesn't execute in the context of the kernel, only in the
+ * context of boot firmware, which isn't the time or place to crash the kernel.
+ * Therefore, disable the __counted_by__ attribute.
+ */
+#undef __counted_by
+#undef __counted_by_ptr
+
 #include <linux/stdarg.h>
 
 #include <linux/efi.h>
drivers/firmware/efi/libstub/file.c +8 -0
index b2601e284695..e845dc2e7aa0 100644
@@ -7,6 +7,14 @@
  * Copyright 2011 Intel Corporation; author Matt Fleming
  */
 
+/*
+ * The EFI stub doesn't execute in the context of the kernel, only in the
+ * context of boot firmware, which isn't the time or place to crash the kernel.
+ * Therefore, disable the __counted_by__ attribute.
+ */
+#undef __counted_by
+#undef __counted_by_ptr
+
 #include <linux/efi.h>
 #include <asm/efi.h>
 
drivers/firmware/efi/libstub/gop.c +8 -0
index b800a6c2290c..f9736d2eff22 100644
@@ -5,6 +5,14 @@
  *
  * ----------------------------------------------------------------------- */
 
+/*
+ * The EFI stub doesn't execute in the context of the kernel, only in the
+ * context of boot firmware, which isn't the time or place to crash the kernel.
+ * Therefore, disable the __counted_by__ attribute.
+ */
+#undef __counted_by
+#undef __counted_by_ptr
+
 #include <linux/bitops.h>
 #include <linux/ctype.h>
 #include <linux/efi.h>
drivers/firmware/efi/libstub/mem.c +8 -0
index fec561e3a792..65bea615420c 100644
@@ -1,5 +1,13 @@
 // SPDX-License-Identifier: GPL-2.0
 
+/*
+ * The EFI stub doesn't execute in the context of the kernel, only in the
+ * context of boot firmware, which isn't the time or place to crash the kernel.
+ * Therefore, disable the __counted_by__ attribute.
+ */
+#undef __counted_by
+#undef __counted_by_ptr
+
 #include <linux/efi.h>
 #include <asm/efi.h>
 
drivers/firmware/efi/libstub/pci.c +8 -0
index 5daa7a0a0e87..a4c9bf67d5e0 100644
@@ -6,6 +6,14 @@
  * Copyright 2019 Google, LLC
  */
 
+/*
+ * The EFI stub doesn't execute in the context of the kernel, only in the
+ * context of boot firmware, which isn't the time or place to crash the kernel.
+ * Therefore, disable the __counted_by__ attribute.
+ */
+#undef __counted_by
+#undef __counted_by_ptr
+
 #include <linux/efi.h>
 #include <linux/pci.h>
 
drivers/firmware/efi/libstub/printk.c +8 -0
index 0a18cfe32528..e2ae89a27b78 100644
@@ -1,5 +1,13 @@
 // SPDX-License-Identifier: GPL-2.0
 
+/*
+ * The EFI stub doesn't execute in the context of the kernel, only in the
+ * context of boot firmware, which isn't the time or place to crash the kernel.
+ * Therefore, disable the __counted_by__ attribute.
+ */
+#undef __counted_by
+#undef __counted_by_ptr
+
 #include <linux/stdarg.h>
 
 #include <linux/ctype.h>
drivers/firmware/efi/libstub/random.c +8 -0
index d63262d36e47..d370f0d79c07 100644
@@ -3,6 +3,14 @@
  * Copyright (C) 2016 Linaro Ltd;  <[email protected]>
  */
 
+/*
+ * The EFI stub doesn't execute in the context of the kernel, only in the
+ * context of boot firmware, which isn't the time or place to crash the kernel.
+ * Therefore, disable the __counted_by__ attribute.
+ */
+#undef __counted_by
+#undef __counted_by_ptr
+
 #include <linux/efi.h>
 #include <asm/efi.h>
 
drivers/firmware/efi/libstub/randomalloc.c +8 -0
index fd80b2f3233a..b09a26aa51e9 100644
@@ -3,6 +3,14 @@
  * Copyright (C) 2016 Linaro Ltd;  <[email protected]>
  */
 
+/*
+ * The EFI stub doesn't execute in the context of the kernel, only in the
+ * context of boot firmware, which isn't the time or place to crash the kernel.
+ * Therefore, disable the __counted_by__ attribute.
+ */
+#undef __counted_by
+#undef __counted_by_ptr
+
 #include <linux/efi.h>
 #include <linux/log2.h>
 #include <asm/efi.h>
drivers/firmware/efi/libstub/secureboot.c +9 -0
index 516f4f0069bd..07c9782e0c44 100644
@@ -7,6 +7,15 @@
  * Copyright (C) 2013 Red Hat, Inc.
  *     Mark Salter <[email protected]>
  */
+
+/*
+ * The EFI stub doesn't execute in the context of the kernel, only in the
+ * context of boot firmware, which isn't the time or place to crash the kernel.
+ * Therefore, disable the __counted_by__ attribute.
+ */
+#undef __counted_by
+#undef __counted_by_ptr
+
 #include <linux/efi.h>
 #include <asm/efi.h>
 
drivers/firmware/efi/libstub/smbios.c +8 -0
index efbbfc3c2c0d..98dc3ee40958 100644
@@ -2,6 +2,14 @@
 // Copyright 2022 Google LLC
 // Author: Ard Biesheuvel <[email protected]>
 
+/*
+ * The EFI stub doesn't execute in the context of the kernel, only in the
+ * context of boot firmware, which isn't the time or place to crash the kernel.
+ * Therefore, disable the __counted_by__ attribute.
+ */
+#undef __counted_by
+#undef __counted_by_ptr
+
 #include <linux/efi.h>
 
 #include "efistub.h"
drivers/firmware/efi/libstub/tpm.c +9 -0
index 73f001114732..27bc0ccc2a2b 100644
@@ -7,6 +7,15 @@
  *     Matthew Garrett <[email protected]>
  *     Thiebaud Weksteen <[email protected]>
  */
+
+/*
+ * The EFI stub doesn't execute in the context of the kernel, only in the
+ * context of boot firmware, which isn't the time or place to crash the kernel.
+ * Therefore, disable the __counted_by__ attribute.
+ */
+#undef __counted_by
+#undef __counted_by_ptr
+
 #include <linux/efi.h>
 #include <linux/tpm_eventlog.h>
 #include <asm/efi.h>
drivers/firmware/efi/libstub/x86-5lvl.c +9 -0
index c3da05c0df8b..3112ab4b2623 100644
@@ -1,4 +1,13 @@
 // SPDX-License-Identifier: GPL-2.0-only
+
+/*
+ * The EFI stub doesn't execute in the context of the kernel, only in the
+ * context of boot firmware, which isn't the time or place to crash the kernel.
+ * Therefore, disable the __counted_by__ attribute.
+ */
+#undef __counted_by
+#undef __counted_by_ptr
+
 #include <linux/efi.h>
 
 #include <asm/boot.h>
drivers/firmware/efi/libstub/x86-stub.c +8 -0
index f4799e29f4cf..77e806c2b016 100644
@@ -6,6 +6,14 @@
  *
  * ----------------------------------------------------------------------- */
 
+/*
+ * The EFI stub doesn't execute in the context of the kernel, only in the
+ * context of boot firmware, which isn't the time or place to crash the kernel.
+ * Therefore, disable the __counted_by__ attribute.
+ */
+#undef __counted_by
+#undef __counted_by_ptr
+
 #include <linux/efi.h>
 #include <linux/pci.h>
 #include <linux/stddef.h>
include/linux/gpio/consumer.h +1 -1
index fceeefd5f893..2b80cf7aa7e7 100644
@@ -667,7 +667,7 @@ struct acpi_gpio_params {
 
 struct acpi_gpio_mapping {
 	const char *name;
-	const struct acpi_gpio_params *data;
+	const struct acpi_gpio_params *data __counted_by_ptr(size);
 	unsigned int size;
 
 /* Ignore IoRestriction field */
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#6 lore raw
In reply to Ard Biesheuvel
Quoted 83 lines · Ard Biesheuvel
Quoted 76 lines · Linus Walleij
Quoted 69 lines · Bill Wendling
Quoted 47 lines · Linus Walleij
Quoted 34 lines · Bill Wendling
Quoted 33 lines · Bill Wendling

The 'data' pointer field in 'struct acpi_gpio_mapping' is associated with the 'size' field, which represents the number of elements of type 'struct acpi_gpio_params' allocated for 'data'.

To improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, annotate 'data' with the __counted_by_ptr attribute.

Analysis of allocation, assignment, and access points shows that the pointer is never accessed before the count is set, which guarantees that this annotation is safe and will not cause runtime panics or false-positive bounds checks.

---
 include/linux/gpio/consumer.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/gpio/consumer.h +1 -1
index fceeefd5f893..2b80cf7aa7e7 100644
@@ -667,7 +667,7 @@ struct acpi_gpio_params {
 
 struct acpi_gpio_mapping {
        const char *name;
-       const struct acpi_gpio_params *data;
+       const struct acpi_gpio_params *data __counted_by_ptr(size);
        unsigned int size;
 
Quoted 11 lines

include/linux/gpio/consumer.h struct acpi_gpio_params { · line 673

Quoted 1 line
include/linux/gpio/consumer.h +0 -0
 /* Ignore IoRestriction field */

There's a problem with 'drivers/firmware/efi/libstub/Makefile'. Clang needs a compiler flag to support the "__counted_by_ptr" attribute referencing a field *after* the pointer, like in this patch. However, the Makefile blasts the flag away for x86 platforms. Below is a hack that copies the part of the top-level Makefile that adds the flag. I don't think that's a good solution. The comment in the driver's Makefile says that the stub code executes before the kernel does, which I assume is why a lot of the flags are blown away... In any event, I'm not sure how best to address this.

Quoted 5 lines

But is this a problem with the current patch?

Does libefistub use <linux/gpio/consumer.h> in any way, shape or form?

It's being #included transitively:

In file included from drivers/firmware/efi/libstub/efi-stub-helper.c:12:
In file included from ./include/linux/efi.h:20:
In file included from ./include/linux/rtc.h:18:
In file included from ./include/linux/nvmem-provider.h:16:
./include/linux/gpio/consumer.h:670:55: error: use of undeclared identifier 'size'; did you
mean 'ksize'?

  670 |         const struct acpi_gpio_params *data __counted_by_ptr(size);
      |                                                              ^~~~
      |                                                              ksize

././include/linux/compiler_types.h:392:64: note: expanded from macro '__counted_by_ptr'
392 | #define __counted_by_ptr(member)
__attribute__((__counted_by__(member)))

Quoted 5 lines
      |
       ^~~~~~

./include/linux/slab.h:602:8: note: 'ksize' declared here
602 | size_t ksize(const void *objp);
| ^

Quoted 5 lines

Hm I see.

Certainly Jeremy or Ard will have an idea about how to solve this, so paging them in.

Quoted 8 lines

libstub code never executes in the context of the kernel, but only in the context of the boot firmware. Generally, we disable instrumentation there that has a significant runtime component, basically because we cannot crash or panic the kernel before we have even booted it.

Can we just #define __counted_by_ptr(...) to nothing when building from that Makefile?

Doing it in the Makefile is tricky, because of how the "c_flags" variable is defined and used. I couldn't find a good way to do it. Instead, I inserted "#undef __counted_by{_ptr}" at the top of the affected files. It's gross. If there's a way I'm missing, please let me know.

-bw

#16 lore raw
In reply to Bill Wendling
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] efi/libstub: incomplete removal of __counted_by attribute --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] efi/libstub: incomplete removal of __counted_by attribute
--

commit db43ca0ac71b2e4fee34adfbd304bb5744b340e2
Author: Bill Wendling <[email protected]>

gpiolib: annotate struct acpi_gpio_mapping with __counted_by_ptr

This commit annotates the data pointer in struct acpi_gpio_mapping with the __counted_by_ptr attribute to improve bounds checking. It also undefines the __counted_by and __counted_by_ptr macros in some of the EFI stub library source files to prevent unsupported bounds-checking instrumentation that could crash the boot firmware.

Quoted 5 lines
drivers/firmware/efi/libstub/alignedmem.c +0 -0
index 31928bd87e0ff..36248a13f15b4 100644

drivers/firmware/efi/libstub/alignedmem.c line 9

Quoted 9 lines
drivers/firmware/efi/libstub/alignedmem.c +7 -0
@@ -1,5 +1,13 @@
 // SPDX-License-Identifier: GPL-2.0
 
+/*
+ * The EFI stub doesn't execute in the context of the kernel, only in the
+ * context of boot firmware, which isn't the time or place to crash the kernel.
+ * Therefore, disable the __counted_by__ attribute.
+ */
+#undef __counted_by
+#undef __counted_by_ptr

[Severity: High]
Are there other EFI stub library files that need these attributes disabled?

The #undef directives appear to be applied to only 14 out of 45 source files in drivers/firmware/efi/libstub/. Architecture-specific EFI stub files for non-x86 platforms (e.g., drivers/firmware/efi/libstub/arm64-stub.c, drivers/firmware/efi/libstub/riscv-stub.c) and generic core files (e.g., drivers/firmware/efi/libstub/vsprintf.c, drivers/firmware/efi/libstub/fdt.c, drivers/firmware/efi/libstub/zboot.c) were not updated.

These files still include <linux/efi.h>, which ultimately pulls in <linux/compiler_attributes.h> and defines the macros globally. Compiling the EFI stub for non-x86 architectures or enabling generic features like zboot could leave the unsupported annotations active, potentially causing build errors or fatal boot-time panics.

Could this be solved by passing -U__counted_by and -U__counted_by_ptr via KBUILD_CFLAGS in drivers/firmware/efi/libstub/Makefile, or by adding the directives to a common header like efistub.h?

Quoted 3 lines
drivers/firmware/efi/libstub/alignedmem.c +1 -0
+
 #include <linux/efi.h>
 #include <asm/efi.h>
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#7 lore raw
In reply to Bill Wendling
Quoted 89 lines · Bill Wendling
Quoted 88 lines · Ard Biesheuvel
Quoted 76 lines · Linus Walleij
Quoted 69 lines · Bill Wendling
Quoted 47 lines · Linus Walleij
Quoted 34 lines · Bill Wendling
Quoted 33 lines · Bill Wendling

The 'data' pointer field in 'struct acpi_gpio_mapping' is associated with the 'size' field, which represents the number of elements of type 'struct acpi_gpio_params' allocated for 'data'.

To improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, annotate 'data' with the __counted_by_ptr attribute.

Analysis of allocation, assignment, and access points shows that the pointer is never accessed before the count is set, which guarantees that this annotation is safe and will not cause runtime panics or false-positive bounds checks.

---
 include/linux/gpio/consumer.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/gpio/consumer.h +1 -1
index fceeefd5f893..2b80cf7aa7e7 100644
@@ -667,7 +667,7 @@ struct acpi_gpio_params {
 
 struct acpi_gpio_mapping {
        const char *name;
-       const struct acpi_gpio_params *data;
+       const struct acpi_gpio_params *data __counted_by_ptr(size);
        unsigned int size;
 
Quoted 11 lines

include/linux/gpio/consumer.h struct acpi_gpio_params { · line 673

Quoted 1 line
include/linux/gpio/consumer.h +0 -0
 /* Ignore IoRestriction field */

There's a problem with 'drivers/firmware/efi/libstub/Makefile'. Clang needs a compiler flag to support the "__counted_by_ptr" attribute referencing a field *after* the pointer, like in this patch. However, the Makefile blasts the flag away for x86 platforms. Below is a hack that copies the part of the top-level Makefile that adds the flag. I don't think that's a good solution. The comment in the driver's Makefile says that the stub code executes before the kernel does, which I assume is why a lot of the flags are blown away... In any event, I'm not sure how best to address this.

Quoted 5 lines

But is this a problem with the current patch?

Does libefistub use <linux/gpio/consumer.h> in any way, shape or form?

It's being #included transitively:

In file included from drivers/firmware/efi/libstub/efi-stub-helper.c:12:
In file included from ./include/linux/efi.h:20:
In file included from ./include/linux/rtc.h:18:
In file included from ./include/linux/nvmem-provider.h:16:
./include/linux/gpio/consumer.h:670:55: error: use of undeclared identifier 'size'; did you
mean 'ksize'?

  670 |         const struct acpi_gpio_params *data __counted_by_ptr(size);
      |                                                              ^~~~
      |                                                              ksize

././include/linux/compiler_types.h:392:64: note: expanded from macro '__counted_by_ptr'
392 | #define __counted_by_ptr(member)
__attribute__((__counted_by__(member)))

Quoted 5 lines
      |
       ^~~~~~

./include/linux/slab.h:602:8: note: 'ksize' declared here
602 | size_t ksize(const void *objp);
| ^

Quoted 5 lines

Hm I see.

Certainly Jeremy or Ard will have an idea about how to solve this, so paging them in.

libstub code never executes in the context of the kernel, but only in the context of the boot firmware. Generally, we disable instrumentation there that has a significant runtime component, basically because we cannot crash or panic the kernel before we have even booted it.

Quoted 9 lines
Quoted 3 lines

Can we just #define __counted_by_ptr(...) to nothing when building from that Makefile?

Doing it in the Makefile is tricky, because of how the "c_flags" variable is defined and used. I couldn't find a good way to do it. Instead, I inserted "#undef __counted_by{_ptr}" at the top of the affected files. It's gross. If there's a way I'm missing, please let me know.

Does that even build?

#8 lore raw
Quoted 93 lines · Ard Biesheuvel
Quoted 92 lines · Bill Wendling
Quoted 91 lines · Ard Biesheuvel
Quoted 76 lines · Linus Walleij
Quoted 69 lines · Bill Wendling
Quoted 47 lines · Linus Walleij
Quoted 34 lines · Bill Wendling
Quoted 33 lines · Bill Wendling

The 'data' pointer field in 'struct acpi_gpio_mapping' is associated with the 'size' field, which represents the number of elements of type 'struct acpi_gpio_params' allocated for 'data'.

To improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, annotate 'data' with the __counted_by_ptr attribute.

Analysis of allocation, assignment, and access points shows that the pointer is never accessed before the count is set, which guarantees that this annotation is safe and will not cause runtime panics or false-positive bounds checks.

---
 include/linux/gpio/consumer.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/gpio/consumer.h +1 -1
index fceeefd5f893..2b80cf7aa7e7 100644
@@ -667,7 +667,7 @@ struct acpi_gpio_params {
 
 struct acpi_gpio_mapping {
        const char *name;
-       const struct acpi_gpio_params *data;
+       const struct acpi_gpio_params *data __counted_by_ptr(size);
        unsigned int size;
 
Quoted 11 lines

include/linux/gpio/consumer.h struct acpi_gpio_params { · line 673

Quoted 1 line
include/linux/gpio/consumer.h +0 -0
 /* Ignore IoRestriction field */

There's a problem with 'drivers/firmware/efi/libstub/Makefile'. Clang needs a compiler flag to support the "__counted_by_ptr" attribute referencing a field *after* the pointer, like in this patch. However, the Makefile blasts the flag away for x86 platforms. Below is a hack that copies the part of the top-level Makefile that adds the flag. I don't think that's a good solution. The comment in the driver's Makefile says that the stub code executes before the kernel does, which I assume is why a lot of the flags are blown away... In any event, I'm not sure how best to address this.

Quoted 5 lines

But is this a problem with the current patch?

Does libefistub use <linux/gpio/consumer.h> in any way, shape or form?

It's being #included transitively:

In file included from drivers/firmware/efi/libstub/efi-stub-helper.c:12:
In file included from ./include/linux/efi.h:20:
In file included from ./include/linux/rtc.h:18:
In file included from ./include/linux/nvmem-provider.h:16:
./include/linux/gpio/consumer.h:670:55: error: use of undeclared identifier 'size'; did you
mean 'ksize'?

  670 |         const struct acpi_gpio_params *data __counted_by_ptr(size);
      |                                                              ^~~~
      |                                                              ksize

././include/linux/compiler_types.h:392:64: note: expanded from macro '__counted_by_ptr'
392 | #define __counted_by_ptr(member)
__attribute__((__counted_by__(member)))

Quoted 5 lines
      |
       ^~~~~~

./include/linux/slab.h:602:8: note: 'ksize' declared here
602 | size_t ksize(const void *objp);
| ^

Quoted 5 lines

Hm I see.

Certainly Jeremy or Ard will have an idea about how to solve this, so paging them in.

libstub code never executes in the context of the kernel, but only in the context of the boot firmware. Generally, we disable instrumentation there that has a significant runtime component, basically because we cannot crash or panic the kernel before we have even booted it.

Can we just #define __counted_by_ptr(...) to nothing when building from that Makefile?

Quoted 8 lines
Quoted 6 lines

Doing it in the Makefile is tricky, because of how the "c_flags" variable is defined and used. I couldn't find a good way to do it. Instead, I inserted "#undef __counted_by{_ptr}" at the top of the affected files. It's gross. If there's a way I'm missing, please let me know.

Does that even build?

It did for me...

Let me look into Sashiko's comments.

-bw

maintainer
#9 lore raw
Quoted 101 lines · Bill Wendling
Quoted 100 lines · Ard Biesheuvel
Quoted 98 lines · Bill Wendling
Quoted 83 lines · Ard Biesheuvel
Quoted 76 lines · Linus Walleij
Quoted 69 lines · Bill Wendling
Quoted 47 lines · Linus Walleij
Quoted 34 lines · Bill Wendling
Quoted 33 lines · Bill Wendling

The 'data' pointer field in 'struct acpi_gpio_mapping' is associated with the 'size' field, which represents the number of elements of type 'struct acpi_gpio_params' allocated for 'data'.

To improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, annotate 'data' with the __counted_by_ptr attribute.

Analysis of allocation, assignment, and access points shows that the pointer is never accessed before the count is set, which guarantees that this annotation is safe and will not cause runtime panics or false-positive bounds checks.

---
 include/linux/gpio/consumer.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/gpio/consumer.h +1 -1
index fceeefd5f893..2b80cf7aa7e7 100644
@@ -667,7 +667,7 @@ struct acpi_gpio_params {
 
 struct acpi_gpio_mapping {
        const char *name;
-       const struct acpi_gpio_params *data;
+       const struct acpi_gpio_params *data __counted_by_ptr(size);
        unsigned int size;
 
Quoted 11 lines

include/linux/gpio/consumer.h struct acpi_gpio_params { · line 673

Quoted 1 line
include/linux/gpio/consumer.h +0 -0
 /* Ignore IoRestriction field */

There's a problem with 'drivers/firmware/efi/libstub/Makefile'. Clang needs a compiler flag to support the "__counted_by_ptr" attribute referencing a field *after* the pointer, like in this patch. However, the Makefile blasts the flag away for x86 platforms. Below is a hack that copies the part of the top-level Makefile that adds the flag. I don't think that's a good solution. The comment in the driver's Makefile says that the stub code executes before the kernel does, which I assume is why a lot of the flags are blown away... In any event, I'm not sure how best to address this.

Quoted 5 lines

But is this a problem with the current patch?

Does libefistub use <linux/gpio/consumer.h> in any way, shape or form?

It's being #included transitively:

In file included from drivers/firmware/efi/libstub/efi-stub-helper.c:12:
In file included from ./include/linux/efi.h:20:
In file included from ./include/linux/rtc.h:18:
In file included from ./include/linux/nvmem-provider.h:16:
./include/linux/gpio/consumer.h:670:55: error: use of undeclared identifier 'size'; did you
mean 'ksize'?

  670 |         const struct acpi_gpio_params *data __counted_by_ptr(size);
      |                                                              ^~~~
      |                                                              ksize

././include/linux/compiler_types.h:392:64: note: expanded from macro '__counted_by_ptr'
392 | #define __counted_by_ptr(member)
__attribute__((__counted_by__(member)))

Quoted 5 lines
      |
       ^~~~~~

./include/linux/slab.h:602:8: note: 'ksize' declared here
602 | size_t ksize(const void *objp);
| ^

Quoted 5 lines

Hm I see.

Certainly Jeremy or Ard will have an idea about how to solve this, so paging them in.

Quoted 8 lines

libstub code never executes in the context of the kernel, but only in the context of the boot firmware. Generally, we disable instrumentation there that has a significant runtime component, basically because we cannot crash or panic the kernel before we have even booted it.

Can we just #define __counted_by_ptr(...) to nothing when building from that Makefile?

Doing it in the Makefile is tricky, because of how the "c_flags" variable is defined and used. I couldn't find a good way to do it. Instead, I inserted "#undef __counted_by{_ptr}" at the top of the affected files. It's gross. If there's a way I'm missing, please let me know.

Quoted 6 lines
Quoted 1 line

Does that even build?

It did for me...

Let me look into Sashiko's comments.

When you #undef __counted_by(), it is passed straight to the compiler rather than being turned into whichever __attribute__(()) it is supposed to resolve to by the preprocessor.

Hence my surprise that it actually builds.

In any case, this should be done in the Makefile or in a header, not in each individual C source file.

#10 lore raw
In reply to Bill Wendling

Hi,

Quoted 1 line · Bill Wendling

On Thu, Oct 1, 2026 at 12:56 PM Linus Walleij <[email protected]> wrote:

<snip>

Quoted 16 lines

It's being #included transitively:

In file included from drivers/firmware/efi/libstub/efi-stub-helper.c:12:
In file included from ./include/linux/efi.h:20:
In file included from ./include/linux/rtc.h:18:
In file included from ./include/linux/nvmem-provider.h:16:
./include/linux/gpio/consumer.h:670:55: error: use of undeclared identifier 'size'; did you
mean 'ksize'?

  670 |         const struct acpi_gpio_params *data __counted_by_ptr(size);
      |                                                              ^~~~
      |                                                              ksize

././include/linux/compiler_types.h:392:64: note: expanded from macro '__counted_by_ptr'
392 | #define __counted_by_ptr(member)
__attribute__((__counted_by__(member)))

Quoted 6 lines
      |
       ^~~~~~

./include/linux/slab.h:602:8: note: 'ksize' declared here
602 | size_t ksize(const void *objp);
| ^

I wonder if we could have a better warning here guiding you towards -fexperimental-late-parse-attributes?

Thanks
Justin

#11 lore raw
Quoted 31 lines · Justin Stitt

Hi,

Quoted 1 line · Bill Wendling

On Thu, Oct 1, 2026 at 12:56 PM Linus Walleij <[email protected]> wrote:

<snip>

Quoted 16 lines

It's being #included transitively:

In file included from drivers/firmware/efi/libstub/efi-stub-helper.c:12:
In file included from ./include/linux/efi.h:20:
In file included from ./include/linux/rtc.h:18:
In file included from ./include/linux/nvmem-provider.h:16:
./include/linux/gpio/consumer.h:670:55: error: use of undeclared identifier 'size'; did you
mean 'ksize'?

  670 |         const struct acpi_gpio_params *data __counted_by_ptr(size);
      |                                                              ^~~~
      |                                                              ksize

././include/linux/compiler_types.h:392:64: note: expanded from macro '__counted_by_ptr'
392 | #define __counted_by_ptr(member)
__attribute__((__counted_by__(member)))

Quoted 6 lines
      |
       ^~~~~~

./include/linux/slab.h:602:8: note: 'ksize' declared here
602 | size_t ksize(const void *objp);
| ^

Quoted 3 lines

I wonder if we could have a better warning here guiding you towards -fexperimental-late-parse-attributes?

I sent a patch to add __NO_COUNTED_BY AND __NO_COUNTED_BY_PTR macros to prevent this. They're similar to __NO_FORTIFY.

https://lore.kernel.org/all/[email protected]/

-bw

maintainer
#12 lore raw
Quoted 4 lines · Bill Wendling

I sent a patch to add __NO_COUNTED_BY AND __NO_COUNTED_BY_PTR macros to prevent this. They're similar to __NO_FORTIFY.

https://lore.kernel.org/all/[email protected]/

I see you are hashing this out with the right people, thanks for going the extra mile and fixing this properly!

Yours,
Linus Walleij

#13 lore raw
Quoted 11 lines · Linus Walleij
Quoted 4 lines · Bill Wendling

I sent a patch to add __NO_COUNTED_BY AND __NO_COUNTED_BY_PTR macros to prevent this. They're similar to __NO_FORTIFY.

https://lore.kernel.org/all/[email protected]/

I see you are hashing this out with the right people, thanks for going the extra mile and fixing this properly!

Always! :-)

I'll ping this thread once we get the problem solved.

-bw

#14 lore raw
Quoted 8 lines · Bill Wendling
Quoted 6 lines · Linus Walleij
Quoted 3 lines · Bill Wendling

I sent a patch to add __NO_COUNTED_BY AND __NO_COUNTED_BY_PTR macros to prevent this. They're similar to __NO_FORTIFY.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

https://lore.kernel.org/all/[email protected]/

I see you are hashing this out with the right people, thanks for going the extra mile and fixing this properly!

Always! :-)

I'll ping this thread once we get the problem solved.

Hi Linus,

Kees' patch made it in and the original patch now builds. PTAL.

-bw

maintainer Reviewed-by on v1 1/1
#19 lore raw
In reply to Bill Wendling
Quoted 8 lines · Bill Wendling

The 'data' pointer field in 'struct acpi_gpio_mapping' is associated with the 'size' field, which represents the number of elements of type 'struct acpi_gpio_params' allocated for 'data'.

To improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, annotate 'data' with the __counted_by_ptr attribute.

Quoted 8 lines

Analysis of allocation, assignment, and access points shows that the pointer is never accessed before the count is set, which guarantees that this annotation is safe and will not cause runtime panics or false-positive bounds checks.

Prerequisites handled in EFI so:

Yours,
Linus Walleij

#17 lore raw
In reply to Bill Wendling
Quoted 8 lines · Bill Wendling

The 'data' pointer field in 'struct acpi_gpio_mapping' is associated with the 'size' field, which represents the number of elements of type 'struct acpi_gpio_params' allocated for 'data'.

To improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, annotate 'data' with the __counted_by_ptr attribute.

Quoted 7 lines

Analysis of allocation, assignment, and access points shows that the pointer is never accessed before the count is set, which guarantees that this annotation is safe and will not cause runtime panics or false-positive bounds checks.

Assisted-by LLM

This can be dropped now.

Quoted 6 lines

---
v2: Undefine "__counted_by" and "__counted_by_ptr" in the EFI stub
library as it doesn't need it and Clang is missing a flag to enable them.
---

Plase, don't send new versions of patches as replies to previous threads, this confuses tools (and maintainers).

Bart

#18 lore raw
Quoted 15 lines · Bartosz Golaszewski
Quoted 13 lines · Bill Wendling

The 'data' pointer field in 'struct acpi_gpio_mapping' is associated with the 'size' field, which represents the number of elements of type 'struct acpi_gpio_params' allocated for 'data'.

To improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, annotate 'data' with the __counted_by_ptr attribute.

Analysis of allocation, assignment, and access points shows that the pointer is never accessed before the count is set, which guarantees that this annotation is safe and will not cause runtime panics or false-positive bounds checks.

Quoted 5 lines
Quoted 2 lines
Assisted-by LLM

This can be dropped now.

Okay. Do you need me to send a new version?

Quoted 10 lines
Quoted 6 lines

---
v2: Undefine "__counted_by" and "__counted_by_ptr" in the EFI stub
library as it doesn't need it and Clang is missing a flag to enable them.
---

Plase, don't send new versions of patches as replies to previous threads, this confuses tools (and maintainers).

The "v2" is NOT the version that should be integrated. I said the original patch. "v2" was sent as part of the discussion we were having how to solve the issue that cropped up, and not meant to be the defacto version.

-bw