Skip to contentSkip to conversation

usb: host: ehci-sched: avoid possible NULL dereference

PATCH In review Sudip Mukherjee 5 participants 6 messages Oct 5, 2020 – Oct 6, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: host: ehci-sched: avoid possible NULL dereference

find_tt() can return NULL or the error value in ERR_PTR() and dereferencing the return value without checking for the error can lead to a possible dereference of NULL pointer or ERR_PTR().

---
 drivers/usb/host/ehci-sched.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/host/ehci-sched.c +4 -0
index 6dfb242f9a4b..f3fd7e9fe6b2 100644
@@ -245,6 +245,8 @@ static void reserve_release_intr_bandwidth(struct ehci_hcd *ehci,
 	/* FS/LS bus bandwidth */
 	if (tt_usecs) {
 		tt = find_tt(qh->ps.udev);
+		if (IS_ERR_OR_NULL(tt))
+			return;
 		if (sign > 0)
 			list_add_tail(&qh->ps.ps_list, &tt->ps_list);
 		else
@@ -1338,6 +1340,8 @@ static void reserve_release_iso_bandwidth(struct ehci_hcd *ehci,
 		}
 
 		tt = find_tt(stream->ps.udev);
+		if (IS_ERR_OR_NULL(tt))
+			return;
 		if (sign > 0)
 			list_add_tail(&stream->ps.ps_list, &tt->ps_list);
 		else
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Sudip Mukherjee

find_tt() can return NULL or the error value in ERR_PTR() and dereferencing the return value without checking for the error can lead to a possible dereference of NULL pointer or ERR_PTR().

Looks fine to me. There is in fact no checks of the return value before a dereference here, and this solves that.

#2 lore raw
Quoted 10 lines · Harley A.W. Lorenzo
Quoted 3 lines · Sudip Mukherjee

find_tt() can return NULL or the error value in ERR_PTR() and dereferencing the return value without checking for the error can lead to a possible dereference of NULL pointer or ERR_PTR().

Looks fine to me. There is in fact no checks of the return value before a dereference here, and this solves that.

No, this patch is wrong. In fact, these calls to find_tt() cannot return NULL or an ERR_PTR value.

Alan Stern

maintainer
#3 lore raw
Quoted 7 lines · On Mon, Oct 05, 2020 at 09:25:44PM -0400, [email protected] wrote:
Quoted 6 lines · Harley A.W. Lorenzo
Quoted 3 lines · Sudip Mukherjee

find_tt() can return NULL or the error value in ERR_PTR() and dereferencing the return value without checking for the error can lead to a possible dereference of NULL pointer or ERR_PTR().

Quoted 7 lines
Quoted 4 lines

Looks fine to me. There is in fact no checks of the return value before a dereference here, and this solves that.

No, this patch is wrong. In fact, these calls to find_tt() cannot return NULL or an ERR_PTR value.

Sudip, if you would prefer to submit a patch that adds comments to those call sites explaining that find_tt() will not return NULL or an error, that would be okay.

Alan Stern

#4 lore raw
In reply to Harley A.W. Lorenzo
Quoted 10 lines · Harley A.W. Lorenzo
Quoted 3 lines · Sudip Mukherjee

find_tt() can return NULL or the error value in ERR_PTR() and dereferencing the return value without checking for the error can lead to a possible dereference of NULL pointer or ERR_PTR().

Looks fine to me. There is in fact no checks of the return value before a dereference here, and this solves that.

Nit, in the future, you need the trailing '>' there.

thanks,

greg k-h

#5 lore raw
In reply to Sudip Mukherjee

Hi All,

I sent out this patch yesterday which I think is an obvious safety issue as the error was not handled. This is a change in code and the resultant binary will not be same. I know we are moving to pcie now, but have we decided yet how to validate these kinds of changes?

Signature · 2 lines
Regards
Sudip
Quoted 32 lines · Sudip Mukherjee

find_tt() can return NULL or the error value in ERR_PTR() and dereferencing the return value without checking for the error can lead to a possible dereference of NULL pointer or ERR_PTR().

---
 drivers/usb/host/ehci-sched.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/host/ehci-sched.c +4 -0
index 6dfb242f9a4b..f3fd7e9fe6b2 100644
@@ -245,6 +245,8 @@ static void reserve_release_intr_bandwidth(struct ehci_hcd *ehci,
 	/* FS/LS bus bandwidth */
 	if (tt_usecs) {
 		tt = find_tt(qh->ps.udev);
+		if (IS_ERR_OR_NULL(tt))
+			return;
 		if (sign > 0)
 			list_add_tail(&qh->ps.ps_list, &tt->ps_list);
 		else
@@ -1338,6 +1340,8 @@ static void reserve_release_iso_bandwidth(struct ehci_hcd *ehci,
 		}
 
 		tt = find_tt(stream->ps.udev);
+		if (IS_ERR_OR_NULL(tt))
+			return;
 		if (sign > 0)
 			list_add_tail(&stream->ps.ps_list, &tt->ps_list);
 		else