public inbox for linux-wireless@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] wireless: mt76: mt7921: Fix use-after-free in fw features query.
@ 2023-03-08  1:00 greearb
  2023-03-08  9:09 ` Lorenzo Bianconi
  0 siblings, 1 reply; 2+ messages in thread
From: greearb @ 2023-03-08  1:00 UTC (permalink / raw)
  To: linux-wireless; +Cc: Ben Greear

From: Ben Greear <greearb@candelatech.com>

Stop referencing 'features' memory after release_firmware is called.

Fixes this crash:

RIP: 0010:mt7921_check_offload_capability+0x17d
mt7921_pci_probe+0xca/0x4b0
...

Signed-off-by: Ben Greear <greearb@candelatech.com>
---
 drivers/net/wireless/mediatek/mt76/mt7921/init.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/init.c b/drivers/net/wireless/mediatek/mt76/mt7921/init.c
index 38d6563cb12f..3b6fb1a6b351 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/init.c
@@ -171,6 +171,7 @@ u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm)
 	const struct firmware *fw;
 	int ret, i, offset = 0;
 	const u8 *data, *end;
+	u8 rv = 0;
 
 	ret = request_firmware(&fw, fw_wm, dev);
 	if (ret)
@@ -197,12 +198,17 @@ u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm)
 	data += sizeof(*rel_info);
 	end = data + le16_to_cpu(rel_info->len);
 
+	/* TODO:  This needs better sanity checking I think.
+	 * Likely a corrupted firmware with bad rel_info->len, for instance,
+	 * would blow this up.
+	 */
 	while (data < end) {
 		rel_info = (struct mt7921_realease_info *)data;
 		data += sizeof(*rel_info);
 
 		if (rel_info->tag == MT7921_FW_TAG_FEATURE) {
 			features = (struct mt7921_fw_features *)data;
+			rv = features->data;
 			break;
 		}
 
@@ -211,7 +217,7 @@ u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm)
 
 	release_firmware(fw);
 
-	return features ? features->data : 0;
+	return rv;
 }
 EXPORT_SYMBOL_GPL(mt7921_check_offload_capability);
 
-- 
2.39.1


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

* Re: [PATCH] wireless: mt76: mt7921: Fix use-after-free in fw features query.
  2023-03-08  1:00 [PATCH] wireless: mt76: mt7921: Fix use-after-free in fw features query greearb
@ 2023-03-08  9:09 ` Lorenzo Bianconi
  0 siblings, 0 replies; 2+ messages in thread
From: Lorenzo Bianconi @ 2023-03-08  9:09 UTC (permalink / raw)
  To: greearb; +Cc: linux-wireless

[-- Attachment #1: Type: text/plain, Size: 2195 bytes --]

> From: Ben Greear <greearb@candelatech.com>
> 
> Stop referencing 'features' memory after release_firmware is called.
> 
> Fixes this crash:
> 
> RIP: 0010:mt7921_check_offload_capability+0x17d
> mt7921_pci_probe+0xca/0x4b0

Hi Ben,

thx for fixing it. Just few minor comments inline.

Regards,
Lorenzo

> ...
> 
> Signed-off-by: Ben Greear <greearb@candelatech.com>
> ---
>  drivers/net/wireless/mediatek/mt76/mt7921/init.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/init.c b/drivers/net/wireless/mediatek/mt76/mt7921/init.c
> index 38d6563cb12f..3b6fb1a6b351 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7921/init.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7921/init.c
> @@ -171,6 +171,7 @@ u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm)
>  	const struct firmware *fw;
>  	int ret, i, offset = 0;
>  	const u8 *data, *end;
> +	u8 rv = 0;

I would say we can use a more meaningful name here, something like offload_capa
or similar. Moreover I thin you can move features pointer just in the
if (rel_info->tag == MT7921_FW_TAG_FEATURE) block.

Regards,
Lorenzo

>  
>  	ret = request_firmware(&fw, fw_wm, dev);
>  	if (ret)
> @@ -197,12 +198,17 @@ u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm)
>  	data += sizeof(*rel_info);
>  	end = data + le16_to_cpu(rel_info->len);
>  
> +	/* TODO:  This needs better sanity checking I think.
> +	 * Likely a corrupted firmware with bad rel_info->len, for instance,
> +	 * would blow this up.
> +	 */
>  	while (data < end) {
>  		rel_info = (struct mt7921_realease_info *)data;
>  		data += sizeof(*rel_info);
>  
>  		if (rel_info->tag == MT7921_FW_TAG_FEATURE) {
>  			features = (struct mt7921_fw_features *)data;
> +			rv = features->data;
>  			break;
>  		}
>  
> @@ -211,7 +217,7 @@ u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm)
>  
>  	release_firmware(fw);
>  
> -	return features ? features->data : 0;
> +	return rv;
>  }
>  EXPORT_SYMBOL_GPL(mt7921_check_offload_capability);
>  
> -- 
> 2.39.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

end of thread, other threads:[~2023-03-08  9:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-08  1:00 [PATCH] wireless: mt76: mt7921: Fix use-after-free in fw features query greearb
2023-03-08  9:09 ` Lorenzo Bianconi

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