Skip to contentSkip to conversation

Fix a double free bug in rsi_91x_deinit

PATCH In review Hui Peng 4 participants 10 messages Aug 19, 2019 – Sep 3, 2019

Subsystems (3)
lore
Share & tools
lore

Hui Peng

author
#0 lore raw

PATCH 1/1 Fix a double free bug in rsi_91x_deinit

dev (struct rsi_91x_usbdev *) field of adapter (struct rsi_91x_usbdev *) is allocated and initialized in rsi_init_usb_interface. If any error is detected in information read from the device side, rsi_init_usb_interface will be freed. However, in the higher level error handling code in rsi_probe, if error is detected, rsi_91x_deinit is called again, in which dev will be freed again, resulting double free.

This patch fixes the double free by removing the free operation on dev in rsi_init_usb_interface, because rsi_91x_deinit is also used in rsi_disconnect, in that code path, the dev field is not
(and thus needs to be) freed.

This bug was found in v4.19, but is also present in the latest version of kernel.

---
 drivers/net/wireless/rsi/rsi_91x_usb.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/wireless/rsi/rsi_91x_usb.c +0 -1
index c0a163e40402..ac917227f708 100644
@@ -640,7 +640,6 @@ static int rsi_init_usb_interface(struct rsi_hw *adapter,
 	kfree(rsi_dev->tx_buffer);
 
 fail_eps:
-	kfree(rsi_dev);
 
 	return status;
 }
Signature · 1 line
2.22.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Hui Peng

dev (struct rsi_91x_usbdev *) field of adapter (struct rsi_91x_usbdev *) is allocated and initialized in rsi_init_usb_interface. If any error is detected in information read from the device side, rsi_init_usb_interface will be freed. However, in the higher level error handling code in rsi_probe, if error is detected, rsi_91x_deinit is called again, in which dev will be freed again, resulting double free.

This patch fixes the double free by removing the free operation on dev in rsi_init_usb_interface, because rsi_91x_deinit is also used in rsi_disconnect, in that code path, the dev field is not
(and thus needs to be) freed.

Quoted 6 lines

This bug was found in v4.19, but is also present in the latest version of kernel.

FWIW:

This patch is listed as fix for CVE-2019-15504, which has a CVSS 2.0 score of 10.0 (high) and CVSS 3.0 score of 9.8 (critical).

Are there any plans to apply this patch to the upstream kernel anytime soon ? If not, are there reasons to believe that the problem is not as severe as its CVSS score may indicate ?

Thanks,
Guenter

Quoted 19 lines
---
 drivers/net/wireless/rsi/rsi_91x_usb.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/wireless/rsi/rsi_91x_usb.c +0 -1
index c0a163e40402..ac917227f708 100644
@@ -640,7 +640,6 @@ static int rsi_init_usb_interface(struct rsi_hw *adapter,
 	kfree(rsi_dev->tx_buffer);
 
 fail_eps:
-	kfree(rsi_dev);
 
 	return status;
 }
Signature · 1 line
2.22.1
author
#2 lore raw
Quoted 22 lines · Guenter Roeck
Quoted 13 lines · Hui Peng

dev (struct rsi_91x_usbdev *) field of adapter (struct rsi_91x_usbdev *) is allocated and initialized in rsi_init_usb_interface. If any error is detected in information read from the device side, rsi_init_usb_interface will be freed. However, in the higher level error handling code in rsi_probe, if error is detected, rsi_91x_deinit is called again, in which dev will be freed again, resulting double free.

This patch fixes the double free by removing the free operation on dev in rsi_init_usb_interface, because rsi_91x_deinit is also used in rsi_disconnect, in that code path, the dev field is not
(and thus needs to be) freed.

Quoted 6 lines

This bug was found in v4.19, but is also present in the latest version of kernel.

FWIW:

Quoted 8 lines

This patch is listed as fix for CVE-2019-15504, which has a CVSS 2.0 score of 10.0 (high) and CVSS 3.0 score of 9.8 (critical).

Are there any plans to apply this patch to the upstream kernel anytime soon ? If not, are there reasons to believe that the problem is not as severe as its CVSS score may indicate ?

