public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: Russell King <linux@armlinux.org.uk>
Cc: Arnd Bergmann <arnd@arndb.de>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] ARM: atags_compat: avoid -Warray-bounds warning
Date: Mon, 26 Oct 2020 23:13:16 +0100	[thread overview]
Message-ID: <20201026221406.3897734-1-arnd@kernel.org> (raw)

From: Arnd Bergmann <arnd@arndb.de>

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 <arnd@arndb.de>
---
 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	other threads:[~2020-10-26 22:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201026221406.3897734-1-arnd@kernel.org \
    --to=arnd@kernel.org \
    --cc=arnd@arndb.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox