Skip to content

Commit 3c34471

Browse files
neosys007ij-intel
authored andcommitted
platform/x86: dell-wmi-sysman: bound enumeration string aggregation
populate_enum_data() aggregates firmware-provided value-modifier and possible-value strings into fixed 512-byte struct members. The current code bounds each individual source string but then appends every string and separator with raw strcat() and no remaining-space check. Switch the aggregation loops to a bounded append helper and reject enumeration packages whose combined strings do not fit in the destination buffers. Fixes: e8a60aa ("platform/x86: Introduce support for Systems Management Driver over WMI for Dell Systems") Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn> Link: https://patch.msgid.link/20260408084501.1-dell-wmi-sysman-v2-pengpeng@iscas.ac.cn [ij: add include] Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
1 parent e8c5973 commit 3c34471

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

drivers/platform/x86/dell/dell-wmi-sysman/enum-attributes.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,32 @@
66
* Copyright (c) 2020 Dell Inc.
77
*/
88

9+
#include <linux/bug.h>
10+
911
#include "dell-wmi-sysman.h"
1012

1113
get_instance_id(enumeration);
1214

15+
static int append_enum_string(char *dest, const char *src)
16+
{
17+
size_t dest_len = strlen(dest);
18+
ssize_t copied;
19+
20+
if (WARN_ON_ONCE(dest_len >= MAX_BUFF))
21+
return -EINVAL;
22+
23+
copied = strscpy(dest + dest_len, src, MAX_BUFF - dest_len);
24+
if (copied < 0)
25+
return -EINVAL;
26+
27+
dest_len += copied;
28+
copied = strscpy(dest + dest_len, ";", MAX_BUFF - dest_len);
29+
if (copied < 0)
30+
return -EINVAL;
31+
32+
return 0;
33+
}
34+
1335
static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
1436
{
1537
int instance_id = get_enumeration_instance_id(kobj);
@@ -176,9 +198,9 @@ int populate_enum_data(union acpi_object *enumeration_obj, int instance_id,
176198
return -EINVAL;
177199
if (check_property_type(enumeration, next_obj, ACPI_TYPE_STRING))
178200
return -EINVAL;
179-
strcat(wmi_priv.enumeration_data[instance_id].dell_value_modifier,
180-
enumeration_obj[next_obj++].string.pointer);
181-
strcat(wmi_priv.enumeration_data[instance_id].dell_value_modifier, ";");
201+
if (append_enum_string(wmi_priv.enumeration_data[instance_id].dell_value_modifier,
202+
enumeration_obj[next_obj++].string.pointer))
203+
return -EINVAL;
182204
}
183205

184206
if (next_obj >= enum_property_count)
@@ -193,9 +215,9 @@ int populate_enum_data(union acpi_object *enumeration_obj, int instance_id,
193215
return -EINVAL;
194216
if (check_property_type(enumeration, next_obj, ACPI_TYPE_STRING))
195217
return -EINVAL;
196-
strcat(wmi_priv.enumeration_data[instance_id].possible_values,
197-
enumeration_obj[next_obj++].string.pointer);
198-
strcat(wmi_priv.enumeration_data[instance_id].possible_values, ";");
218+
if (append_enum_string(wmi_priv.enumeration_data[instance_id].possible_values,
219+
enumeration_obj[next_obj++].string.pointer))
220+
return -EINVAL;
199221
}
200222

201223
return sysfs_create_group(attr_name_kobj, &enumeration_attr_group);

0 commit comments

Comments
 (0)