This patch is also still under review.

Quoted 22 lines

Thanks,
Guenter

Quoted 19 lines
---
 drivers/net/wireless/rsi/rsi_91x_usb.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/wireless/rsi/rsi_91x_usb.c +0 -1
index c0a163e40402..ac917227f708 100644
@@ -640,7 +640,6 @@ static int rsi_init_usb_interface(struct rsi_hw *adapter,
 	kfree(rsi_dev->tx_buffer);
 
 fail_eps:
-	kfree(rsi_dev);
 
 	return status;
 }
Signature · 1 line
2.22.1
#3 lore raw
In reply to Guenter Roeck
Quoted 21 lines · Guenter Roeck
Quoted 13 lines · Hui Peng

dev (struct rsi_91x_usbdev *) field of adapter (struct rsi_91x_usbdev *) is allocated and initialized in rsi_init_usb_interface. If any error is detected in information read from the device side, rsi_init_usb_interface will be freed. However, in the higher level error handling code in rsi_probe, if error is detected, rsi_91x_deinit is called again, in which dev will be freed again, resulting double free.

This patch fixes the double free by removing the free operation on dev in rsi_init_usb_interface, because rsi_91x_deinit is also used in rsi_disconnect, in that code path, the dev field is not
(and thus needs to be) freed.

Quoted 6 lines

This bug was found in v4.19, but is also present in the latest version of kernel.

Quoted 6 lines

FWIW:

This patch is listed as fix for CVE-2019-15504, which has a CVSS 2.0 score of 10.0 (high) and CVSS 3.0 score of 9.8 (critical).

A double free in error path is considered as a critical CVE issue? I'm very curious, why is that?

Quoted 2 lines

Are there any plans to apply this patch to the upstream kernel anytime soon ?

I was on vacation last week and hence I have not been able to apply any wireless patches. I should be able to catch up next week.

Signature · 1 line
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#4 lore raw
Quoted 25 lines · Kalle Valo
Quoted 23 lines · Guenter Roeck
Quoted 13 lines · Hui Peng

dev (struct rsi_91x_usbdev *) field of adapter (struct rsi_91x_usbdev *) is allocated and initialized in rsi_init_usb_interface. If any error is detected in information read from the device side, rsi_init_usb_interface will be freed. However, in the higher level error handling code in rsi_probe, if error is detected, rsi_91x_deinit is called again, in which dev will be freed again, resulting double free.

This patch fixes the double free by removing the free operation on dev in rsi_init_usb_interface, because rsi_91x_deinit is also used in rsi_disconnect, in that code path, the dev field is not
(and thus needs to be) freed.

Quoted 6 lines

This bug was found in v4.19, but is also present in the latest version of kernel.

FWIW:

Quoted 8 lines
Quoted 4 lines

This patch is listed as fix for CVE-2019-15504, which has a CVSS 2.0 score of 10.0 (high) and CVSS 3.0 score of 9.8 (critical).

A double free in error path is considered as a critical CVE issue? I'm very curious, why is that?

You'd have to ask the people assigning CVSS scores. However, if the memory was reallocated, that reallocated memory (which is still in use) is freed. Then all kinds of bad things can happen.

Guenter

Quoted 6 lines
Quoted 2 lines

Are there any plans to apply this patch to the upstream kernel anytime soon ?

I was on vacation last week and hence I have not been able to apply any wireless patches. I should be able to catch up next week.

#5 lore raw
Quoted 31 lines · Guenter Roeck
Quoted 30 lines · Kalle Valo
Quoted 27 lines · Guenter Roeck
Quoted 13 lines · Hui Peng

dev (struct rsi_91x_usbdev *) field of adapter (struct rsi_91x_usbdev *) is allocated and initialized in rsi_init_usb_interface. If any error is detected in information read from the device side, rsi_init_usb_interface will be freed. However, in the higher level error handling code in rsi_probe, if error is detected, rsi_91x_deinit is called again, in which dev will be freed again, resulting double free.

