[PATCH v1 12/19] ACPICA: Introduce ACPI_NONSTRING

Rafael J. Wysocki posted 19 patches 9 months, 3 weeks ago
[PATCH v1 12/19] ACPICA: Introduce ACPI_NONSTRING
Posted by Rafael J. Wysocki 9 months, 3 weeks ago
From: Kees Cook <kees@kernel.org>

ACPICA commit 878823ca20f1987cba0c9d4c1056be0d117ea4fe

In order to distinguish character arrays from C Strings (i.e. strings with
a terminating NUL character), add support for the "nonstring" attribute
provided by GCC. (A better name might be "ACPI_NONCSTRING", but that's
the attribute name, so stick to the existing naming convention.)

GCC 15's -Wunterminated-string-initialization will warn about truncation
of the NUL byte for string initializers unless the destination is marked
with "nonstring". Prepare for applying this attribute to the project.

Link: https://github.com/acpica/acpica/commit/878823ca
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 include/acpi/actypes.h        | 4 ++++
 include/acpi/platform/acgcc.h | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h
index 80767e8bf3ad..f7b3c4a4b7e7 100644
--- a/include/acpi/actypes.h
+++ b/include/acpi/actypes.h
@@ -1327,4 +1327,8 @@ typedef enum {
 #define ACPI_FLEX_ARRAY(TYPE, NAME)     TYPE NAME[0]
 #endif
 
+#ifndef ACPI_NONSTRING
+#define ACPI_NONSTRING		/* No terminating NUL character */
+#endif
+
 #endif				/* __ACTYPES_H__ */
diff --git a/include/acpi/platform/acgcc.h b/include/acpi/platform/acgcc.h
index 04b4bf620517..68e9379623e6 100644
--- a/include/acpi/platform/acgcc.h
+++ b/include/acpi/platform/acgcc.h
@@ -72,4 +72,12 @@
                 TYPE NAME[];                    \
         }
 
+/*
+ * Explicitly mark strings that lack a terminating NUL character so
+ * that ACPICA can be built with -Wunterminated-string-initialization.
+ */
+#if __has_attribute(__nonstring__)
+#define ACPI_NONSTRING __attribute__((__nonstring__))
+#endif
+
 #endif				/* __ACGCC_H__ */
-- 
2.43.0
Re: [PATCH v1 12/19] ACPICA: Introduce ACPI_NONSTRING
Posted by Kees Cook 9 months, 2 weeks ago
On Fri, Apr 25, 2025 at 09:27:58PM +0200, Rafael J. Wysocki wrote:
> From: Kees Cook <kees@kernel.org>
> 
> ACPICA commit 878823ca20f1987cba0c9d4c1056be0d117ea4fe
> 
> In order to distinguish character arrays from C Strings (i.e. strings with
> a terminating NUL character), add support for the "nonstring" attribute
> provided by GCC. (A better name might be "ACPI_NONCSTRING", but that's
> the attribute name, so stick to the existing naming convention.)
> 
> GCC 15's -Wunterminated-string-initialization will warn about truncation
> of the NUL byte for string initializers unless the destination is marked
> with "nonstring". Prepare for applying this attribute to the project.
> 
> Link: https://github.com/acpica/acpica/commit/878823ca
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Whoops, I missed adding my S-o-b to the original upstream ACPICA commit.
Please consider this:

Signed-off-by: Kees Cook <kees@kernel.org>

-- 
Kees Cook
Re: [PATCH v1 12/19] ACPICA: Introduce ACPI_NONSTRING
Posted by Rafael J. Wysocki 9 months, 2 weeks ago
On Wed, Apr 30, 2025 at 8:35 PM Kees Cook <kees@kernel.org> wrote:
>
> On Fri, Apr 25, 2025 at 09:27:58PM +0200, Rafael J. Wysocki wrote:
> > From: Kees Cook <kees@kernel.org>
> >
> > ACPICA commit 878823ca20f1987cba0c9d4c1056be0d117ea4fe
> >
> > In order to distinguish character arrays from C Strings (i.e. strings with
> > a terminating NUL character), add support for the "nonstring" attribute
> > provided by GCC. (A better name might be "ACPI_NONCSTRING", but that's
> > the attribute name, so stick to the existing naming convention.)
> >
> > GCC 15's -Wunterminated-string-initialization will warn about truncation
> > of the NUL byte for string initializers unless the destination is marked
> > with "nonstring". Prepare for applying this attribute to the project.
> >
> > Link: https://github.com/acpica/acpica/commit/878823ca
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Whoops, I missed adding my S-o-b to the original upstream ACPICA commit.
> Please consider this:
>
> Signed-off-by: Kees Cook <kees@kernel.org>

Added, thanks!