diff mbox series

[RFC,1/2] ACPI: mark ACPI_COPY_NAMESEG destinations with __nonstring attribute

Message ID a9bd2a1b490b4305c18f8473aab21c97e8902fb8.1743313252.git.x0rw3ll@gmail.com (mailing list archive)
State RFC, archived
Headers show
Series ACPI: replace deprecated strncpy() | expand

Commit Message

Ahmed Salem March 30, 2025, 5:54 a.m. UTC
strncpy(), which ACPI_COPY_NAMESEG currently uses, is deprecated[1].

This patch is the first of two, ultimately replacing strncpy() with
strtomem(), avoiding future compiler warnings about truncation.

[1] https://github.com/KSPP/linux/issues/90

Signed-off-by: Ahmed Salem <x0rw3ll@gmail.com>
---
 drivers/acpi/acpica/acdebug.h                            | 2 +-
 drivers/acpi/prmt.c                                      | 2 +-
 drivers/acpi/sysfs.c                                     | 4 ++--
 include/acpi/actbl.h                                     | 6 +++---
 tools/power/acpi/os_specific/service_layers/oslinuxtbl.c | 2 +-
 tools/power/acpi/tools/acpidump/apfiles.c                | 2 +-
 6 files changed, 9 insertions(+), 9 deletions(-)

Comments

Rafael J. Wysocki March 31, 2025, 11:49 a.m. UTC | #1
On Sun, Mar 30, 2025 at 7:54 AM Ahmed Salem <x0rw3ll@gmail.com> wrote:
>
> strncpy(), which ACPI_COPY_NAMESEG currently uses, is deprecated[1].
>
> This patch is the first of two, ultimately replacing strncpy() with
> strtomem(), avoiding future compiler warnings about truncation.
>
> [1] https://github.com/KSPP/linux/issues/90
>
> Signed-off-by: Ahmed Salem <x0rw3ll@gmail.com>

ACPICA material is primarily handled by the upstream ACPICA project on
GitHub, so please avoid mixing ACPICA code changes with changes to the
other code in one patch.

Also, ACPICA changes should first be submitted to upstream ACPICA, as
indicated on this list for many times, see for instance:

https://lore.kernel.org/linux-acpi/CAJZ5v0gUDxrAn4W+Rf3ifjrg8Z9ZzTTOZjPFSSN5488mPqzXeA@mail.gmail.com/

