* [PATCH] ACPI: tables: Add __nonstring annotations for unterminated strings
@ 2025-04-15 23:20 Kees Cook
2025-04-23 20:04 ` Rafael J. Wysocki
0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2025-04-15 23:20 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Kees Cook, Len Brown, Robert Moore, linux-acpi, acpica-devel,
linux-kernel, linux-hardening
When a character array without a terminating NUL character has a static
initializer, GCC 15's -Wunterminated-string-initialization will only
warn if the array lacks the "nonstring" attribute[1]. Mark the 4-byte
ACPI identifier arrays with __nonstring (and the new __nonstring_array)
to correctly identify the char arrays as "not C strings" and thereby
eliminate the many warnings like this:
In file included from include/acpi/actbl.h:371,
from include/acpi/acpi.h:26,
from include/linux/acpi.h:26,
from drivers/acpi/tables.c:19:
include/acpi/actbl1.h:30:33: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (5 chars into 4 available) [-Wunterminated-string-initialization]
30 | #define ACPI_SIG_BERT "BERT" /* Boot Error Record Table */
| ^~~~~~
drivers/acpi/tables.c:400:9: note: in expansion of macro 'ACPI_SIG_BERT'
400 | ACPI_SIG_BERT, ACPI_SIG_BGRT, ACPI_SIG_CPEP, ACPI_SIG_ECDT,
| ^~~~~~~~~~~~~
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Len Brown <lenb@kernel.org>
Cc: Robert Moore <robert.moore@intel.com>
Cc: linux-acpi@vger.kernel.org
Cc: acpica-devel@lists.linux.dev
---
drivers/acpi/tables.c | 2 +-
include/acpi/actbl.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index 2295abbecd14..0a9ade7117bd 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -396,7 +396,7 @@ static u8 __init acpi_table_checksum(u8 *buffer, u32 length)
}
/* All but ACPI_SIG_RSDP and ACPI_SIG_FACS: */
-static const char table_sigs[][ACPI_NAMESEG_SIZE] __initconst = {
+static const char table_sigs[][ACPI_NAMESEG_SIZE] __nonstring_array __initconst = {
ACPI_SIG_BERT, ACPI_SIG_BGRT, ACPI_SIG_CPEP, ACPI_SIG_ECDT,
ACPI_SIG_EINJ, ACPI_SIG_ERST, ACPI_SIG_HEST, ACPI_SIG_MADT,
ACPI_SIG_MSCT, ACPI_SIG_SBST, ACPI_SIG_SLIT, ACPI_SIG_SRAT,
diff --git a/include/acpi/actbl.h b/include/acpi/actbl.h
index 451f6276da49..2fc89704be17 100644
--- a/include/acpi/actbl.h
+++ b/include/acpi/actbl.h
@@ -66,7 +66,7 @@
******************************************************************************/
struct acpi_table_header {
- char signature[ACPI_NAMESEG_SIZE]; /* ASCII table signature */
+ char signature[ACPI_NAMESEG_SIZE] __nonstring; /* ASCII table signature */
u32 length; /* Length of table in bytes, including this header */
u8 revision; /* ACPI Specification minor version number */
u8 checksum; /* To make sum of entire table == 0 */
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ACPI: tables: Add __nonstring annotations for unterminated strings
2025-04-15 23:20 [PATCH] ACPI: tables: Add __nonstring annotations for unterminated strings Kees Cook
@ 2025-04-23 20:04 ` Rafael J. Wysocki
0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2025-04-23 20:04 UTC (permalink / raw)
To: Kees Cook
Cc: Rafael J. Wysocki, Len Brown, Robert Moore, linux-acpi,
acpica-devel, linux-kernel, linux-hardening
On Wed, Apr 16, 2025 at 1:20 AM Kees Cook <kees@kernel.org> wrote:
>
> When a character array without a terminating NUL character has a static
> initializer, GCC 15's -Wunterminated-string-initialization will only
> warn if the array lacks the "nonstring" attribute[1]. Mark the 4-byte
> ACPI identifier arrays with __nonstring (and the new __nonstring_array)
> to correctly identify the char arrays as "not C strings" and thereby
> eliminate the many warnings like this:
>
> In file included from include/acpi/actbl.h:371,
> from include/acpi/acpi.h:26,
> from include/linux/acpi.h:26,
> from drivers/acpi/tables.c:19:
> include/acpi/actbl1.h:30:33: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (5 chars into 4 available) [-Wunterminated-string-initialization]
> 30 | #define ACPI_SIG_BERT "BERT" /* Boot Error Record Table */
> | ^~~~~~
> drivers/acpi/tables.c:400:9: note: in expansion of macro 'ACPI_SIG_BERT'
> 400 | ACPI_SIG_BERT, ACPI_SIG_BGRT, ACPI_SIG_CPEP, ACPI_SIG_ECDT,
> | ^~~~~~~~~~~~~
>
> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Len Brown <lenb@kernel.org>
> Cc: Robert Moore <robert.moore@intel.com>
> Cc: linux-acpi@vger.kernel.org
> Cc: acpica-devel@lists.linux.dev
> ---
> drivers/acpi/tables.c | 2 +-
> include/acpi/actbl.h | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
> index 2295abbecd14..0a9ade7117bd 100644
> --- a/drivers/acpi/tables.c
> +++ b/drivers/acpi/tables.c
> @@ -396,7 +396,7 @@ static u8 __init acpi_table_checksum(u8 *buffer, u32 length)
> }
>
> /* All but ACPI_SIG_RSDP and ACPI_SIG_FACS: */
> -static const char table_sigs[][ACPI_NAMESEG_SIZE] __initconst = {
> +static const char table_sigs[][ACPI_NAMESEG_SIZE] __nonstring_array __initconst = {
> ACPI_SIG_BERT, ACPI_SIG_BGRT, ACPI_SIG_CPEP, ACPI_SIG_ECDT,
> ACPI_SIG_EINJ, ACPI_SIG_ERST, ACPI_SIG_HEST, ACPI_SIG_MADT,
> ACPI_SIG_MSCT, ACPI_SIG_SBST, ACPI_SIG_SLIT, ACPI_SIG_SRAT,
> diff --git a/include/acpi/actbl.h b/include/acpi/actbl.h
> index 451f6276da49..2fc89704be17 100644
> --- a/include/acpi/actbl.h
> +++ b/include/acpi/actbl.h
> @@ -66,7 +66,7 @@
> ******************************************************************************/
>
> struct acpi_table_header {
> - char signature[ACPI_NAMESEG_SIZE]; /* ASCII table signature */
> + char signature[ACPI_NAMESEG_SIZE] __nonstring; /* ASCII table signature */
> u32 length; /* Length of table in bytes, including this header */
> u8 revision; /* ACPI Specification minor version number */
> u8 checksum; /* To make sum of entire table == 0 */
> --
Applied as 6.16 material.
I've rebased it on top of
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9d7a0577c9db35c4cc52db90bc415ea248446472
so basically the hunk in actbl.h is gone. Please see
https://web.git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git/commit/?h=bleeding-edge&id=18eb45b67544b995a8a6f48a72b816fd75776f52
Thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-23 20:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-15 23:20 [PATCH] ACPI: tables: Add __nonstring annotations for unterminated strings Kees Cook
2025-04-23 20:04 ` Rafael J. Wysocki
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).