This patch fixes the double free by removing the free operation on dev in rsi_init_usb_interface, because rsi_91x_deinit is also used in rsi_disconnect, in that code path, the dev field is not
(and thus needs to be) freed.

Quoted 6 lines

This bug was found in v4.19, but is also present in the latest version of kernel.

FWIW:

This patch is listed as fix for CVE-2019-15504, which has a CVSS 2.0 score of 10.0 (high) and CVSS 3.0 score of 9.8 (critical).

Quoted 7 lines
Quoted 3 lines

A double free in error path is considered as a critical CVE issue? I'm very curious, why is that?

You'd have to ask the people assigning CVSS scores. However, if the memory was reallocated, that reallocated memory (which is still in use) is freed. Then all kinds of bad things can happen.

Yes, but moving from "bad things _can_ happen" to "bad things happen" in an instance like this will be a tough task. It also requires physical access to the machine.

Anyway, that doesn't mean we shouldn't fix it, it's just that CVSS can be crazy when it comes to kernel patches (i.e. almost all fixes should be "critical"...)

thanks,

greg k-h

#6 lore raw
Quoted 36 lines · Greg KH
Quoted 35 lines · Guenter Roeck
Quoted 33 lines · Kalle Valo
Quoted 21 lines · Guenter Roeck
Quoted 13 lines · Hui Peng

dev (struct rsi_91x_usbdev *) field of adapter (struct rsi_91x_usbdev *) is allocated and initialized in rsi_init_usb_interface. If any error is detected in information read from the device side, rsi_init_usb_interface will be freed. However, in the higher level error handling code in rsi_probe, if error is detected, rsi_91x_deinit is called again, in which dev will be freed again, resulting double free.

This patch fixes the double free by removing the free operation on dev in rsi_init_usb_interface, because rsi_91x_deinit is also used in rsi_disconnect, in that code path, the dev field is not
(and thus needs to be) freed.

Quoted 6 lines

This bug was found in v4.19, but is also present in the latest version of kernel.

Quoted 6 lines

FWIW:

This patch is listed as fix for CVE-2019-15504, which has a CVSS 2.0 score of 10.0 (high) and CVSS 3.0 score of 9.8 (critical).

A double free in error path is considered as a critical CVE issue? I'm very curious, why is that?

Quoted 8 lines
Quoted 3 lines

You'd have to ask the people assigning CVSS scores. However, if the memory was reallocated, that reallocated memory (which is still in use) is freed. Then all kinds of bad things can happen.

Yes, but moving from "bad things _can_ happen" to "bad things happen" in an instance like this will be a tough task. It also requires physical access to the machine.

Is this correct even with usbip enabled ?

Quoted 4 lines

Anyway, that doesn't mean we shouldn't fix it, it's just that CVSS can be crazy when it comes to kernel patches (i.e. almost all fixes should be "critical"...)

Not all of them, but probably too many. That is why I asked if the problem is real. I _used_ to trust CVSS scores, but by now I am at least somewhat suspicious - especially if a patch wasn't applied for a period of time, like this series of usb patches.

Having said that, I am even more wary of double-free problems - those tend to be notoriously difficult to debug. I'd rather have them out of my way, even if they are unlikely to be seen in the real world (plus, Murphy says that anything unlikely is going to happen almost immediately).

Guenter

#7 lore raw
Quoted 41 lines · Guenter Roeck
Quoted 40 lines · Greg KH
Quoted 38 lines · Guenter Roeck
Quoted 25 lines · Kalle Valo
Quoted 23 lines · Guenter Roeck
Quoted 13 lines · Hui Peng

dev (struct rsi_91x_usbdev *) field of adapter (struct rsi_91x_usbdev *) is allocated and initialized in rsi_init_usb_interface. If any error is detected in information read from the device side, rsi_init_usb_interface will be freed. However, in the higher level error handling code in rsi_probe, if error is detected, rsi_91x_deinit is called again, in which dev will be freed again, resulting double free.

This patch fixes the double free by removing the free operation on dev in rsi_init_usb_interface, because rsi_91x_deinit is also used in rsi_disconnect, in that code path, the dev field is not
(and thus needs to be) freed.

Quoted 6 lines

