From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752324AbdKHSaO (ORCPT ); Wed, 8 Nov 2017 13:30:14 -0500 Received: from esa3.dell-outbound.iphmx.com ([68.232.153.94]:33347 "EHLO esa3.dell-outbound.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751653AbdKHSaL (ORCPT ); Wed, 8 Nov 2017 13:30:11 -0500 IronPort-PHdr: =?us-ascii?q?9a23=3AEGKkcB2b7AsbQ38SsmDT+DRfVm0co7zxezQtwd8Z?= =?us-ascii?q?sesWKvzxwZ3uMQTl6Ol3ixeRBMOAuqIC07KempujcFRI2YyGvnEGfc4EfD4+ou?= =?us-ascii?q?JSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgpp?= =?us-ascii?q?POT1HZPZg9iq2+yo9ZDeZwZFiCChbb9uMR67sRjfus4KjIV4N60/0AHJonxGe+?= =?us-ascii?q?RXwWNnO1eelAvi68mz4ZBu7T1et+ou+MBcX6r6eb84TaFDAzQ9L281/szrugLd?= =?us-ascii?q?QgaJ+3ART38ZkhtMAwjC8RH6QpL8uTb0u+ZhxCWXO9D9QLYpUjqg8qhrUgflhi?= =?us-ascii?q?cZOTAk7GHZhM9+jKxZrxKguxNxzIHbbZqJNPVlfKPRYc8WSXZDU8tXSidPApm8?= =?us-ascii?q?b4wKD+cZOutWqJPyp0EPrRu5HwWiAuLvyjpPhn/wwaI60vouEQXC3AwnBN8BrW?= =?us-ascii?q?rbrNHxNKsITe+1y6zIwCzFYvhL2jn98JDFfxEirP2WQ759f9TdxVMyGw7FgFic?= =?us-ascii?q?s5LpMy+L2ugVrmSX8/BsWf+ghmMpsQ19vDeiytk2hoTLho8Z0k3I+Cp3zYovON?= =?us-ascii?q?G1SU92bcSnHZZQrS2WKZd6Tt8kTmp1oig10KcGtoS+fCUSzZQnwAPQZOKffoiT?= =?us-ascii?q?5xLjSP6RITBlhHJ5YL6/hwi98UynyuDkSMa0y0xFojRfntbRqH8N0xjT5tGASv?= =?us-ascii?q?tg4keuwjGP1x3V6u5ZP0w4j6vbK4Yhwr41mZsfq1jMHijzmEnuja+WcFsr+vSw?= =?us-ascii?q?5unmYbjqvIGQOoFqhg3kL6gjmsKyDf4mPgQSQWSX4eG826fi/U39TrVKlPo2kq?= =?us-ascii?q?zBvZ7dP8sbvK+5AwhP3ogl6ha/CjCm0NIEknkGMl1FfBaHj4/yNl7TPv/4CfO/?= =?us-ascii?q?j06wnzdswvDKJqfhDYnVLnjfjLfheq5w61ZYyAUp0dBf6ZVUCqsEIP7qR0Dxrt?= =?us-ascii?q?3YDgEnPAyu2urmB9Zw24IFVGKRDa+WLrnSvUWL5u0xOemMYpEauDLnJ/gi/f7u?= =?us-ascii?q?gmczmUUBcqmxwZsXdHe4E+xiI0WYZ3rsn9gAHX4JvgUgVuzqjkONUTpIanasUK?= =?us-ascii?q?Iz+Cs7BJilDYjdXICthqKO3COhEp1RfGBGBQPELXC9I56NR/cdYSSbOMZwmzoN?= =?us-ascii?q?U/6iVpc5yAqxvQrr475mKPfEvCweqZ/nktNy4ruX3UU77zp4J82H1W2HCW15yC?= =?us-ascii?q?dAEyc/2KE5u0t9w02r3q1xgvgeHttWsbcBBgskNZfG08R7Dd7oUw7Md9vPT0yp?= =?us-ascii?q?FJHuVTg3QsMZwtkAeU9xFtyuyBfZ0Hz5LaUSkunfIZUu86Wa+3n0IMB2ynvC0K?= =?us-ascii?q?4Jg1QiRo1EMmjw1f03zBTaG4OcyxbRrK2tb6lJhCM=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2HZAADvOgNamMqZ6ERdGQEBAQEBAQEBA?= =?us-ascii?q?QEBAQcBAQEBAYQIficHg3aKH48lgXyBf4ZWjXeBMgNcCoU7AhqEYj8YAQEBAQE?= =?us-ascii?q?BAQEBAQIQAQEBAQEICwsGKC+COCKCRAEBAQEDIxFFDAQCAQgRBAEBAQICIwMCA?= =?us-ascii?q?gIfJQEICAIEAQ0FCIoDAxWqCYInhBYBgy8Ng0gBAQEBAQEBAQEBAQEBAQEBAQE?= =?us-ascii?q?BAQEdgQ+CIYIHgz2DKoJrgjEQIQKCW4JjBaFdPZAFhHCTQY0iiH+BOR+BCIEie?= =?us-ascii?q?jSDDoJZEwyBLAE6dwGLC4ERAQEB?= X-IPAS-Result: =?us-ascii?q?A2HZAADvOgNamMqZ6ERdGQEBAQEBAQEBAQEBAQcBAQEBAYQ?= =?us-ascii?q?IficHg3aKH48lgXyBf4ZWjXeBMgNcCoU7AhqEYj8YAQEBAQEBAQEBAQIQAQEBA?= =?us-ascii?q?QEICwsGKC+COCKCRAEBAQEDIxFFDAQCAQgRBAEBAQICIwMCAgIfJQEICAIEAQ0?= =?us-ascii?q?FCIoDAxWqCYInhBYBgy8Ng0gBAQEBAQEBAQEBAQEBAQEBAQEBAQEdgQ+CIYIHg?= =?us-ascii?q?z2DKoJrgjEQIQKCW4JjBaFdPZAFhHCTQY0iiH+BOR+BCIEiejSDDoJZEwyBLAE?= =?us-ascii?q?6dwGLC4ERAQEB?= From: X-LoopCount0: from 10.166.132.190 X-IronPort-AV: E=Sophos;i="5.44,365,1505797200"; d="scan'208";a="573640963" X-DLP: DLP_GlobalPCIDSS To: , , , , CC: , , , Subject: RE: [PATCH] dell-smbios: fix string overflow Thread-Topic: [PATCH] dell-smbios: fix string overflow Thread-Index: AQHTWIpcMm95AJcDL0S8rmQgl9tUKaMLMK0A//+cCTA= Date: Wed, 8 Nov 2017 18:30:08 +0000 Message-ID: <01d8cf85a7984a3cb1dd92771b65b8ea@ausx13mpc120.AMER.DELL.COM> References: <20171108120844.3196747-1-arnd@arndb.de> <8b46d25f-f9e6-d2e5-1b7c-abbc6dd47298@linux.intel.com> In-Reply-To: <8b46d25f-f9e6-d2e5-1b7c-abbc6dd47298@linux.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.143.242.75] Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by nfs id vA8IUKDq023648 > -----Original Message----- > From: sathyanarayanan kuppuswamy > [mailto:sathyanarayanan.kuppuswamy@linux.intel.com] > Sent: Wednesday, November 8, 2017 12:23 PM > To: Arnd Bergmann ; Pali Rohár ; > Limonciello, Mario ; Darren Hart > ; Andy Shevchenko > Cc: Edward O'Callaghan ; Hans de Goede > ; platform-driver-x86@vger.kernel.org; linux- > kernel@vger.kernel.org > Subject: Re: [PATCH] dell-smbios: fix string overflow > > Hi, > > I recommend using "platform/x86: dell-smbios:" in commit header. > > On 11/08/2017 04:08 AM, Arnd Bergmann wrote: > > The new sysfs code overwrites two fixed-length character arrays > > that are each one byte shorter than they need to be, to hold > > the trailing \0: > > > > drivers/platform/x86/dell-smbios.c: In function 'build_tokens_sysfs': > > drivers/platform/x86/dell-smbios.c:494:42: error: 'sprintf' writing a terminating > nul past the end of the destination [-Werror=format-overflow=] > > sprintf(buffer_location, "%04x_location", > > drivers/platform/x86/dell-smbios.c:494:3: note: 'sprintf' output 14 bytes into a > destination of size 13 > > drivers/platform/x86/dell-smbios.c:506:36: error: 'sprintf' writing a terminating > nul past the end of the destination [-Werror=format-overflow=] > > sprintf(buffer_value, "%04x_value", > > drivers/platform/x86/dell-smbios.c:506:3: note: 'sprintf' output 11 bytes into a > destination of size 10 > Don't need to include the error log in commit message. Just explaining > the issue is good enough. > > > > This changes it to just use kasprintf(), which always gets it right. > > > > Fixes: 33b9ca1e53b4 ("platform/x86: dell-smbios: Add a sysfs interface for > SMBIOS tokens") > > Signed-off-by: Arnd Bergmann > > --- > > drivers/platform/x86/dell-smbios.c | 12 ++++-------- > > 1 file changed, 4 insertions(+), 8 deletions(-) > > > > diff --git a/drivers/platform/x86/dell-smbios.c b/drivers/platform/x86/dell- > smbios.c > > index d99edd803c19..6a60db515bda 100644 > > --- a/drivers/platform/x86/dell-smbios.c > > +++ b/drivers/platform/x86/dell-smbios.c > > @@ -463,8 +463,6 @@ static struct platform_driver platform_driver = { > > > > static int build_tokens_sysfs(struct platform_device *dev) > > { > > - char buffer_location[13]; > > - char buffer_value[10]; > > char *location_name; > > char *value_name; > > size_t size; > > @@ -491,9 +489,8 @@ static int build_tokens_sysfs(struct platform_device > *dev) > > if (da_tokens[i].tokenID == 0) > > continue; > > /* add location */ > > - sprintf(buffer_location, "%04x_location", > > - da_tokens[i].tokenID); > > - location_name = kstrdup(buffer_location, GFP_KERNEL); > > + location_name = kasprintf(GFP_KERNEL, "%04x_location", > > + da_tokens[i].tokenID); > > if (location_name == NULL) > > goto out_unwind_strings; > > sysfs_attr_init(&token_location_attrs[i].attr); > > @@ -503,9 +500,8 @@ static int build_tokens_sysfs(struct platform_device > *dev) > > token_attrs[j++] = &token_location_attrs[i].attr; > > > > /* add value */ > > - sprintf(buffer_value, "%04x_value", > > - da_tokens[i].tokenID); > > - value_name = kstrdup(buffer_value, GFP_KERNEL); > > + value_name = kasprintf(GFP_KERNEL, "%04x_value", > > + da_tokens[i].tokenID); > > if (value_name == NULL) > > goto loop_fail_create_value; > > sysfs_attr_init(&token_value_attrs[i].attr); > > -- Arnd, Assuming Darren will do the fixup for title and message as recommended by Sathyanarayanan before committing: Acked-by: Mario Limonciello Thanks, for the fix. For my own information and improvement, would you share how you caught that? Just added "-Werror=format-overflow=" to CFLAGS? I wasn't seeing the compile errors with default flags in my own testing, so I'd like to make sure I'm doing better testing in the future.