2022-12-14 15:08:50

by Ilpo Järvinen

[permalink] [raw]
Subject: [PATCH v2 1/1] fpga: m10bmc-sec: Fix probe rollback

Handle probe error rollbacks properly to avoid leaks.

Fixes: 5cd339b370e2 ("fpga: m10bmc-sec: add max10 secure update functions")
Reviewed-by: Matthew Gerlach <[email protected]>
Reviewed-by: Russ Weight <[email protected]>
Reviewed-by: Marco Pagani <[email protected]>
Signed-off-by: Ilpo Järvinen <[email protected]>
---
I don't know if the previous one fell through cracks so resending this.

v2:
- Resending v1 with Marco's Rev-by

drivers/fpga/intel-m10-bmc-sec-update.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/fpga/intel-m10-bmc-sec-update.c b/drivers/fpga/intel-m10-bmc-sec-update.c
index 79d48852825e..03f1bd81c434 100644
--- a/drivers/fpga/intel-m10-bmc-sec-update.c
+++ b/drivers/fpga/intel-m10-bmc-sec-update.c
@@ -574,20 +574,27 @@ static int m10bmc_sec_probe(struct platform_device *pdev)
len = scnprintf(buf, SEC_UPDATE_LEN_MAX, "secure-update%d",
sec->fw_name_id);
sec->fw_name = kmemdup_nul(buf, len, GFP_KERNEL);
- if (!sec->fw_name)
- return -ENOMEM;
+ if (!sec->fw_name) {
+ ret = -ENOMEM;
+ goto fw_name_fail;
+ }

fwl = firmware_upload_register(THIS_MODULE, sec->dev, sec->fw_name,
&m10bmc_ops, sec);
if (IS_ERR(fwl)) {
dev_err(sec->dev, "Firmware Upload driver failed to start\n");
- kfree(sec->fw_name);
- xa_erase(&fw_upload_xa, sec->fw_name_id);
- return PTR_ERR(fwl);
+ ret = PTR_ERR(fwl);
+ goto fw_uploader_fail;
}

sec->fwl = fwl;
return 0;
+
+fw_uploader_fail:
+ kfree(sec->fw_name);
+fw_name_fail:
+ xa_erase(&fw_upload_xa, sec->fw_name_id);
+ return ret;
}

static int m10bmc_sec_remove(struct platform_device *pdev)
--
2.30.2


2022-12-16 09:40:44

by Xu Yilun

[permalink] [raw]
Subject: Re: [PATCH v2 1/1] fpga: m10bmc-sec: Fix probe rollback

On 2022-12-14 at 16:49:52 +0200, Ilpo J?rvinen wrote:
> Handle probe error rollbacks properly to avoid leaks.
>
> Fixes: 5cd339b370e2 ("fpga: m10bmc-sec: add max10 secure update functions")
> Reviewed-by: Matthew Gerlach <[email protected]>
> Reviewed-by: Russ Weight <[email protected]>
> Reviewed-by: Marco Pagani <[email protected]>
> Signed-off-by: Ilpo J?rvinen <[email protected]>
> ---
> I don't know if the previous one fell through cracks so resending this.

I'll pick this when v6.2-rc1 comes.

Acked-by: Xu Yilun <[email protected]>

>
> v2:
> - Resending v1 with Marco's Rev-by
>
> drivers/fpga/intel-m10-bmc-sec-update.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/fpga/intel-m10-bmc-sec-update.c b/drivers/fpga/intel-m10-bmc-sec-update.c
> index 79d48852825e..03f1bd81c434 100644
> --- a/drivers/fpga/intel-m10-bmc-sec-update.c
> +++ b/drivers/fpga/intel-m10-bmc-sec-update.c
> @@ -574,20 +574,27 @@ static int m10bmc_sec_probe(struct platform_device *pdev)
> len = scnprintf(buf, SEC_UPDATE_LEN_MAX, "secure-update%d",
> sec->fw_name_id);
> sec->fw_name = kmemdup_nul(buf, len, GFP_KERNEL);
> - if (!sec->fw_name)
> - return -ENOMEM;
> + if (!sec->fw_name) {
> + ret = -ENOMEM;
> + goto fw_name_fail;
> + }
>
> fwl = firmware_upload_register(THIS_MODULE, sec->dev, sec->fw_name,
> &m10bmc_ops, sec);
> if (IS_ERR(fwl)) {
> dev_err(sec->dev, "Firmware Upload driver failed to start\n");
> - kfree(sec->fw_name);
> - xa_erase(&fw_upload_xa, sec->fw_name_id);
> - return PTR_ERR(fwl);
> + ret = PTR_ERR(fwl);
> + goto fw_uploader_fail;
> }
>
> sec->fwl = fwl;
> return 0;
> +
> +fw_uploader_fail:
> + kfree(sec->fw_name);
> +fw_name_fail:
> + xa_erase(&fw_upload_xa, sec->fw_name_id);
> + return ret;
> }
>
> static int m10bmc_sec_remove(struct platform_device *pdev)
> --
> 2.30.2
>

2022-12-26 04:20:25

by Xu Yilun

[permalink] [raw]
Subject: Re: [PATCH v2 1/1] fpga: m10bmc-sec: Fix probe rollback

