2023-09-23 00:30:56

by Joseph, Jithu

[permalink] [raw]
Subject: [PATCH v2 5/9] platform/x86/intel/ifs: Validate image size

Perform additional validation prior to loading IFS image.

Error out if the size of the file being loaded doesn't match the size
specified in the header.

Signed-off-by: Jithu Joseph <[email protected]>
Reviewed-by: Tony Luck <[email protected]>
Tested-by: Pengfei Xu <[email protected]>
---
drivers/platform/x86/intel/ifs/load.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/platform/x86/intel/ifs/load.c b/drivers/platform/x86/intel/ifs/load.c
index 6b827247945b..b09106034fac 100644
--- a/drivers/platform/x86/intel/ifs/load.c
+++ b/drivers/platform/x86/intel/ifs/load.c
@@ -375,6 +375,7 @@ int ifs_load_firmware(struct device *dev)
{
const struct ifs_test_caps *test = ifs_get_test_caps(dev);
struct ifs_data *ifsd = ifs_get_data(dev);
+ unsigned int expected_size;
const struct firmware *fw;
char scan_path[64];
int ret = -EINVAL;
@@ -389,6 +390,13 @@ int ifs_load_firmware(struct device *dev)
goto done;
}

+ expected_size = ((struct microcode_header_intel *)fw->data)->totalsize;
+ if (fw->size != expected_size) {
+ dev_err(dev, "File size mismatch (expected %d, actual %ld). Corrupted IFS image.\n",
+ expected_size, fw->size);
+ return -EBADFD;
+ }
+
ret = image_sanity_check(dev, (struct microcode_header_intel *)fw->data);
if (ret)
goto release;
--
2.25.1


2023-09-25 17:10:16

by Ilpo Järvinen

[permalink] [raw]
Subject: Re: [PATCH v2 5/9] platform/x86/intel/ifs: Validate image size

On Fri, 22 Sep 2023, Jithu Joseph wrote:

> Perform additional validation prior to loading IFS image.
>
> Error out if the size of the file being loaded doesn't match the size
> specified in the header.
>
> Signed-off-by: Jithu Joseph <[email protected]>
> Reviewed-by: Tony Luck <[email protected]>
> Tested-by: Pengfei Xu <[email protected]>
> ---
> drivers/platform/x86/intel/ifs/load.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/platform/x86/intel/ifs/load.c b/drivers/platform/x86/intel/ifs/load.c
> index 6b827247945b..b09106034fac 100644
> --- a/drivers/platform/x86/intel/ifs/load.c
> +++ b/drivers/platform/x86/intel/ifs/load.c
> @@ -375,6 +375,7 @@ int ifs_load_firmware(struct device *dev)
> {
> const struct ifs_test_caps *test = ifs_get_test_caps(dev);
> struct ifs_data *ifsd = ifs_get_data(dev);
> + unsigned int expected_size;
> const struct firmware *fw;
> char scan_path[64];
> int ret = -EINVAL;
> @@ -389,6 +390,13 @@ int ifs_load_firmware(struct device *dev)
> goto done;
> }
>
> + expected_size = ((struct microcode_header_intel *)fw->data)->totalsize;
> + if (fw->size != expected_size) {
> + dev_err(dev, "File size mismatch (expected %d, actual %ld). Corrupted IFS image.\n",
> + expected_size, fw->size);
> + return -EBADFD;

I don't think this error code is best suited for what occurred. I guess
returning just -EINVAL would be fine.

--
i.

> + }
> +
> ret = image_sanity_check(dev, (struct microcode_header_intel *)fw->data);
> if (ret)
> goto release;
>

2023-09-25 22:30:42

by Joseph, Jithu

[permalink] [raw]
Subject: Re: [PATCH v2 5/9] platform/x86/intel/ifs: Validate image size



On 9/25/2023 8:43 AM, Ilpo Järvinen wrote:
> On Fri, 22 Sep 2023, Jithu Joseph wrote:
>
>> Perform additional validation prior to loading IFS image.
>>
>> Error out if the size of the file being loaded doesn't match the size
>> specified in the header.
>>
>> Signed-off-by: Jithu Joseph <[email protected]>
>> Reviewed-by: Tony Luck <[email protected]>
>> Tested-by: Pengfei Xu <[email protected]>
>> ---
>> drivers/platform/x86/intel/ifs/load.c | 8 ++++++++
>> 1 file changed, 8 insertions(+)
>>
>> diff --git a/drivers/platform/x86/intel/ifs/load.c b/drivers/platform/x86/intel/ifs/load.c
>> index 6b827247945b..b09106034fac 100644
>> --- a/drivers/platform/x86/intel/ifs/load.c
>> +++ b/drivers/platform/x86/intel/ifs/load.c
>> @@ -375,6 +375,7 @@ int ifs_load_firmware(struct device *dev)
>> {
>> const struct ifs_test_caps *test = ifs_get_test_caps(dev);
>> struct ifs_data *ifsd = ifs_get_data(dev);
>> + unsigned int expected_size;
>> const struct firmware *fw;
>> char scan_path[64];
>> int ret = -EINVAL;
>> @@ -389,6 +390,13 @@ int ifs_load_firmware(struct device *dev)
>> goto done;
>> }
>>
>> + expected_size = ((struct microcode_header_intel *)fw->data)->totalsize;
>> + if (fw->size != expected_size) {
>> + dev_err(dev, "File size mismatch (expected %d, actual %ld). Corrupted IFS image.\n",
>> + expected_size, fw->size);
>> + return -EBADFD;
>
> I don't think this error code is best suited for what occurred. I guess
> returning just -EINVAL would be fine.

Will change

Jithu