platform/x86: dell-wmi-sysman: replace deprecated strlcpy with strscpy
Subsystems (2)
PATCH v3 1/1 platform/x86: dell-wmi-sysman: replace deprecated strlcpy with strscpy
The kernel has deprecated the use of strlcpy wrappers in favor of the safer strscpy variants. Replace the internal driver helper function strlcpy_attr() with strscpy_attr() across all dell-wmi-sysman attribute parser files.
Ensure explicit destination buffer sizes are passed using sizeof() to prevent potential out-of-bounds array writes during ACPI object evaluations.
Signed-off-by Ava Green <[email protected]>
---
Changes in v3:
- Fix kernel doc formatting (reported by kernel robot) Changes in v2:
- Send accidently, Please ignore this version
.../dell/dell-wmi-sysman/dell-wmi-sysman.h | 2 +- .../dell/dell-wmi-sysman/enum-attributes.c | 25 +++++++++++-------- .../x86/dell/dell-wmi-sysman/int-attributes.c | 20 +++++++++------ .../dell/dell-wmi-sysman/passobj-attributes.c | 5 ++-- .../dell/dell-wmi-sysman/string-attributes.c | 25 +++++++++++-------- .../x86/dell/dell-wmi-sysman/sysman.c | 18 ++++++------- 6 files changed, 54 insertions(+), 41 deletions(-)
drivers/platform/x86/dell/dell-wmi-sysman/dell-wmi-sysman.h +1 -1
@@ -162,7 +162,7 @@ static ssize_t curr_val##_store(struct kobject *kobj, \union acpi_object *get_wmiobj_pointer (int instance_id,const char *guid_string);int get_instance_count (const char *guid_string); -void strlcpy_attr (char *dest,char *src); +int strscpy_attr (char *dest,char *src,size_t size);int populate_enum_data (union acpi_object *enumeration_obj,int instance_id,struct kobject *attr_name_kobj,u32 enum_property_count);
drivers/platform/x86/dell/dell-wmi-sysman/enum-attributes.c +15 -10
@@ -165,24 +165,29 @@ int populate_enum_data(union acpi_object *enumeration_obj, int instance_id, wmi_priv.enumeration_data[instance_id].attr_name_kobj = attr_name_kobj;if (check_property_type (enumeration,ATTR_NAME ,ACPI_TYPE_STRING ))return -EINVAL ; -strlcpy_attr (wmi_priv.enumeration_data[instance_id].attribute_name, - enumeration_obj[ATTR_NAME ].string.pointer); +strscpy_attr (wmi_priv.enumeration_data[instance_id].attribute_name, + enumeration_obj[ATTR_NAME ].string.pointer, +sizeof (wmi_priv.enumeration_data[instance_id].attribute_name));if (check_property_type (enumeration,DISPL_NAME_LANG_CODE ,ACPI_TYPE_STRING ))return -EINVAL ; -strlcpy_attr (wmi_priv.enumeration_data[instance_id].display_name_language_code, - enumeration_obj[DISPL_NAME_LANG_CODE ].string.pointer); +strscpy_attr (wmi_priv.enumeration_data[instance_id].display_name_language_code, + enumeration_obj[DISPL_NAME_LANG_CODE ].string.pointer, +sizeof (wmi_priv.enumeration_data[instance_id].display_name_language_code));if (check_property_type (enumeration,DISPLAY_NAME ,ACPI_TYPE_STRING ))return -EINVAL ; -strlcpy_attr (wmi_priv.enumeration_data[instance_id].display_name, - enumeration_obj[DISPLAY_NAME ].string.pointer); +strscpy_attr (wmi_priv.enumeration_data[instance_id].display_name, + enumeration_obj[DISPLAY_NAME ].string.pointer, +sizeof (wmi_priv.enumeration_data[instance_id].display_name));if (check_property_type (enumeration,DEFAULT_VAL ,ACPI_TYPE_STRING ))return -EINVAL ; -strlcpy_attr (wmi_priv.enumeration_data[instance_id].default_value, - enumeration_obj[DEFAULT_VAL ].string.pointer); +strscpy_attr (wmi_priv.enumeration_data[instance_id].default_value, + enumeration_obj[DEFAULT_VAL ].string.pointer, +sizeof (wmi_priv.enumeration_data[instance_id].default_value));if (check_property_type (enumeration,MODIFIER ,ACPI_TYPE_STRING ))return -EINVAL ; -strlcpy_attr (wmi_priv.enumeration_data[instance_id].dell_modifier, - enumeration_obj[MODIFIER ].string.pointer); +strscpy_attr (wmi_priv.enumeration_data[instance_id].dell_modifier, + enumeration_obj[MODIFIER ].string.pointer, +sizeof (wmi_priv.enumeration_data[instance_id].dell_modifier)); next_obj =MODIFIER +1 ;
drivers/platform/x86/dell/dell-wmi-sysman/int-attributes.c +12 -8
@@ -144,24 +144,28 @@ int populate_int_data(union acpi_object *integer_obj, int instance_id, wmi_priv.integer_data[instance_id].attr_name_kobj = attr_name_kobj;if (check_property_type (integer,ATTR_NAME ,ACPI_TYPE_STRING ))return -EINVAL ; -strlcpy_attr (wmi_priv.integer_data[instance_id].attribute_name, - integer_obj[ATTR_NAME ].string.pointer); +strscpy_attr (wmi_priv.integer_data[instance_id].attribute_name, + integer_obj[ATTR_NAME ].string.pointer, +sizeof (wmi_priv.integer_data[instance_id].attribute_name));if (check_property_type (integer,DISPL_NAME_LANG_CODE ,ACPI_TYPE_STRING ))return -EINVAL ; -strlcpy_attr (wmi_priv.integer_data[instance_id].display_name_language_code, - integer_obj[DISPL_NAME_LANG_CODE ].string.pointer); +strscpy_attr (wmi_priv.integer_data[instance_id].display_name_language_code, + integer_obj[DISPL_NAME_LANG_CODE ].string.pointer, +sizeof (wmi_priv.integer_data[instance_id].display_name_language_code));if (check_property_type (integer,DISPLAY_NAME ,ACPI_TYPE_STRING ))return -EINVAL ; -strlcpy_attr (wmi_priv.integer_data[instance_id].display_name, - integer_obj[DISPLAY_NAME ].string.pointer); +strscpy_attr (wmi_priv.integer_data[instance_id].display_name, + integer_obj[DISPLAY_NAME ].string.pointer, +sizeof (wmi_priv.integer_data[instance_id].display_name));if (check_property_type (integer,DEFAULT_VAL ,ACPI_TYPE_INTEGER ))return -EINVAL ; wmi_priv.integer_data[instance_id].default_value = (uintptr_t )integer_obj[DEFAULT_VAL ].string.pointer;if (check_property_type (integer,MODIFIER ,ACPI_TYPE_STRING ))return -EINVAL ; -strlcpy_attr (wmi_priv.integer_data[instance_id].dell_modifier, - integer_obj[MODIFIER ].string.pointer); +strscpy_attr (wmi_priv.integer_data[instance_id].dell_modifier, + integer_obj[MODIFIER ].string.pointer, +sizeof (wmi_priv.integer_data[instance_id].dell_modifier));if (check_property_type (integer,MIN_VALUE ,ACPI_TYPE_INTEGER ))return -EINVAL ; wmi_priv.integer_data[instance_id].min_value =
drivers/platform/x86/dell/dell-wmi-sysman/passobj-attributes.c +3 -2
@@ -163,8 +163,9 @@ int populate_po_data(union acpi_object *po_obj, int instance_id, struct kobject wmi_priv.po_data[instance_id].attr_name_kobj = attr_name_kobj;if (check_property_type (po,ATTR_NAME ,ACPI_TYPE_STRING ))return -EINVAL ; -strlcpy_attr (wmi_priv.po_data[instance_id].attribute_name, - po_obj[ATTR_NAME ].string.pointer); +strscpy_attr (wmi_priv.po_data[instance_id].attribute_name, + po_obj[ATTR_NAME ].string.pointer, +sizeof (wmi_priv.po_data[instance_id].attribute_name));if (check_property_type (po,MIN_PASS_LEN ,ACPI_TYPE_INTEGER ))return -EINVAL ; wmi_priv.po_data[instance_id].min_password_length =
drivers/platform/x86/dell/dell-wmi-sysman/string-attributes.c +15 -10
@@ -128,24 +128,29 @@ int populate_str_data(union acpi_object *str_obj, int instance_id, struct kobjec wmi_priv.str_data[instance_id].attr_name_kobj = attr_name_kobj;if (check_property_type (str,ATTR_NAME ,ACPI_TYPE_STRING ))return -EINVAL ; -strlcpy_attr (wmi_priv.str_data[instance_id].attribute_name, - str_obj[ATTR_NAME ].string.pointer); +strscpy_attr (wmi_priv.str_data[instance_id].attribute_name, + str_obj[ATTR_NAME ].string.pointer, +sizeof (wmi_priv.str_data[instance_id].attribute_name));if (check_property_type (str,DISPL_NAME_LANG_CODE ,ACPI_TYPE_STRING ))return -EINVAL ; -strlcpy_attr (wmi_priv.str_data[instance_id].display_name_language_code, - str_obj[DISPL_NAME_LANG_CODE ].string.pointer); +strscpy_attr (wmi_priv.str_data[instance_id].display_name_language_code, + str_obj[DISPL_NAME_LANG_CODE ].string.pointer, +sizeof (wmi_priv.str_data[instance_id].display_name_language_code));if (check_property_type (str,DISPLAY_NAME ,ACPI_TYPE_STRING ))return -EINVAL ; -strlcpy_attr (wmi_priv.str_data[instance_id].display_name, - str_obj[DISPLAY_NAME ].string.pointer); +strscpy_attr (wmi_priv.str_data[instance_id].display_name, + str_obj[DISPLAY_NAME ].string.pointer, +sizeof (wmi_priv.str_data[instance_id].display_name));if (check_property_type (str,DEFAULT_VAL ,ACPI_TYPE_STRING ))return -EINVAL ; -strlcpy_attr (wmi_priv.str_data[instance_id].default_value, - str_obj[DEFAULT_VAL ].string.pointer); +strscpy_attr (wmi_priv.str_data[instance_id].default_value, + str_obj[DEFAULT_VAL ].string.pointer, +sizeof (wmi_priv.str_data[instance_id].default_value));if (check_property_type (str,MODIFIER ,ACPI_TYPE_STRING ))return -EINVAL ; -strlcpy_attr (wmi_priv.str_data[instance_id].dell_modifier, - str_obj[MODIFIER ].string.pointer); +strscpy_attr (wmi_priv.str_data[instance_id].dell_modifier, + str_obj[MODIFIER ].string.pointer, +sizeof (wmi_priv.str_data[instance_id].dell_modifier));if (check_property_type (str,MIN_LEN ,ACPI_TYPE_INTEGER ))return -EINVAL ; wmi_priv.str_data[instance_id].min_length = (uintptr_t )str_obj[MIN_LEN ].string.pointer;
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +8 -10
@@ -229,23 +229,21 @@ static const struct kobj_type attr_name_ktype = { .sysfs_ops = &kobj_sysfs_ops, }; +/** -* strlcpy_attr - Copy a length-limited, NULL-terminated string with bound checks +* strscpy_attr - Copy a length limited, NULL-terminated string with bound checks * @dest: Where to copy the string to * @src: Where to copy the string from +* @size: Size of the destination buffer */ -void strlcpy_attr (char *dest,char *src) +int strscpy_attr (char *dest,char *src,size_t size) { -size_t len =strlen (src) +1 ; - -if (len >1 && len <=MAX_BUFF ) -strscpy (dest, src, len); +ssize_t rc =strscpy (dest, src, size); -/*len can be zero because any property not-applicable to attribute can -* be empty so check only for too long buffers and log error -*/ -if (len >MAX_BUFF ) +if (rc == -E2BIG )pr_err ("Source string returned from BIOS is out of bound!\n" ); + +return rc; }/**
Signature · 1 line
2.56.0