aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2017-11-08 07:08:39 -0500
committerDarren Hart (VMware) <dvhart@infradead.org>2017-11-08 15:58:29 -0500
commit54d11736ec3179954b6cdea4b4e1136d6bb39f39 (patch)
treed0390178bc40e57ff0b9582e9e50bd8b99d67e5b
parent43aaf4f03f063b12bcba2f8b800fdec85e2acc75 (diff)
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: bd664f6b3e disable new gcc-7.1.1 warnings for now Fixes: 33b9ca1e53b4 ("platform/x86: dell-smbios: Add a sysfs interface for SMBIOS tokens") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Mario Limonciello <mario.limonciello@dell.com> [dvhart: add subject prefix and reproducer details for context] Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>
-rw-r--r--drivers/platform/x86/dell-smbios.c12
1 files 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 = {
463 463
464static int build_tokens_sysfs(struct platform_device *dev) 464static int build_tokens_sysfs(struct platform_device *dev)
465{ 465{
466 char buffer_location[13];
467 char buffer_value[10];
468 char *location_name; 466 char *location_name;
469 char *value_name; 467 char *value_name;
470 size_t size; 468 size_t size;
@@ -491,9 +489,8 @@ static int build_tokens_sysfs(struct platform_device *dev)
491 if (da_tokens[i].tokenID == 0) 489 if (da_tokens[i].tokenID == 0)
492 continue; 490 continue;
493 /* add location */ 491 /* add location */
494 sprintf(buffer_location, "%04x_location", 492 location_name = kasprintf(GFP_KERNEL, "%04x_location",
495 da_tokens[i].tokenID); 493 da_tokens[i].tokenID);
496 location_name = kstrdup(buffer_location, GFP_KERNEL);
497 if (location_name == NULL) 494 if (location_name == NULL)
498 goto out_unwind_strings; 495 goto out_unwind_strings;
499 sysfs_attr_init(&token_location_attrs[i].attr); 496 sysfs_attr_init(&token_location_attrs[i].attr);
@@ -503,9 +500,8 @@ static int build_tokens_sysfs(struct platform_device *dev)
503 token_attrs[j++] = &token_location_attrs[i].attr; 500 token_attrs[j++] = &token_location_attrs[i].attr;
504 501
505 /* add value */ 502 /* add value */
506 sprintf(buffer_value, "%04x_value", 503 value_name = kasprintf(GFP_KERNEL, "%04x_value",
507 da_tokens[i].tokenID); 504 da_tokens[i].tokenID);
508 value_name = kstrdup(buffer_value, GFP_KERNEL);
509 if (value_name == NULL) 505 if (value_name == NULL)
510 goto loop_fail_create_value; 506 goto loop_fail_create_value;
511 sysfs_attr_init(&token_value_attrs[i].attr); 507 sysfs_attr_init(&token_value_attrs[i].attr);