Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-Wattribute-warning in drivers/scsi/libfc/fc_elsct.c #1590

Closed
nathanchance opened this issue Feb 14, 2022 · 4 comments
Closed

-Wattribute-warning in drivers/scsi/libfc/fc_elsct.c #1590

nathanchance opened this issue Feb 14, 2022 · 4 comments
Assignees
Labels
-Wattribute-warning [BUG] linux-next This is an issue only seen in linux-next [FIXED][LINUX] development cycle This bug was only present and fixed in a -next or -rc cycle [FIXED][LINUX] 5.18 This bug was fixed in Linux 5.18

Comments

@nathanchance
Copy link
Member

With both ARCH=arm64 allmodconfig and ARCH=x86_64 allmodconfig on linux-next, I see:

In file included from drivers/scsi/libfc/fc_elsct.c:17:
In file included from ./include/scsi/libfc.h:11:
In file included from ./include/linux/timer.h:6:
In file included from ./include/linux/ktime.h:24:
In file included from ./include/linux/time.h:60:
In file included from ./include/linux/time32.h:13:
In file included from ./include/linux/timex.h:65:
In file included from ./arch/arm64/include/asm/timex.h:8:
In file included from ./arch/arm64/include/asm/arch_timer.h:18:
In file included from ./include/linux/smp.h:13:
In file included from ./include/linux/cpumask.h:12:
In file included from ./include/linux/bitmap.h:11:
In file included from ./include/linux/string.h:253:
./include/linux/fortify-string.h:328:4: error: call to __write_overflow_field declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]
                        __write_overflow_field(p_size_field, size);
                        ^
./include/linux/fortify-string.h:328:4: error: call to __write_overflow_field declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]
2 errors generated.

This comes from the new fortify checks.

I noticed that @GustavoARSilva sent a patch to convert a couple of structures to use a flexible member array in drivers/scsi, which actually resolves this.

cc @kees

@nathanchance nathanchance added [PATCH] Exists There is a patch that fixes this issue [BUG] linux-next This is an issue only seen in linux-next -Wattribute-warning labels Feb 14, 2022
@GustavoARSilva
Copy link

GustavoARSilva commented Feb 14, 2022

I wonder if this patch still resolves those issues:

diff --git a/drivers/scsi/libfc/fc_encode.h b/drivers/scsi/libfc/fc_encode.h
index 74ae7fd15d8d..7dcac3b6baa7 100644
--- a/drivers/scsi/libfc/fc_encode.h
+++ b/drivers/scsi/libfc/fc_encode.h
@@ -246,7 +246,7 @@ static inline int fc_ct_ms_fill(struct fc_lport *lport,
                                   &entry->type);
                put_unaligned_be16(len, &entry->len);
                put_unaligned_be64(lport->wwnn,
-                                  (__be64 *)&entry->value[0]);
+                                  (__be64 *)&entry->value);

                /* Manufacturer */
                entry = (struct fc_fdmi_attr_entry *)((char *)entry->value +
diff --git a/include/scsi/fc/fc_ms.h b/include/scsi/fc/fc_ms.h
index 00191695233a..56a5d2b5a624 100644
--- a/include/scsi/fc/fc_ms.h
+++ b/include/scsi/fc/fc_ms.h
@@ -158,7 +158,7 @@ struct fc_fdmi_port_name {
 struct fc_fdmi_attr_entry {
        __be16          type;
        __be16          len;
-       __u8            value[1];
+       __u8            value[];
 } __attribute__((__packed__));

 /*
@@ -166,7 +166,7 @@ struct fc_fdmi_attr_entry {
  */
 struct fs_fdmi_attrs {
        __be32                          numattrs;
-       struct fc_fdmi_attr_entry       attr[1];
+       struct fc_fdmi_attr_entry       attr[];
 } __attribute__((__packed__));

 /*

@nathanchance
Copy link
Member Author

@GustavoARSilva it does, thanks!

fengguang pushed a commit to 0day-ci/linux that referenced this issue Feb 14, 2022
Use flexible-array members in struct fc_fdmi_attr_entry and
fs_fdmi_attrs instead of one-element arrays, and refactor the
code accordingly.

Also, this helps with the ongoing efforts to globally enable
-Warray-bounds and get us closer to being able to tighten the
FORTIFY_SOURCE routines on memcpy().

KSPP#79
ClangBuiltLinux#1590
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
@GustavoARSilva
Copy link

Great. :) I just sent out a proper patch for this: https://lore.kernel.org/linux-hardening/20220214223903.GA859464@embeddedor/

@GustavoARSilva GustavoARSilva self-assigned this Feb 14, 2022
@nathanchance nathanchance added [PATCH] Submitted A patch has been submitted for review and removed [PATCH] Exists There is a patch that fixes this issue labels Feb 14, 2022
@GustavoARSilva GustavoARSilva added the [PATCH] Accepted A submitted patch has been accepted upstream label Feb 28, 2022
@GustavoARSilva
Copy link

fengguang pushed a commit to 0day-ci/linux that referenced this issue Feb 28, 2022
Use flexible-array members in struct fc_fdmi_attr_entry and fs_fdmi_attrs
instead of one-element arrays, and refactor the code accordingly.

Also, this helps with the ongoing efforts to globally enable -Warray-bounds
and get us closer to being able to tighten the FORTIFY_SOURCE routines on
memcpy().

KSPP#79
ClangBuiltLinux#1590

Link: https://lore.kernel.org/r/20220214223903.GA859464@embeddedor
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
@nickdesaulniers nickdesaulniers removed the [PATCH] Submitted A patch has been submitted for review label Feb 28, 2022
@nickdesaulniers nickdesaulniers added [FIXED][LINUX] development cycle This bug was only present and fixed in a -next or -rc cycle and removed [PATCH] Accepted A submitted patch has been accepted upstream labels Feb 28, 2022
@GustavoARSilva GustavoARSilva added the [FIXED][LINUX] 5.18 This bug was fixed in Linux 5.18 label Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Wattribute-warning [BUG] linux-next This is an issue only seen in linux-next [FIXED][LINUX] development cycle This bug was only present and fixed in a -next or -rc cycle [FIXED][LINUX] 5.18 This bug was fixed in Linux 5.18
Projects
None yet
Development

No branches or pull requests

3 participants