This bug was found in v4.19, but is also present in the latest version of kernel.

FWIW:

Quoted 8 lines
Quoted 4 lines

This patch is listed as fix for CVE-2019-15504, which has a CVSS 2.0 score of 10.0 (high) and CVSS 3.0 score of 9.8 (critical).

A double free in error path is considered as a critical CVE issue? I'm very curious, why is that?

You'd have to ask the people assigning CVSS scores. However, if the memory was reallocated, that reallocated memory (which is still in use) is freed. Then all kinds of bad things can happen.

Quoted 6 lines
Quoted 4 lines

Yes, but moving from "bad things _can_ happen" to "bad things happen" in an instance like this will be a tough task. It also requires physical access to the machine.

Is this correct even with usbip enabled ?

Who has usbip enabled anywhere? :)

I don't know if usbip can trigger this type of thing, maybe someone needs to test that...

thanks,

greg k-h

#8 lore raw
Quoted 42 lines · Greg KH
Quoted 41 lines · Guenter Roeck
Quoted 40 lines · Greg KH
Quoted 38 lines · Guenter Roeck
Quoted 25 lines · Kalle Valo
Quoted 23 lines · Guenter Roeck
Quoted 13 lines · Hui Peng

dev (struct rsi_91x_usbdev *) field of adapter (struct rsi_91x_usbdev *) is allocated and initialized in rsi_init_usb_interface. If any error is detected in information read from the device side, rsi_init_usb_interface will be freed. However, in the higher level error handling code in rsi_probe, if error is detected, rsi_91x_deinit is called again, in which dev will be freed again, resulting double free.

This patch fixes the double free by removing the free operation on dev in rsi_init_usb_interface, because rsi_91x_deinit is also used in rsi_disconnect, in that code path, the dev field is not
(and thus needs to be) freed.

Quoted 6 lines

This bug was found in v4.19, but is also present in the latest version of kernel.

FWIW:

Quoted 8 lines
Quoted 4 lines

This patch is listed as fix for CVE-2019-15504, which has a CVSS 2.0 score of 10.0 (high) and CVSS 3.0 score of 9.8 (critical).

A double free in error path is considered as a critical CVE issue? I'm very curious, why is that?

You'd have to ask the people assigning CVSS scores. However, if the memory was reallocated, that reallocated memory (which is still in use) is freed. Then all kinds of bad things can happen.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

Yes, but moving from "bad things _can_ happen" to "bad things happen" in an instance like this will be a tough task. It also requires physical access to the machine.

Is this correct even with usbip enabled ?

Who has usbip enabled anywhere? :)

It is enabled in Ubuntu, and it looks like it is enabled in Fedora as well. It is disabled in Chrome OS. I didn't check other distributions.

Quoted 3 lines

I don't know if usbip can trigger this type of thing, maybe someone needs to test that...

I seemed to recall someone mentioning that it is possible to use usbip for remote attacks. This is why I mentioned it. I don't recall details, though, and I don't know if it is really possible and to what extent.

Guenter

#9 lore raw

Re: [PATCH] rsi: fix a double free bug in rsi_91x_deinit()

In reply to Hui Peng
Quoted 13 lines · Hui Peng

dev (struct rsi_91x_usbdev *) field of adapter (struct rsi_91x_usbdev *) is allocated and initialized in rsi_init_usb_interface. If any error is detected in information read from the device side, rsi_init_usb_interface will be freed. However, in the higher level error handling code in rsi_probe, if error is detected, rsi_91x_deinit is called again, in which dev will be freed again, resulting double free.

This patch fixes the double free by removing the free operation on dev in rsi_init_usb_interface, because rsi_91x_deinit is also used in rsi_disconnect, in that code path, the dev field is not
(and thus needs to be) freed.

Quoted 7 lines

This bug was found in v4.19, but is also present in the latest version of kernel. Fixes CVE-2019-15504.

Patch applied to wireless-drivers.git, thanks.

8b51dc729147 rsi: fix a double free bug in rsi_91x_deinit()

Signature · 3 lines
https://patchwork.kernel.org/patch/11102087/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches