wireless: mt76: mt7921: Fix use-after-free in fw features query.
Subsystems (2)
PATCH v2 1/1 wireless: mt76: mt7921: Fix use-after-free in fw features query.
From: Ben Greear <[email protected]>
Stop referencing 'features' memory after release_firmware is called.
Fixes this crash:
RIP: 0010:mt7921_check_offload_capability+0x17d mt7921_pci_probe+0xca/0x4b0
...
--- drivers/net/wireless/mediatek/mt76/mt7921/init.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7921/init.c +9 -2
@@ -165,12 +165,12 @@ mt7921_mac_init_band(struct mt7921_dev *dev, u8 band)u8 mt7921_check_offload_capability (struct device *dev,const char *fw_wm) { -struct mt7921_fw_features *features =NULL ;const struct mt76_connac2_fw_trailer *hdr;struct mt7921_realease_info *rel_info;const struct firmware *fw;int ret, i, offset =0 ;const u8 *data, *end; +u8 offload_caps =0 ; ret =request_firmware (&fw, fw_wm, dev);if (ret)
@@ -197,12 +197,19 @@ 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 ) { +struct mt7921_fw_features *features; + features = (struct mt7921_fw_features *)data; + offload_caps = features->data;break ; }
@@ -211,7 +218,7 @@ u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm)release_firmware (fw); -return features ? features->data :0 ; +return offload_caps; }EXPORT_SYMBOL_GPL (mt7921_check_offload_capability);
Signature · 1 line
2.39.1
Quoted 11 lines
From: Ben Greear <[email protected]>
Stop referencing 'features' memory after
release_firmwareis called.Fixes this crash:
RIP: 0010:mt7921_check_offload_capability+0x17d mt7921_pci_probe+0xca/0x4b0...
Signed-off-by Ben Greear <[email protected]>
Quoted 54 lines
--- drivers/net/wireless/mediatek/mt76/mt7921/init.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/net/wireless/mediatek/mt76/mt7921/init.c +9
-2@@ -165,12 +165,12 @@ mt7921_mac_init_band(struct mt7921_dev *dev, u8 band)u8 mt7921_check_offload_capability (struct device *dev,const char *fw_wm) { -struct mt7921_fw_features *features =NULL ;const struct mt76_connac2_fw_trailer *hdr;struct mt7921_realease_info *rel_info;const struct firmware *fw;int ret, i, offset =0 ;const u8 *data, *end; +u8 offload_caps =0 ; ret =request_firmware (&fw, fw_wm, dev);if (ret)@@ -197,12 +197,19 @@ 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 ) { +struct mt7921_fw_features *features; + features = (struct mt7921_fw_features *)data; + offload_caps = features->data;break ; }@@ -211,7 +218,7 @@ u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm)release_firmware (fw); -return features ? features->data :0 ; +return offload_caps; }EXPORT_SYMBOL_GPL (mt7921_check_offload_capability);Signature · 1 line
2.39.1
Lorenzo Bianconi
maintainerQuoted 9 lines
From: Ben Greear <[email protected]>
Stop referencing 'features' memory after
release_firmwareis called.Fixes this crash:
RIP: 0010:mt7921_check_offload_capability+0x17d mt7921_pci_probe+0xca/0x4b0...
I would say even this patch can go trough wireless tree.
@Felix: agree?
Regards,
Lorenzo
Quoted 56 lines
Signed-off-by Ben Greear <[email protected]>--- drivers/net/wireless/mediatek/mt76/mt7921/init.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/net/wireless/mediatek/mt76/mt7921/init.c +9
-2@@ -165,12 +165,12 @@ mt7921_mac_init_band(struct mt7921_dev *dev, u8 band)u8 mt7921_check_offload_capability (struct device *dev,const char *fw_wm) { -struct mt7921_fw_features *features =NULL ;const struct mt76_connac2_fw_trailer *hdr;struct mt7921_realease_info *rel_info;const struct firmware *fw;int ret, i, offset =0 ;const u8 *data, *end; +u8 offload_caps =0 ; ret =request_firmware (&fw, fw_wm, dev);if (ret)@@ -197,12 +197,19 @@ 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 ) { +struct mt7921_fw_features *features; + features = (struct mt7921_fw_features *)data; + offload_caps = features->data;break ; }@@ -211,7 +218,7 @@ u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm)release_firmware (fw); -return features ? features->data :0 ; +return offload_caps; }EXPORT_SYMBOL_GPL (mt7921_check_offload_capability);Signature · 1 line
2.39.1
Lorenzo Bianconi
maintainerQuoted 34 lines
From: Ben Greear <[email protected]>
Stop referencing 'features' memory after
release_firmwareis called.Fixes this crash:
RIP: 0010:mt7921_check_offload_capability+0x17d mt7921_pci_probe+0xca/0x4b0...
Signed-off-by Ben Greear <[email protected]>--- drivers/net/wireless/mediatek/mt76/mt7921/init.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/net/wireless/mediatek/mt76/mt7921/init.c +1
-1@@ -165,12 +165,12 @@ mt7921_mac_init_band(struct mt7921_dev *dev, u8 band)u8 mt7921_check_offload_capability (struct device *dev,const char *fw_wm) { -struct mt7921_fw_features *features =NULL ;const struct mt76_connac2_fw_trailer *hdr;struct mt7921_realease_info *rel_info;const struct firmware *fw;int ret, i, offset =0 ;const u8 *data, *end; +u8 offload_caps =0 ; ret =request_firmware (&fw, fw_wm, dev);if (ret)
drivers/net/wireless/mediatek/mt76/mt7921/init.c u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm) · line 203
Quoted 7 lines
drivers/net/wireless/mediatek/mt76/mt7921/init.c +4
-0@@ -197,12 +197,19 @@ 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. +*/
can you please repost dropping this comment?
Regards,
Lorenzo
Quoted 24 lines
drivers/net/wireless/mediatek/mt76/mt7921/init.c +4
-1while (data < end) { rel_info = (struct mt7921_realease_info *)data; data +=sizeof (*rel_info);if (rel_info->tag ==MT7921_FW_TAG_FEATURE ) { +struct mt7921_fw_features *features; + features = (struct mt7921_fw_features *)data; + offload_caps = features->data;break ; }@@ -211,7 +218,7 @@ u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm)release_firmware (fw); -return features ? features->data :0 ; +return offload_caps; }EXPORT_SYMBOL_GPL (mt7921_check_offload_capability);Signature · 1 line
2.39.1
Quoted 37 lines · Lorenzo Bianconi
Quoted 37 lines
From: Ben Greear <[email protected]>
Stop referencing 'features' memory after
release_firmwareis called.Fixes this crash:
RIP: 0010:mt7921_check_offload_capability+0x17d mt7921_pci_probe+0xca/0x4b0...
Signed-off-by Ben Greear <[email protected]>--- drivers/net/wireless/mediatek/mt76/mt7921/init.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/net/wireless/mediatek/mt76/mt7921/init.c +1
-1@@ -165,12 +165,12 @@ mt7921_mac_init_band(struct mt7921_dev *dev, u8 band)u8 mt7921_check_offload_capability (struct device *dev,const char *fw_wm) { -struct mt7921_fw_features *features =NULL ;const struct mt76_connac2_fw_trailer *hdr;struct mt7921_realease_info *rel_info;const struct firmware *fw;int ret, i, offset =0 ;const u8 *data, *end; +u8 offload_caps =0 ; ret =request_firmware (&fw, fw_wm, dev);if (ret)@@ -197,12 +197,19 @@ u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm) data +=sizeof (*rel_info); end = data +le16_to_cpu (rel_info->len);
Quoted 6 lines
drivers/net/wireless/mediatek/mt76/mt7921/init.c u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm) · line 203
Quoted 4 lines
drivers/net/wireless/mediatek/mt76/mt7921/init.c +4
-0+/* TODO: This needs better sanity checking I think. +* Likely a corrupted firmware with bad rel_info->len, for instance, +* would blow this up. +*/ can you please repost dropping this comment?
Why? Looks to me like this portion of mtk driver logic assumes firmware is never corrupted on accident or on purpose. It should be fixed at some point.
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
Lorenzo Bianconi
maintainerQuoted 42 lines · Lorenzo Bianconi
Quoted 32 lines
Quoted 32 lines
From: Ben Greear <[email protected]>
Stop referencing 'features' memory after
release_firmwareis called.Fixes this crash:
RIP: 0010:mt7921_check_offload_capability+0x17d mt7921_pci_probe+0xca/0x4b0...
Signed-off-by Ben Greear <[email protected]>--- drivers/net/wireless/mediatek/mt76/mt7921/init.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/net/wireless/mediatek/mt76/mt7921/init.c +1
-1@@ -165,12 +165,12 @@ mt7921_mac_init_band(struct mt7921_dev *dev, u8 band)u8 mt7921_check_offload_capability (struct device *dev,const char *fw_wm) { -struct mt7921_fw_features *features =NULL ;const struct mt76_connac2_fw_trailer *hdr;struct mt7921_realease_info *rel_info;const struct firmware *fw;int ret, i, offset =0 ;const u8 *data, *end; +u8 offload_caps =0 ; ret =request_firmware (&fw, fw_wm, dev);if (ret)@@ -197,12 +197,19 @@ u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm)Quoted 8 lines
drivers/net/wireless/mediatek/mt76/mt7921/init.c u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm) · line 203
Quoted 6 lines
drivers/net/wireless/mediatek/mt76/mt7921/init.c +4
-0data +=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. +*/ can you please repost dropping this comment?
Quoted 2 lines
Why? Looks to me like this portion of mtk driver logic assumes firmware is never corrupted on accident or on purpose. It should be fixed at some point.
even if this is a theoretical issue, this does not seem the right way to track it and it is not related to this patch.
Regards,
Lorenzo
Quoted 7 lines
Thanks,
BenSignature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
Quoted 42 lines · Lorenzo Bianconi
Quoted 42 lines · Lorenzo Bianconi
Quoted 40 lines
Quoted 32 lines
From: Ben Greear <[email protected]>
Stop referencing 'features' memory after
release_firmwareis called.Fixes this crash:
RIP: 0010:mt7921_check_offload_capability+0x17d mt7921_pci_probe+0xca/0x4b0...
Signed-off-by Ben Greear <[email protected]>--- drivers/net/wireless/mediatek/mt76/mt7921/init.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/net/wireless/mediatek/mt76/mt7921/init.c +1
-1@@ -165,12 +165,12 @@ mt7921_mac_init_band(struct mt7921_dev *dev, u8 band)u8 mt7921_check_offload_capability (struct device *dev,const char *fw_wm) { -struct mt7921_fw_features *features =NULL ;const struct mt76_connac2_fw_trailer *hdr;struct mt7921_realease_info *rel_info;const struct firmware *fw;int ret, i, offset =0 ;const u8 *data, *end; +u8 offload_caps =0 ; ret =request_firmware (&fw, fw_wm, dev);if (ret)drivers/net/wireless/mediatek/mt76/mt7921/init.c u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm) · line 202
Quoted 6 lines
drivers/net/wireless/mediatek/mt76/mt7921/init.c +4
-0@@ -197,12 +197,19 @@ 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. +*/ can you please repost dropping this comment?
Quoted 5 lines
Quoted 2 lines
Why? Looks to me like this portion of mtk driver logic assumes firmware is never corrupted on accident or on purpose. It should be fixed at some point.
even if this is a theoretical issue, this does not seem the right way to track it and it is not related to this patch.
There is no better way I know to track such problems, it is not like random OSS developers will read kernel bugzilla for this sort of thing, and email bug report about it will be buried in days and never seen again.
And it is related to crazy memory corruption bugs since a corrupted firmware could cause similar memory corruption. So next time someone is working on this code, maybe they will see the comment and code it more defensively.
Anyway, if you insist, I can re-spin the patch against 6.2 and repost. I also hear that it will not apply to 6.3, but I'm not yet working on 6.3.
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
Lorenzo Bianconi
maintainerQuoted 49 lines · Lorenzo Bianconi
Quoted 42 lines
Quoted 42 lines · Lorenzo Bianconi
Quoted 40 lines
Quoted 32 lines
From: Ben Greear <[email protected]>
Stop referencing 'features' memory after
release_firmwareis called.Fixes this crash:
RIP: 0010:mt7921_check_offload_capability+0x17d mt7921_pci_probe+0xca/0x4b0...
Signed-off-by Ben Greear <[email protected]>--- drivers/net/wireless/mediatek/mt76/mt7921/init.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/net/wireless/mediatek/mt76/mt7921/init.c +1
-1@@ -165,12 +165,12 @@ mt7921_mac_init_band(struct mt7921_dev *dev, u8 band)u8 mt7921_check_offload_capability (struct device *dev,const char *fw_wm) { -struct mt7921_fw_features *features =NULL ;const struct mt76_connac2_fw_trailer *hdr;struct mt7921_realease_info *rel_info;const struct firmware *fw;int ret, i, offset =0 ;const u8 *data, *end; +u8 offload_caps =0 ; ret =request_firmware (&fw, fw_wm, dev);if (ret)drivers/net/wireless/mediatek/mt76/mt7921/init.c u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm) · line 202
Quoted 6 lines
drivers/net/wireless/mediatek/mt76/mt7921/init.c +4
-0@@ -197,12 +197,19 @@ 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. +*/ can you please repost dropping this comment?
Quoted 5 lines
Quoted 2 lines
Why? Looks to me like this portion of mtk driver logic assumes firmware is never corrupted on accident or on purpose. It should be fixed at some point.
even if this is a theoretical issue, this does not seem the right way to track it and it is not related to this patch.
Quoted 7 lines
There is no better way I know to track such problems, it is not like random OSS developers will read kernel bugzilla for this sort of thing, and email bug report about it will be buried in days and never seen again.
And it is related to crazy memory corruption bugs since a corrupted firmware could cause similar memory corruption. So next time someone is working on this code, maybe they will see the comment and code it more defensively.
honestly I do not think this comment is so useful to understand a memory corruption issue, it just makes the code uglier. If you feel this is a real issue, I would say to post a patch to improve the code :).
Regards,
Lorenzo
Quoted 10 lines
Anyway, if you insist, I can re-spin the patch against 6.2 and repost. I also hear that it will not apply to 6.3, but I'm not yet working on 6.3.
Thanks,
BenSignature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
Quoted 53 lines · Lorenzo Bianconi
Quoted 53 lines · Lorenzo Bianconi
Quoted 42 lines
Quoted 42 lines · Lorenzo Bianconi
Quoted 40 lines
Quoted 32 lines
From: Ben Greear <[email protected]>
Stop referencing 'features' memory after
release_firmwareis called.Fixes this crash:
RIP: 0010:mt7921_check_offload_capability+0x17d mt7921_pci_probe+0xca/0x4b0...
Signed-off-by Ben Greear <[email protected]>--- drivers/net/wireless/mediatek/mt76/mt7921/init.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/net/wireless/mediatek/mt76/mt7921/init.c +1
-1@@ -165,12 +165,12 @@ mt7921_mac_init_band(struct mt7921_dev *dev, u8 band)u8 mt7921_check_offload_capability (struct device *dev,const char *fw_wm) { -struct mt7921_fw_features *features =NULL ;const struct mt76_connac2_fw_trailer *hdr;struct mt7921_realease_info *rel_info;const struct firmware *fw;int ret, i, offset =0 ;const u8 *data, *end; +u8 offload_caps =0 ; ret =request_firmware (&fw, fw_wm, dev);if (ret)drivers/net/wireless/mediatek/mt76/mt7921/init.c u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm) · line 202
Quoted 6 lines
drivers/net/wireless/mediatek/mt76/mt7921/init.c +4
-0@@ -197,12 +197,19 @@ 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. +*/ can you please repost dropping this comment?
Quoted 5 lines
Quoted 2 lines
Why? Looks to me like this portion of mtk driver logic assumes firmware is never corrupted on accident or on purpose. It should be fixed at some point.
even if this is a theoretical issue, this does not seem the right way to track it and it is not related to this patch.
There is no better way I know to track such problems, it is not like random OSS developers will read kernel bugzilla for this sort of thing, and email bug report about it will be buried in days and never seen again.
Quoted 7 lines
Quoted 3 lines
And it is related to crazy memory corruption bugs since a corrupted firmware could cause similar memory corruption. So next time someone is working on this code, maybe they will see the comment and code it more defensively.
honestly I do not think this comment is so useful to understand a memory corruption issue, it just makes the code uglier. If you feel this is a real issue, I would say to post a patch to improve the code :).
I care enough to note a complaint, but not enough to fix it. Someone with docs about the firmware format would have a better chance of doing a good job at this I think.
I'll post a new patch removing the comment when I get a chance to work on kernel code again.
If someone has time and interest to do it sooner, please feel free to submit a revised patch.
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com