> ---
>  drivers/acpi/acpica/acdebug.h                            | 2 +-
>  drivers/acpi/prmt.c                                      | 2 +-
>  drivers/acpi/sysfs.c                                     | 4 ++--
>  include/acpi/actbl.h                                     | 6 +++---
>  tools/power/acpi/os_specific/service_layers/oslinuxtbl.c | 2 +-
>  tools/power/acpi/tools/acpidump/apfiles.c                | 2 +-
>  6 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/acpi/acpica/acdebug.h b/drivers/acpi/acpica/acdebug.h
> index 911875c5a5f1..2b56a8178f43 100644
> --- a/drivers/acpi/acpica/acdebug.h
> +++ b/drivers/acpi/acpica/acdebug.h
> @@ -37,7 +37,7 @@ struct acpi_db_argument_info {
>  struct acpi_db_execute_walk {
>         u32 count;
>         u32 max_count;
> -       char name_seg[ACPI_NAMESEG_SIZE + 1];
> +       char name_seg[ACPI_NAMESEG_SIZE + 1] __nonstring;
>  };
>
>  #define PARAM_LIST(pl)                  pl
> diff --git a/drivers/acpi/prmt.c b/drivers/acpi/prmt.c
> index e549914a636c..ca70f01c940c 100644
> --- a/drivers/acpi/prmt.c
> +++ b/drivers/acpi/prmt.c
> @@ -40,7 +40,7 @@ struct prm_buffer {
>  };
>
>  struct prm_context_buffer {
> -       char signature[ACPI_NAMESEG_SIZE];
> +       char signature[ACPI_NAMESEG_SIZE] __nonstring;
>         u16 revision;
>         u16 reserved;
>         guid_t identifier;
> diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
> index a48ebbf768f9..a05d4032d4f1 100644
> --- a/drivers/acpi/sysfs.c
> +++ b/drivers/acpi/sysfs.c
> @@ -307,9 +307,9 @@ static struct kobject *hotplug_kobj;
>
>  struct acpi_table_attr {
>         struct bin_attribute attr;
> -       char name[ACPI_NAMESEG_SIZE];
> +       char name[ACPI_NAMESEG_SIZE] __nonstring;
>         int instance;
> -       char filename[ACPI_NAMESEG_SIZE+ACPI_INST_SIZE];
> +       char filename[ACPI_NAMESEG_SIZE+ACPI_INST_SIZE] __nonstring;
>         struct list_head node;
>  };
>
> diff --git a/include/acpi/actbl.h b/include/acpi/actbl.h
> index 451f6276da49..8aa60281e7db 100644
> --- a/include/acpi/actbl.h
> +++ b/include/acpi/actbl.h
> @@ -66,12 +66,12 @@
>   ******************************************************************************/
>
>  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 */
> -       char oem_id[ACPI_OEM_ID_SIZE];  /* ASCII OEM identification */
> -       char oem_table_id[ACPI_OEM_TABLE_ID_SIZE];      /* ASCII OEM table identification */
> +       char oem_id[ACPI_OEM_ID_SIZE] __nonstring;      /* ASCII OEM identification */
> +       char oem_table_id[ACPI_OEM_TABLE_ID_SIZE] __nonstring;  /* ASCII OEM table identification */
>         u32 oem_revision;       /* OEM revision number */
>         char asl_compiler_id[ACPI_NAMESEG_SIZE];        /* ASCII ASL compiler vendor ID */
>         u32 asl_compiler_revision;      /* ASL compiler version */
> diff --git a/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c b/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c
> index 9d70d8c945af..52026b9e389e 100644
> --- a/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c
> +++ b/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c
> @@ -19,7 +19,7 @@ ACPI_MODULE_NAME("oslinuxtbl")
>  typedef struct osl_table_info {
>         struct osl_table_info *next;
>         u32 instance;
> -       char signature[ACPI_NAMESEG_SIZE];
> +       char signature[ACPI_NAMESEG_SIZE] __nonstring;
>
>  } osl_table_info;
>
> diff --git a/tools/power/acpi/tools/acpidump/apfiles.c b/tools/power/acpi/tools/acpidump/apfiles.c
> index 13817f9112c0..5a39b7d9351d 100644
> --- a/tools/power/acpi/tools/acpidump/apfiles.c
> +++ b/tools/power/acpi/tools/acpidump/apfiles.c
> @@ -103,7 +103,7 @@ int ap_open_output_file(char *pathname)
>
>  int ap_write_to_binary_file(struct acpi_table_header *table, u32 instance)
>  {
> -       char filename[ACPI_NAMESEG_SIZE + 16];
> +       char filename[ACPI_NAMESEG_SIZE + 16] __nonstring;
>         char instance_str[16];
>         ACPI_FILE file;
>         acpi_size actual;
> --
> 2.47.2
>
>
Ahmed Salem March 31, 2025, 5:55 p.m. UTC | #2
On 25/03/31 01:49PM, Rafael J. Wysocki wrote:
> On Sun, Mar 30, 2025 at 7:54 AM Ahmed Salem <x0rw3ll@gmail.com> wrote:
> >
> > strncpy(), which ACPI_COPY_NAMESEG currently uses, is deprecated[1].
> >
> > This patch is the first of two, ultimately replacing strncpy() with
> > strtomem(), avoiding future compiler warnings about truncation.
> >
> > [1] https://github.com/KSPP/linux/issues/90
> >
> > Signed-off-by: Ahmed Salem <x0rw3ll@gmail.com>
> 
> ACPICA material is primarily handled by the upstream ACPICA project on
> GitHub, so please avoid mixing ACPICA code changes with changes to the
> other code in one patch.
> 
> Also, ACPICA changes should first be submitted to upstream ACPICA, as
> indicated on this list for many times, see for instance:
> 
> https://lore.kernel.org/linux-acpi/CAJZ5v0gUDxrAn4W+Rf3ifjrg8Z9ZzTTOZjPFSSN5488mPqzXeA@mail.gmail.com/
> 

Thank you so much for the note! In full transparency, I did see that
comment prior to submitting this patch. However, I wasn't entirely sure
whether I should have done that given the nature of this patch.

This marks my second time contributing patches as part of the LKMP, and
I've just got started learning C fairly recently, so I thought I'd
consolidate the changes into this series so if there's anything wrong
with my approach, it would cut the time discussing it over on upstream
as well as mailing lists. Hindsight being what it is, however, I should
have seen the MR from Kees Cook introducing ACPI_NONSTRING before
proposing changes, so that's definitely lessons learned for current and
future reference.

Point taken nonetheless, and I will be submitting the ACPICA-related PR
upstream, and resend the ACPI-specific one here instead without the RFC
tag. My apologies, and thank you so much once again for your time and
effort!

> > ---
> >  drivers/acpi/acpica/acdebug.h                            | 2 +-
> >  drivers/acpi/prmt.c                                      | 2 +-
> >  drivers/acpi/sysfs.c                                     | 4 ++--
> >  include/acpi/actbl.h                                     | 6 +++---
> >  tools/power/acpi/os_specific/service_layers/oslinuxtbl.c | 2 +-
> >  tools/power/acpi/tools/acpidump/apfiles.c                | 2 +-
> >  6 files changed, 9 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/acpi/acpica/acdebug.h b/drivers/acpi/acpica/acdebug.h
> > index 911875c5a5f1..2b56a8178f43 100644
> > --- a/drivers/acpi/acpica/acdebug.h
> > +++ b/drivers/acpi/acpica/acdebug.h
> > @@ -37,7 +37,7 @@ struct acpi_db_argument_info {
> >  struct acpi_db_execute_walk {
> >         u32 count;
> >         u32 max_count;
> > -       char name_seg[ACPI_NAMESEG_SIZE + 1];
> > +       char name_seg[ACPI_NAMESEG_SIZE + 1] __nonstring;
> >  };
> >
> >  #define PARAM_LIST(pl)                  pl
> > diff --git a/drivers/acpi/prmt.c b/drivers/acpi/prmt.c
> > index e549914a636c..ca70f01c940c 100644
> > --- a/drivers/acpi/prmt.c
> > +++ b/drivers/acpi/prmt.c
> > @@ -40,7 +40,7 @@ struct prm_buffer {
> >  };
> >
> >  struct prm_context_buffer {
> > -       char signature[ACPI_NAMESEG_SIZE];
> > +       char signature[ACPI_NAMESEG_SIZE] __nonstring;
> >         u16 revision;
> >         u16 reserved;
> >         guid_t identifier;
> > diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
> > index a48ebbf768f9..a05d4032d4f1 100644
> > --- a/drivers/acpi/sysfs.c
> > +++ b/drivers/acpi/sysfs.c
> > @@ -307,9 +307,9 @@ static struct kobject *hotplug_kobj;
> >
> >  struct acpi_table_attr {
> >         struct bin_attribute attr;
> > -       char name[ACPI_NAMESEG_SIZE];
> > +       char name[ACPI_NAMESEG_SIZE] __nonstring;
> >         int instance;
> > -       char filename[ACPI_NAMESEG_SIZE+ACPI_INST_SIZE];
> > +       char filename[ACPI_NAMESEG_SIZE+ACPI_INST_SIZE] __nonstring;
> >         struct list_head node;
> >  };
> >
> > diff --git a/include/acpi/actbl.h b/include/acpi/actbl.h
> > index 451f6276da49..8aa60281e7db 100644
> > --- a/include/acpi/actbl.h
> > +++ b/include/acpi/actbl.h
> > @@ -66,12 +66,12 @@
> >   ******************************************************************************/
> >
> >  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 */
> > -       char oem_id[ACPI_OEM_ID_SIZE];  /* ASCII OEM identification */
> > -       char oem_table_id[ACPI_OEM_TABLE_ID_SIZE];      /* ASCII OEM table identification */
> > +       char oem_id[ACPI_OEM_ID_SIZE] __nonstring;      /* ASCII OEM identification */
> > +       char oem_table_id[ACPI_OEM_TABLE_ID_SIZE] __nonstring;  /* ASCII OEM table identification */
> >         u32 oem_revision;       /* OEM revision number */
> >         char asl_compiler_id[ACPI_NAMESEG_SIZE];        /* ASCII ASL compiler vendor ID */
> >         u32 asl_compiler_revision;      /* ASL compiler version */
> > diff --git a/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c b/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c
> > index 9d70d8c945af..52026b9e389e 100644
> > --- a/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c
> > +++ b/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c
> > @@ -19,7 +19,7 @@ ACPI_MODULE_NAME("oslinuxtbl")
> >  typedef struct osl_table_info {
> >         struct osl_table_info *next;
> >         u32 instance;
> > -       char signature[ACPI_NAMESEG_SIZE];
> > +       char signature[ACPI_NAMESEG_SIZE] __nonstring;
> >
> >  } osl_table_info;
> >
> > diff --git a/tools/power/acpi/tools/acpidump/apfiles.c b/tools/power/acpi/tools/acpidump/apfiles.c
> > index 13817f9112c0..5a39b7d9351d 100644
> > --- a/tools/power/acpi/tools/acpidump/apfiles.c
> > +++ b/tools/power/acpi/tools/acpidump/apfiles.c
> > @@ -103,7 +103,7 @@ int ap_open_output_file(char *pathname)
> >
> >  int ap_write_to_binary_file(struct acpi_table_header *table, u32 instance)
> >  {
> > -       char filename[ACPI_NAMESEG_SIZE + 16];
> > +       char filename[ACPI_NAMESEG_SIZE + 16] __nonstring;
> >         char instance_str[16];
> >         ACPI_FILE file;
> >         acpi_size actual;
> > --
> > 2.47.2
> >
> >
diff mbox series

Patch

diff --git a/drivers/acpi/acpica/acdebug.h b/drivers/acpi/acpica/acdebug.h
index 911875c5a5f1..2b56a8178f43 100644
--- a/drivers/acpi/acpica/acdebug.h
+++ b/drivers/acpi/acpica/acdebug.h
@@ -37,7 +37,7 @@  struct acpi_db_argument_info {
 struct acpi_db_execute_walk {
 	u32 count;
 	u32 max_count;
-	char name_seg[ACPI_NAMESEG_SIZE + 1];
+	char name_seg[ACPI_NAMESEG_SIZE + 1] __nonstring;
 };
 
 #define PARAM_LIST(pl)                  pl
diff --git a/drivers/acpi/prmt.c b/drivers/acpi/prmt.c
index e549914a636c..ca70f01c940c 100644
--- a/drivers/acpi/prmt.c
+++ b/drivers/acpi/prmt.c
@@ -40,7 +40,7 @@  struct prm_buffer {
 };
 
 struct prm_context_buffer {
-	char signature[ACPI_NAMESEG_SIZE];
+	char signature[ACPI_NAMESEG_SIZE] __nonstring;
 	u16 revision;
 	u16 reserved;
 	guid_t identifier;
diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index a48ebbf768f9..a05d4032d4f1 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -307,9 +307,9 @@  static struct kobject *hotplug_kobj;
 
 struct acpi_table_attr {
 	struct bin_attribute attr;
-	char name[ACPI_NAMESEG_SIZE];
+	char name[ACPI_NAMESEG_SIZE] __nonstring;
 	int instance;
-	char filename[ACPI_NAMESEG_SIZE+ACPI_INST_SIZE];
+	char filename[ACPI_NAMESEG_SIZE+ACPI_INST_SIZE] __nonstring;
 	struct list_head node;
 };
 
diff --git a/include/acpi/actbl.h b/include/acpi/actbl.h
index 451f6276da49..8aa60281e7db 100644
--- a/include/acpi/actbl.h
+++ b/include/acpi/actbl.h
@@ -66,12 +66,12 @@ 
  ******************************************************************************/
 
 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 */
-	char oem_id[ACPI_OEM_ID_SIZE];	/* ASCII OEM identification */
-	char oem_table_id[ACPI_OEM_TABLE_ID_SIZE];	/* ASCII OEM table identification */
+	char oem_id[ACPI_OEM_ID_SIZE] __nonstring;	/* ASCII OEM identification */
+	char oem_table_id[ACPI_OEM_TABLE_ID_SIZE] __nonstring;	/* ASCII OEM table identification */
 	u32 oem_revision;	/* OEM revision number */
 	char asl_compiler_id[ACPI_NAMESEG_SIZE];	/* ASCII ASL compiler vendor ID */
 	u32 asl_compiler_revision;	/* ASL compiler version */
diff --git a/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c b/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c
index 9d70d8c945af..52026b9e389e 100644
--- a/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c
+++ b/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c
@@ -19,7 +19,7 @@  ACPI_MODULE_NAME("oslinuxtbl")
 typedef struct osl_table_info {
 	struct osl_table_info *next;
 	u32 instance;
-	char signature[ACPI_NAMESEG_SIZE];
+	char signature[ACPI_NAMESEG_SIZE] __nonstring;
 
 } osl_table_info;
 
diff --git a/tools/power/acpi/tools/acpidump/apfiles.c b/tools/power/acpi/tools/acpidump/apfiles.c
index 13817f9112c0..5a39b7d9351d 100644
--- a/tools/power/acpi/tools/acpidump/apfiles.c
+++ b/tools/power/acpi/tools/acpidump/apfiles.c
@@ -103,7 +103,7 @@  int ap_open_output_file(char *pathname)
 
 int ap_write_to_binary_file(struct acpi_table_header *table, u32 instance)
 {
-	char filename[ACPI_NAMESEG_SIZE + 16];
+	char filename[ACPI_NAMESEG_SIZE + 16] __nonstring;
 	char instance_str[16];
 	ACPI_FILE file;
 	acpi_size actual;