linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: x86@kernel.org, Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>
Cc: linux-kernel@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>
Subject: [PATCH 8/8] x86: intel-mid: fix a format string overflow warning
Date: Wed, 19 Jul 2017 14:53:06 +0200	[thread overview]
Message-ID: <20170719125310.2487451-9-arnd@arndb.de> (raw)
In-Reply-To: <20170719125310.2487451-1-arnd@arndb.de>

We have space for exactly three characters for the index in "max7315_%d_base",
but as gcc points out having more would cause an string overflow:

arch/x86/platform/intel-mid/device_libs/platform_max7315.c: In function 'max7315_platform_data':
arch/x86/platform/intel-mid/device_libs/platform_max7315.c:41:26: error: '%d' directive writing between 1 and 11 bytes into a region of size 9 [-Werror=format-overflow=]
   sprintf(base_pin_name, "max7315_%d_base", nr);
                          ^~~~~~~~~~~~~~~~~
arch/x86/platform/intel-mid/device_libs/platform_max7315.c:41:26: note: directive argument in the range [-2147483647, 2147483647]
arch/x86/platform/intel-mid/device_libs/platform_max7315.c:41:3: note: 'sprintf' output between 15 and 25 bytes into a destination of size 17
   sprintf(base_pin_name, "max7315_%d_base", nr);

This makes it use an snprintf() to truncate the string if that happened
rather than overflowing the stack. In practice, this is safe, because
there won't be a large number of max7315 devices in the systems, and
both the format and the length are defined by the firmware interface.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
Originally submitted on July 14, this is the same patch with slightly
improved changelog.
---
 arch/x86/platform/intel-mid/device_libs/platform_max7315.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/x86/platform/intel-mid/device_libs/platform_max7315.c b/arch/x86/platform/intel-mid/device_libs/platform_max7315.c
index 6e075afa7877..58337b2bc682 100644
--- a/arch/x86/platform/intel-mid/device_libs/platform_max7315.c
+++ b/arch/x86/platform/intel-mid/device_libs/platform_max7315.c
@@ -38,8 +38,10 @@ static void __init *max7315_platform_data(void *info)
 	 */
 	strcpy(i2c_info->type, "max7315");
 	if (nr++) {
-		sprintf(base_pin_name, "max7315_%d_base", nr);
-		sprintf(intr_pin_name, "max7315_%d_int", nr);
+		snprintf(base_pin_name, sizeof(base_pin_name),
+			 "max7315_%d_base", nr);
+		snprintf(intr_pin_name, sizeof(intr_pin_name),
+			 "max7315_%d_int", nr);
 	} else {
 		strcpy(base_pin_name, "max7315_base");
 		strcpy(intr_pin_name, "max7315_int");
-- 
2.9.0

  parent reply	other threads:[~2017-07-19 12:56 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-19 12:52 [PATCH 0/8] x86: randconfig warning fixes Arnd Bergmann
2017-07-19 12:52 ` [PATCH 1/8] perf/x86: shut up false-positive -Wmaybe-uninitialized warning Arnd Bergmann
2017-07-20 10:24   ` [tip:x86/urgent] perf/x86: Shut " tip-bot for Arnd Bergmann
2017-07-19 12:53 ` [PATCH 2/8] x86: math-emu: possible uninitialized variable use Arnd Bergmann
2017-07-20 10:25   ` [tip:x86/urgent] x86/fpu/math-emu: Fix " tip-bot for Arnd Bergmann
2017-07-19 12:53 ` [PATCH 3/8] x86: math-emu: avoid bogus -Wint-in-bool-context warning Arnd Bergmann
2017-07-20 10:25   ` [tip:x86/urgent] x86/fpu/math-emu: Avoid " tip-bot for Arnd Bergmann
2017-07-19 12:53 ` [PATCH 4/8] x86: io: add "memory" clobber to insb/insw/insl/outsb/outsw/outsl Arnd Bergmann
2017-07-19 19:25   ` Arnd Bergmann
2017-07-19 19:46   ` Linus Torvalds
2017-07-20 10:25   ` [tip:x86/urgent] x86/io: Add " tip-bot for Arnd Bergmann
2017-07-19 12:53 ` [PATCH 5/8] x86: silence build with "make -s" Arnd Bergmann
2017-07-20 10:26   ` [tip:x86/urgent] x86/build: Silence the " tip-bot for Arnd Bergmann
2017-07-19 12:53 ` [PATCH 6/8] x86: add MULTIUSER dependency for KVM Arnd Bergmann
2017-07-19 14:11   ` Radim Krčmář
2017-07-19 14:18     ` Arnd Bergmann
2017-07-19 16:13       ` Radim Krčmář
2017-07-23 13:41         ` Paolo Bonzini
2017-07-19 12:53 ` [PATCH 7/8] x86: add PCI dependency for PUNIT_ATOM_DEBUG Arnd Bergmann
2017-07-20 10:26   ` [tip:x86/urgent] x86/platform: Add " tip-bot for Arnd Bergmann
2017-07-19 12:53 ` Arnd Bergmann [this message]
2017-07-20 10:27   ` [tip:x86/urgent] x86/platform/intel-mid: Fix a format string overflow warning tip-bot for Arnd Bergmann

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=20170719125310.2487451-9-arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).