ACPI: tables: Add __nonstring annotations for unterminated strings
Subsystems (2)
PATCH 1/1 ACPI: tables: Add __nonstring annotations for unterminated strings
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,
| ^~~~~~~~~~~~~---
Cc: "Rafael J. Wysocki" <[email protected]>
Cc: Len Brown <[email protected]>
Cc: Robert Moore <[email protected]>
Cc: [email protected]
Cc: [email protected]
--- drivers/acpi/tables.c | 2 +- include/acpi/actbl.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/tables.c +1 -1
@@ -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 ,
include/acpi/actbl.h +1 -1
@@ -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 */
Signature · 1 line
2.34.1
Quoted 50 lines · Kees Cook
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,
frominclude/acpi/acpi.h:26,
frominclude/linux/acpi.h:26,
fromdrivers/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, | ^~~~~~~~~~~~~Signed-off-by Kees Cook <[email protected]>---
Cc: "Rafael J. Wysocki" <[email protected]>
Cc: Len Brown <[email protected]>
Cc: Robert Moore <[email protected]>
Cc: [email protected]
Cc: [email protected]--- drivers/acpi/tables.c | 2 +- include/acpi/actbl.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/acpi/tables.c +1
-1@@ -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 ,include/acpi/actbl.h +0
-0
include/acpi/actbl.h
Quoted 9 lines
include/acpi/actbl.h +1
-2@@ -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
so basically the hunk in actbl.h is gone. Please see
Thanks!