Commit 54d11736 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Darren Hart (VMware)

platform/x86: dell-smbios: fix string overflow

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

This changes it to just use kasprintf(), which always gets it right.

Discovered with gcc-7.1.1 with the following commit reverted:
bd664f6b disable new gcc-7.1.1 warnings for now

Fixes: 33b9ca1e ("platform/x86: dell-smbios: Add a sysfs interface for SMBIOS tokens")
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Acked-by: default avatarMario Limonciello <mario.limonciello@dell.com>
[dvhart: add subject prefix and reproducer details for context]
Signed-off-by: default avatarDarren Hart (VMware) <dvhart@infradead.org>
parent 43aaf4f0
......@@ -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",
location_name = kasprintf(GFP_KERNEL, "%04x_location",
da_tokens[i].tokenID);
location_name = kstrdup(buffer_location, GFP_KERNEL);
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",
value_name = kasprintf(GFP_KERNEL, "%04x_value",
da_tokens[i].tokenID);
value_name = kstrdup(buffer_value, GFP_KERNEL);
if (value_name == NULL)
goto loop_fail_create_value;
sysfs_attr_init(&token_value_attrs[i].attr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment