From: Arnd Bergmann <[email protected]>

gcc-11 reports a struct member overflow when copying a string
into a single-character array:

In file included from arch/arm/kernel/atags_compat.c:17:
In function 'strcpy',
    inlined from 'build_tag_list' at arch/arm/kernel/atags_compat.c:200:2:
include/linux/string.h:287:29: warning: '__builtin_strcpy' offset 108 from the 
object at 'taglist' is out of the bounds of referenced subobject 'cmdline' with 
type 'char[1]' at offset 108 [-Warray-bounds]
  287 | #define __underlying_strcpy __builtin_strcpy
      |                             ^
include/linux/string.h:481:10: note: in expansion of macro '__underlying_strcpy'
  481 |   return __underlying_strcpy(p, q);
      |          ^~~~~~~~~~~~~~~~~~~
In file included from arch/arm/include/asm/setup.h:14,
                 from arch/arm/kernel/atags_compat.c:20:
arch/arm/kernel/atags_compat.c: In function 'build_tag_list':
arch/arm/include/uapi/asm/setup.h:127:7: note: subobject 'cmdline' declared here
  127 |  char cmdline[1]; /* this is the minimum size */
      |       ^~~~~~~

The code is otherwise correct, so just shut up the warning by
not letting the compiler see the underlying type.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Arnd Bergmann <[email protected]>
---
 arch/arm/kernel/atags_compat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/kernel/atags_compat.c b/arch/arm/kernel/atags_compat.c
index 10da11c212cc..3f1f631763ba 100644
--- a/arch/arm/kernel/atags_compat.c
+++ b/arch/arm/kernel/atags_compat.c
@@ -197,7 +197,7 @@ static void __init build_tag_list(struct param_struct 
*params, void *taglist)
        tag->hdr.tag = ATAG_CMDLINE;
        tag->hdr.size = (strlen(params->commandline) + 3 +
                         sizeof(struct tag_header)) >> 2;
-       strcpy(tag->u.cmdline.cmdline, params->commandline);
+       strcpy((void*)&tag->u, params->commandline);
 
        tag = tag_next(tag);
        tag->hdr.tag = ATAG_NONE;
-- 
2.27.0

Reply via email to