On 2022-12-14 at 16:49:52 +0200, Ilpo J?rvinen wrote:
> Handle probe error rollbacks properly to avoid leaks.
>
> Fixes: 5cd339b370e2 ("fpga: m10bmc-sec: add max10 secure update functions")
> Reviewed-by: Matthew Gerlach <[email protected]>
> Reviewed-by: Russ Weight <[email protected]>
> Reviewed-by: Marco Pagani <[email protected]>
> Signed-off-by: Ilpo J?rvinen <[email protected]>

I assume this should be in stable kernel, so

Cc: [email protected]

If OK, I could add it myself.

Thanks,
Yilun

> ---
> I don't know if the previous one fell through cracks so resending this.
>
> v2:
> - Resending v1 with Marco's Rev-by
>
> drivers/fpga/intel-m10-bmc-sec-update.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/fpga/intel-m10-bmc-sec-update.c b/drivers/fpga/intel-m10-bmc-sec-update.c
> index 79d48852825e..03f1bd81c434 100644
> --- a/drivers/fpga/intel-m10-bmc-sec-update.c
> +++ b/drivers/fpga/intel-m10-bmc-sec-update.c
> @@ -574,20 +574,27 @@ static int m10bmc_sec_probe(struct platform_device *pdev)
> len = scnprintf(buf, SEC_UPDATE_LEN_MAX, "secure-update%d",
> sec->fw_name_id);
> sec->fw_name = kmemdup_nul(buf, len, GFP_KERNEL);
> - if (!sec->fw_name)
> - return -ENOMEM;
> + if (!sec->fw_name) {
> + ret = -ENOMEM;
> + goto fw_name_fail;
> + }
>
> fwl = firmware_upload_register(THIS_MODULE, sec->dev, sec->fw_name,
> &m10bmc_ops, sec);
> if (IS_ERR(fwl)) {
> dev_err(sec->dev, "Firmware Upload driver failed to start\n");
> - kfree(sec->fw_name);
> - xa_erase(&fw_upload_xa, sec->fw_name_id);
> - return PTR_ERR(fwl);
> + ret = PTR_ERR(fwl);
> + goto fw_uploader_fail;
> }
>
> sec->fwl = fwl;
> return 0;
> +
> +fw_uploader_fail:
> + kfree(sec->fw_name);
> +fw_name_fail:
> + xa_erase(&fw_upload_xa, sec->fw_name_id);
> + return ret;
> }
>
> static int m10bmc_sec_remove(struct platform_device *pdev)
> --
> 2.30.2
>

2022-12-26 18:17:41

by Ilpo Järvinen

[permalink] [raw]
Subject: Re: [PATCH v2 1/1] fpga: m10bmc-sec: Fix probe rollback

On Mon, 26 Dec 2022, Xu Yilun wrote:

> On 2022-12-14 at 16:49:52 +0200, Ilpo J?rvinen wrote:
> > Handle probe error rollbacks properly to avoid leaks.
> >
> > Fixes: 5cd339b370e2 ("fpga: m10bmc-sec: add max10 secure update functions")
> > Reviewed-by: Matthew Gerlach <[email protected]>
> > Reviewed-by: Russ Weight <[email protected]>
> > Reviewed-by: Marco Pagani <[email protected]>
> > Signed-off-by: Ilpo J?rvinen <[email protected]>
>
> I assume this should be in stable kernel, so
>
> Cc: [email protected]
>
> If OK, I could add it myself.

Yes, it should have been there but I forgot it.

Please add it like you suggested. Thanks.

--
i.

> > ---
> > I don't know if the previous one fell through cracks so resending this.
> >
> > v2:
> > - Resending v1 with Marco's Rev-by
> >
> > drivers/fpga/intel-m10-bmc-sec-update.c | 17 ++++++++++++-----
> > 1 file changed, 12 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/fpga/intel-m10-bmc-sec-update.c b/drivers/fpga/intel-m10-bmc-sec-update.c
> > index 79d48852825e..03f1bd81c434 100644
> > --- a/drivers/fpga/intel-m10-bmc-sec-update.c
> > +++ b/drivers/fpga/intel-m10-bmc-sec-update.c
> > @@ -574,20 +574,27 @@ static int m10bmc_sec_probe(struct platform_device *pdev)
> > len = scnprintf(buf, SEC_UPDATE_LEN_MAX, "secure-update%d",
> > sec->fw_name_id);
> > sec->fw_name = kmemdup_nul(buf, len, GFP_KERNEL);
> > - if (!sec->fw_name)
> > - return -ENOMEM;
> > + if (!sec->fw_name) {
> > + ret = -ENOMEM;
> > + goto fw_name_fail;
> > + }
> >
> > fwl = firmware_upload_register(THIS_MODULE, sec->dev, sec->fw_name,
> > &m10bmc_ops, sec);
> > if (IS_ERR(fwl)) {
> > dev_err(sec->dev, "Firmware Upload driver failed to start\n");
> > - kfree(sec->fw_name);
> > - xa_erase(&fw_upload_xa, sec->fw_name_id);
> > - return PTR_ERR(fwl);
> > + ret = PTR_ERR(fwl);
> > + goto fw_uploader_fail;
> > }
> >
> > sec->fwl = fwl;
> > return 0;
> > +
> > +fw_uploader_fail:
> > + kfree(sec->fw_name);
> > +fw_name_fail:
> > + xa_erase(&fw_upload_xa, sec->fw_name_id);
> > + return ret;
> > }
> >
> > static int m10bmc_sec_remove(struct platform_device *pdev)
> > --
> > 2.30.2
> >
>