public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix  dereferencing freed memory 'fw'
@ 2024-09-22 10:52 Dipendra Khadka
  2024-09-23  8:20 ` Heikki Krogerus
  2024-09-23  8:35 ` Heikki Krogerus
  0 siblings, 2 replies; 4+ messages in thread
From: Dipendra Khadka @ 2024-09-22 10:52 UTC (permalink / raw)
  To: heikki.krogerus, gregkh; +Cc: Dipendra Khadka, linux-usb, linux-kernel

smatch reported dereferencing freed memory as below:
'''
drivers/usb/typec/tipd/core.c:1196 tps6598x_apply_patch() error: dereferencing freed memory 'fw'
'''

Invoking release_firware(fw) just after checking ret.

Signed-off-by: Dipendra Khadka <kdipendra88@gmail.com>
---
 drivers/usb/typec/tipd/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
index ea768b19a7f1..eb5596e3406a 100644
--- a/drivers/usb/typec/tipd/core.c
+++ b/drivers/usb/typec/tipd/core.c
@@ -1191,11 +1191,11 @@ static int tps6598x_apply_patch(struct tps6598x *tps)
 	dev_info(tps->dev, "Firmware update succeeded\n");
 
 release_fw:
-	release_firmware(fw);
 	if (ret) {
 		dev_err(tps->dev, "Failed to write patch %s of %zu bytes\n",
 			firmware_name, fw->size);
 	}
+	release_firmware(fw);
 
 	return ret;
 };
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix  dereferencing freed memory 'fw'
  2024-09-22 10:52 [PATCH] Fix dereferencing freed memory 'fw' Dipendra Khadka
@ 2024-09-23  8:20 ` Heikki Krogerus
  2024-09-23  8:35 ` Heikki Krogerus
  1 sibling, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2024-09-23  8:20 UTC (permalink / raw)
  To: Dipendra Khadka; +Cc: gregkh, linux-usb, linux-kernel

Hi Dipendra,

Thanks for the patch. You forgot the susbsytem and driver from your
subject line:
https://docs.kernel.org/process/submitting-patches.html#the-canonical-patch-format

On Sun, Sep 22, 2024 at 10:52:11AM +0000, Dipendra Khadka wrote:
> smatch reported dereferencing freed memory as below:
> '''
> drivers/usb/typec/tipd/core.c:1196 tps6598x_apply_patch() error: dereferencing freed memory 'fw'
> '''
> 
> Invoking release_firware(fw) just after checking ret.
> 
> Signed-off-by: Dipendra Khadka <kdipendra88@gmail.com>

This is a use-after-free case, so please add the Fixes tag:

Fixes: 916b8e5fa73d ("usb: typec: tipd: add error log to provide firmware name and size")

> ---
>  drivers/usb/typec/tipd/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> index ea768b19a7f1..eb5596e3406a 100644
> --- a/drivers/usb/typec/tipd/core.c
> +++ b/drivers/usb/typec/tipd/core.c
> @@ -1191,11 +1191,11 @@ static int tps6598x_apply_patch(struct tps6598x *tps)
>  	dev_info(tps->dev, "Firmware update succeeded\n");
>  
>  release_fw:
> -	release_firmware(fw);
>  	if (ret) {
>  		dev_err(tps->dev, "Failed to write patch %s of %zu bytes\n",
>  			firmware_name, fw->size);
>  	}
> +	release_firmware(fw);
>  
>  	return ret;
>  };
> -- 
> 2.43.0

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix  dereferencing freed memory 'fw'
  2024-09-22 10:52 [PATCH] Fix dereferencing freed memory 'fw' Dipendra Khadka
  2024-09-23  8:20 ` Heikki Krogerus
@ 2024-09-23  8:35 ` Heikki Krogerus
  2024-09-23  8:45   ` Dipendra Khadka
  1 sibling, 1 reply; 4+ messages in thread
From: Heikki Krogerus @ 2024-09-23  8:35 UTC (permalink / raw)
  To: Dipendra Khadka; +Cc: gregkh, linux-usb, linux-kernel

On Sun, Sep 22, 2024 at 10:52:11AM +0000, Dipendra Khadka wrote:
> smatch reported dereferencing freed memory as below:
> '''
> drivers/usb/typec/tipd/core.c:1196 tps6598x_apply_patch() error: dereferencing freed memory 'fw'
> '''

This is only my opinion, but I don't like those '''single triple
quotes''' in commit messages - they are just confusing. You don't need
to use any kind of quotation marks in cases like this IMO.

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix dereferencing freed memory 'fw'
  2024-09-23  8:35 ` Heikki Krogerus
@ 2024-09-23  8:45   ` Dipendra Khadka
  0 siblings, 0 replies; 4+ messages in thread
From: Dipendra Khadka @ 2024-09-23  8:45 UTC (permalink / raw)
  To: Heikki Krogerus; +Cc: gregkh, linux-usb, linux-kernel

Hi Heikki,

On Mon, 23 Sept 2024 at 14:20, Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
>
> On Sun, Sep 22, 2024 at 10:52:11AM +0000, Dipendra Khadka wrote:
> > smatch reported dereferencing freed memory as below:
> > '''
> > drivers/usb/typec/tipd/core.c:1196 tps6598x_apply_patch() error: dereferencing freed memory 'fw'
> > '''
>
> This is only my opinion, but I don't like those '''single triple
> quotes''' in commit messages - they are just confusing. You don't need
> to use any kind of quotation marks in cases like this IMO.
>

Thanks for the feedback. I will send v2.

> thanks,
>
> --
> heikki

Best Regards,
Dipendra Khadka

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-09-23  8:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-22 10:52 [PATCH] Fix dereferencing freed memory 'fw' Dipendra Khadka
2024-09-23  8:20 ` Heikki Krogerus
2024-09-23  8:35 ` Heikki Krogerus
2024-09-23  8:45   ` Dipendra Khadka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox