platform/x86: hp-bioscfg: fix a signedness bug in hp_wmi_perform_query()
Subsystems (3)
PATCH 1/3 platform/x86: hp-bioscfg: fix a signedness bug in hp_wmi_perform_query()
The error handling won't work if "mid" is unsigned. "ret" is used to store negative error codes and declaring it as a u32 won't cause a bug but it's ugly. The "actual_outsize" variable is a number between 0-4096 so it can be declared as int as well.
--- drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c +1 -1
@@ -123,7 +123,7 @@ int hp_wmi_perform_query(int query, enum hp_wmi_command command, void *buffer,struct bios_return *bios_return;union acpi_object *obj =NULL ;struct bios_args *args =NULL ; -u32 mid, actual_outsize, ret; +int mid, actual_outsize, ret;size_t bios_args_size; mid =hp_encode_outsize_for_pvsz (outsize);
Signature · 1 line
2.39.2
PATCH 1/1 platform/x86: hp-bioscfg: prevent a small buffer overflow
This function escapes certain special characters like \n. So if the last character in the string is a '\n' then it gets changed into two characters '\' and '\n'. But maybe we only have space for the '\' so we need to check for that.
The "conv_dst_size" variable is always less than or to equal the "size" variable. It's easier to just check "conv_dst_size" instead of checking both.
--- drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c +5 -2
@@ -94,12 +94,15 @@ int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_utf16s_to_utf8s (src, src_size,UTF16_HOST_ENDIAN , dst, conv_dst_size); dst[conv_dst_size] =0 ; -for (i =0 ; i < size && i < conv_dst_size; i++) { +for (i =0 ; i < conv_dst_size; i++) {if (*src =='\\' || *src =='\r' || *src =='\n' || - *src =='\t' ) + *src =='\t' ) { dst[i++] ='\\' ; +if (i == conv_dst_size) +break ; + }if (*src =='\r' ) dst[i] ='r' ;
Signature · 1 line
2.39.2
RE: [PATCH] platform/x86: hp-bioscfg: prevent a small buffer overflow
Regards,
Jorge Lopez
HP Inc
"Once you stop learning, you start dying"
Albert Einstein
Quoted 51 lines
-----Original Message-----
From: Dan Carpenter <[email protected]>
Sent: Tuesday, July 18, 2023 2:06 AM
To: Lopez, Jorge A (Security) <[email protected]>
Cc: Hans de Goede <[email protected]>; Mark Gross <[email protected]>; Thomas Weißschuh <[email protected]>; [email protected]; [email protected]
Subject: [PATCH] platform/x86: hp-bioscfg: prevent a small buffer overflowCAUTION: External Email
This function escapes certain special characters like \n. So if the last character in the string is a '\n' then it gets changed into two characters '\' and '\n'. But maybe we only have space for the '\' so we need to check for that.
The "
conv_dst_size" variable is always less than or to equal the "size" variable. It's easier to just check "conv_dst_size" instead of checking both.Fixes a34fc329b189 ("platform/x86: hp-bioscfg: bioscfg")Signed-off-by Dan Carpenter <[email protected]>--- drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/platform/x86/hp/hp-bioscfg/bioscfg.c +5
-2@@ -94,12 +94,15 @@ int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_utf16s_to_utf8s (src ,src_size ,UTF16_HOST_ENDIAN ,dst ,conv_dst_size ); dst[conv_dst_size] =0 ; -for (i =0 ; i < size && i < conv_dst_size; i++) { +for (i =0 ; i < conv_dst_size; i++) {if (*src =='\\' || *src =='\r' || *src =='\n' || - *src =='\t' ) + *src =='\t' ) { dst[i++] ='\\' ; +if (i == conv_dst_size) +break ; + }if (*src =='\r' )dst[i] = 'r';--
2.39.2
PATCH 3/3 platform/x86: hp-bioscfg: fix error reporting in hp_add_other_attributes()
In reply to Dan CarpenterReturn a negative error code instead of returning success.
--- drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c +5 -0
@@ -630,13 +630,18 @@ static int hp_add_other_attributes(int attr_type)switch (attr_type) {case HPWMI_SECURE_PLATFORM_TYPE : ret =hp_populate_secure_platform_data (attr_name_kobj); +if (ret) + goto err_other_attr_init;break ;case HPWMI_SURE_START_TYPE : ret =hp_populate_sure_start_data (attr_name_kobj); +if (ret) + goto err_other_attr_init;break ;default : + ret = -EINVAL ; goto err_other_attr_init; }
Signature · 1 line
2.39.2
RE: [PATCH 3/3] platform/x86: hp-bioscfg: fix error reporting in hp_add_other_attributes()
Regards,
Jorge Lopez
HP Inc
"Once you stop learning, you start dying"
Albert Einstein
Quoted 46 lines
-----Original Message-----
From: Dan Carpenter <[email protected]>
Sent: Tuesday, July 18, 2023 2:06 AM
To: Lopez, Jorge A (Security) <[email protected]>
Cc: Hans de Goede <[email protected]>; Mark Gross <[email protected]>; Thomas Weißschuh <[email protected]>; [email protected]; [email protected]
Subject: [PATCH 3/3] platform/x86: hp-bioscfg: fix error reporting inhp_add_other_attributes()CAUTION: External Email
Return a negative error code instead of returning success.
Fixes a34fc329b189 ("platform/x86: hp-bioscfg: bioscfg")Signed-off-by Dan Carpenter <[email protected]>--- drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/platform/x86/hp/hp-bioscfg/bioscfg.c +5
-1@@ -630,13 +630,18 @@ static int hp_add_other_attributes(int attr_type)switch (attr_type) {case HPWMI_SECURE_PLATFORM_TYPE : ret =hp_populate_secure_platform_data (attr_name_kobj); +if (ret) + goto err_other_attr_init;break ;case HPWMI_SURE_START_TYPE : ret =hp_populate_sure_start_data (attr_name_kobj); +if (ret) + goto err_other_attr_init;break ;default : + ret = -EINVAL ; goto err_other_attr_init; } --2.39.2
Regards,
Jorge Lopez
HP Inc
"Once you stop learning, you start dying"
Albert Einstein
Quoted 40 lines
-----Original Message-----
From: Dan Carpenter <[email protected]>
Sent: Tuesday, July 18, 2023 2:05 AM
To: Lopez, Jorge A (Security) <[email protected]>
Cc: Hans de Goede <[email protected]>; Mark Gross <[email protected]>; Thomas Weißschuh <[email protected]>; [email protected]; [email protected]
Subject: [PATCH 1/3] platform/x86: hp-bioscfg: fix a signedness bug inhp_wmi_perform_query()CAUTION: External Email
The error handling won't work if "mid" is unsigned. "ret" is used to store negative error codes and declaring it as a u32 won't cause a bug but it's ugly. The "
actual_outsize" variable is a number between 0-4096 so it can be declared as int as well.Fixes 69ea03e38f24 ("platform/x86: hp-bioscfg: biosattr-interface")Signed-off-by Dan Carpenter <[email protected]>--- drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c +1
-1@@ -123,7 +123,7 @@ int hp_wmi_perform_query(int query, enum hp_wmi_command command, void *buffer, struct bios_return *bios_return;union acpi_object *obj =NULL ;struct bios_args *args =NULL ; -u32 mid, actual_outsize, ret; +int mid, actual_outsize, ret;size_t bios_args_size;mid = hp_encode_outsize_for_pvsz(outsize);--
2.39.2
Hi,
Quoted 7 lines · Dan Carpenter
The error handling won't work if "mid" is unsigned. "ret" is used to store negative error codes and declaring it as a u32 won't cause a bug but it's ugly. The "
actual_outsize" variable is a number between 0-4096 so it can be declared as int as well.Fixes 69ea03e38f24 ("platform/x86: hp-bioscfg: biosattr-interface")Signed-off-by Dan Carpenter <[email protected]>
Thank you for your patch-series, I've applied the series to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans
Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.
Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.
Regards,
Hans
Quoted 17 lines
--- drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c +1
-1@@ -123,7 +123,7 @@ int hp_wmi_perform_query(int query, enum hp_wmi_command command, void *buffer,struct bios_return *bios_return;union acpi_object *obj =NULL ;struct bios_args *args =NULL ; -u32 mid, actual_outsize, ret; +int mid, actual_outsize, ret;size_t bios_args_size; mid =hp_encode_outsize_for_pvsz (outsize);