* [PATCH][next] sparc: openpromio: Address -Warray-bounds warning
@ 2023-06-22 23:14 Gustavo A. R. Silva
2023-06-29 19:57 ` Kees Cook
0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2023-06-22 23:14 UTC (permalink / raw)
To: David S. Miller
Cc: sparclinux, linux-kernel, Gustavo A. R. Silva, linux-hardening
One-element arrays are deprecated, and we are replacing them with flexible
array members instead. So, replace one-element array with flexible-array
member in struct openpromio.
Address the following warning found after building (with GCC-13) sparc
with sparc64_defconfig:
In function 'opromgetprop',
inlined from 'openprom_sunos_ioctl.isra' at drivers/sbus/char/openprom.c:312:11:
drivers/sbus/char/openprom.c:141:24: warning: array subscript 1 is above array bounds of 'char[1]' [-Warray-bounds=]
141 | op->oprom_array[len] = '\0';
| ~~~~~~~~~~~~~~~^~~~~
In file included from drivers/sbus/char/openprom.c:31:
arch/sparc/include/uapi/asm/openpromio.h: In function 'openprom_sunos_ioctl.isra':
arch/sparc/include/uapi/asm/openpromio.h:16:17: note: while referencing 'oprom_array'
16 | char oprom_array[1]; /* Holds property names and values. */
| ^~~~~~~~~~~
This helps with the ongoing efforts to tighten the FORTIFY_SOURCE
routines on memcpy() and help us make progress towards globally
enabling -Warray-bounds.
This results in no differences in binary output.
Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/322
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
arch/sparc/include/uapi/asm/openpromio.h | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/arch/sparc/include/uapi/asm/openpromio.h b/arch/sparc/include/uapi/asm/openpromio.h
index d4494b679e99..2a73ec77aba6 100644
--- a/arch/sparc/include/uapi/asm/openpromio.h
+++ b/arch/sparc/include/uapi/asm/openpromio.h
@@ -10,10 +10,9 @@
* were chosen to be exactly equal to the SunOS equivalents.
*/
-struct openpromio
-{
+struct openpromio {
unsigned int oprom_size; /* Actual size of the oprom_array. */
- char oprom_array[1]; /* Holds property names and values. */
+ char oprom_array[]; /* Holds property names and values. */
};
#define OPROMMAXPARAM 4096 /* Maximum size of oprom_array. */
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH][next] sparc: openpromio: Address -Warray-bounds warning
2023-06-22 23:14 [PATCH][next] sparc: openpromio: Address -Warray-bounds warning Gustavo A. R. Silva
@ 2023-06-29 19:57 ` Kees Cook
0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2023-06-29 19:57 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: David S. Miller, sparclinux, linux-kernel, linux-hardening
On Thu, Jun 22, 2023 at 05:14:51PM -0600, Gustavo A. R. Silva wrote:
> One-element arrays are deprecated, and we are replacing them with flexible
> array members instead. So, replace one-element array with flexible-array
> member in struct openpromio.
>
> Address the following warning found after building (with GCC-13) sparc
> with sparc64_defconfig:
> In function 'opromgetprop',
> inlined from 'openprom_sunos_ioctl.isra' at drivers/sbus/char/openprom.c:312:11:
> drivers/sbus/char/openprom.c:141:24: warning: array subscript 1 is above array bounds of 'char[1]' [-Warray-bounds=]
> 141 | op->oprom_array[len] = '\0';
> | ~~~~~~~~~~~~~~~^~~~~
> In file included from drivers/sbus/char/openprom.c:31:
> arch/sparc/include/uapi/asm/openpromio.h: In function 'openprom_sunos_ioctl.isra':
> arch/sparc/include/uapi/asm/openpromio.h:16:17: note: while referencing 'oprom_array'
> 16 | char oprom_array[1]; /* Holds property names and values. */
> | ^~~~~~~~~~~
>
> This helps with the ongoing efforts to tighten the FORTIFY_SOURCE
> routines on memcpy() and help us make progress towards globally
> enabling -Warray-bounds.
>
> This results in no differences in binary output.
>
> Link: https://github.com/KSPP/linux/issues/79
> Link: https://github.com/KSPP/linux/issues/322
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-06-29 19:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-22 23:14 [PATCH][next] sparc: openpromio: Address -Warray-bounds warning Gustavo A. R. Silva
2023-06-29 19:57 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox