* [PATCH] USB: EHCI: fix dereference of ERR_PTR
@ 2015-09-16 14:08 Sudip Mukherjee
2015-09-16 14:16 ` Fabio Estevam
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Sudip Mukherjee @ 2015-09-16 14:08 UTC (permalink / raw)
To: Alan Stern, Greg Kroah-Hartman; +Cc: linux-kernel, linux-usb, Sudip Mukherjee
On error find_tt() returns either a NULL pointer or the error value in
ERR_PTR. But we were dereferencing it directly without even checking if
find_tt() returned a valid pointer or not.
Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---
drivers/usb/host/ehci-sched.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index f9a3327..27bced7 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -257,6 +257,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 (!tt || IS_ERR(tt))
+ return;
if (sign > 0)
list_add_tail(&qh->ps.ps_list, &tt->ps_list);
else
@@ -1373,6 +1375,8 @@ static void reserve_release_iso_bandwidth(struct ehci_hcd *ehci,
}
tt = find_tt(stream->ps.udev);
+ if (!tt || IS_ERR(tt))
+ return;
if (sign > 0)
list_add_tail(&stream->ps.ps_list, &tt->ps_list);
else
--
1.9.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] USB: EHCI: fix dereference of ERR_PTR
2015-09-16 14:08 [PATCH] USB: EHCI: fix dereference of ERR_PTR Sudip Mukherjee
@ 2015-09-16 14:16 ` Fabio Estevam
2015-09-16 14:25 ` Sergei Shtylyov
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Fabio Estevam @ 2015-09-16 14:16 UTC (permalink / raw)
To: Sudip Mukherjee; +Cc: Alan Stern, Greg Kroah-Hartman, linux-kernel, USB list
On Wed, Sep 16, 2015 at 11:08 AM, Sudip Mukherjee
<sudipm.mukherjee@gmail.com> wrote:
> On error find_tt() returns either a NULL pointer or the error value in
> ERR_PTR. But we were dereferencing it directly without even checking if
> find_tt() returned a valid pointer or not.
>
> Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
> ---
> drivers/usb/host/ehci-sched.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
> index f9a3327..27bced7 100644
> --- a/drivers/usb/host/ehci-sched.c
> +++ b/drivers/usb/host/ehci-sched.c
> @@ -257,6 +257,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 (!tt || IS_ERR(tt))
> + return;
Could you use IS_ERR_OR_NULL(tt)?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] USB: EHCI: fix dereference of ERR_PTR
2015-09-16 14:08 [PATCH] USB: EHCI: fix dereference of ERR_PTR Sudip Mukherjee
2015-09-16 14:16 ` Fabio Estevam
@ 2015-09-16 14:25 ` Sergei Shtylyov
2015-09-16 16:22 ` [PATCH v2] " Sudip Mukherjee
2015-09-21 2:48 ` [PATCH] " Lu, Baolu
3 siblings, 0 replies; 9+ messages in thread
From: Sergei Shtylyov @ 2015-09-16 14:25 UTC (permalink / raw)
To: Sudip Mukherjee, Alan Stern, Greg Kroah-Hartman; +Cc: linux-kernel, linux-usb
Hello.
On 9/16/2015 5:08 PM, Sudip Mukherjee wrote:
> On error find_tt() returns either a NULL pointer or the error value in
> ERR_PTR. But we were dereferencing it directly without even checking if
> find_tt() returned a valid pointer or not.
>
> Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
> ---
> drivers/usb/host/ehci-sched.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
> index f9a3327..27bced7 100644
> --- a/drivers/usb/host/ehci-sched.c
> +++ b/drivers/usb/host/ehci-sched.c
> @@ -257,6 +257,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 (!tt || IS_ERR(tt))
There's IS_ERR_OR_NULL()?
> + return;
> if (sign > 0)
> list_add_tail(&qh->ps.ps_list, &tt->ps_list);
> else
> @@ -1373,6 +1375,8 @@ static void reserve_release_iso_bandwidth(struct ehci_hcd *ehci,
> }
>
> tt = find_tt(stream->ps.udev);
> + if (!tt || IS_ERR(tt))
Likewise.
[...]
MBR, Sergei
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] USB: EHCI: fix dereference of ERR_PTR
2015-09-16 14:08 [PATCH] USB: EHCI: fix dereference of ERR_PTR Sudip Mukherjee
2015-09-16 14:16 ` Fabio Estevam
2015-09-16 14:25 ` Sergei Shtylyov
@ 2015-09-16 16:22 ` Sudip Mukherjee
2015-09-16 16:54 ` Alan Stern
2015-09-21 2:48 ` [PATCH] " Lu, Baolu
3 siblings, 1 reply; 9+ messages in thread
From: Sudip Mukherjee @ 2015-09-16 16:22 UTC (permalink / raw)
To: Alan Stern, Greg Kroah-Hartman
Cc: linux-kernel, linux-usb, Fabio Estevam, Sergei Shtylyov,
Sudip Mukherjee
On error find_tt() returns either a NULL pointer or the error value in
ERR_PTR. But we were dereferencing it directly without even checking if
find_tt() returned a valid pointer or not.
Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---
v2: used IS_ERR_OR_NULL (didn't know it was there. thanks)
drivers/usb/host/ehci-sched.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index f9a3327..de75343 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -257,6 +257,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
@@ -1373,6 +1375,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
--
1.9.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2] USB: EHCI: fix dereference of ERR_PTR
2015-09-16 16:22 ` [PATCH v2] " Sudip Mukherjee
@ 2015-09-16 16:54 ` Alan Stern
2015-09-18 5:48 ` Sudip Mukherjee
0 siblings, 1 reply; 9+ messages in thread
From: Alan Stern @ 2015-09-16 16:54 UTC (permalink / raw)
To: Sudip Mukherjee
Cc: Greg Kroah-Hartman, linux-kernel, linux-usb, Fabio Estevam,
Sergei Shtylyov
On Wed, 16 Sep 2015, Sudip Mukherjee wrote:
> On error find_tt() returns either a NULL pointer or the error value in
> ERR_PTR. But we were dereferencing it directly without even checking if
> find_tt() returned a valid pointer or not.
>
> Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
> ---
>
> v2: used IS_ERR_OR_NULL (didn't know it was there. thanks)
>
>
> drivers/usb/host/ehci-sched.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
> index f9a3327..de75343 100644
> --- a/drivers/usb/host/ehci-sched.c
> +++ b/drivers/usb/host/ehci-sched.c
> @@ -257,6 +257,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
> @@ -1373,6 +1375,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
This patch isn't needed. In both reserve_release_intr_bandwidth() and
reserve_release_iso_bandwidth() it is known that find_tt() will return
a valid pointer.
This is because each of those functions is called from only one place.
For example, reserve_release_intr_bandwidth() is called only at the end
of qh_schedule(). But near the start of qh_schedule() there is earlier
call to tt_find(), and there we do test for error pointers. If the
first call doesn't return an error then the second call won't either.
The same sort of thing happens in reserve_release_iso_bandwidth().
Alan Stern
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] USB: EHCI: fix dereference of ERR_PTR
2015-09-16 16:54 ` Alan Stern
@ 2015-09-18 5:48 ` Sudip Mukherjee
2015-09-18 14:45 ` Alan Stern
0 siblings, 1 reply; 9+ messages in thread
From: Sudip Mukherjee @ 2015-09-18 5:48 UTC (permalink / raw)
To: Alan Stern
Cc: Greg Kroah-Hartman, linux-kernel, linux-usb, Fabio Estevam,
Sergei Shtylyov
On Wed, Sep 16, 2015 at 12:54:03PM -0400, Alan Stern wrote:
> On Wed, 16 Sep 2015, Sudip Mukherjee wrote:
>
> > On error find_tt() returns either a NULL pointer or the error value in
> > ERR_PTR. But we were dereferencing it directly without even checking if
> > find_tt() returned a valid pointer or not.
> >
> > Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
> > ---
<snip>
> > @@ -1373,6 +1375,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
>
> This patch isn't needed. In both reserve_release_intr_bandwidth() and
> reserve_release_iso_bandwidth() it is known that find_tt() will return
> a valid pointer.
>
> This is because each of those functions is called from only one place.
> For example, reserve_release_intr_bandwidth() is called only at the end
> of qh_schedule(). But near the start of qh_schedule() there is earlier
> call to tt_find(), and there we do test for error pointers. If the
> first call doesn't return an error then the second call won't either.
>
> The same sort of thing happens in reserve_release_iso_bandwidth().
Yes, I should have looked more before sending. Sorry for the noise.
But in those checkes for find_tt() only IS_ERR is checked, shouldn't we
check for IS_ERR_OR_NULL as find_tt() can return NULL also?
regards
sudip
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] USB: EHCI: fix dereference of ERR_PTR
2015-09-18 5:48 ` Sudip Mukherjee
@ 2015-09-18 14:45 ` Alan Stern
0 siblings, 0 replies; 9+ messages in thread
From: Alan Stern @ 2015-09-18 14:45 UTC (permalink / raw)
To: Sudip Mukherjee
Cc: Greg Kroah-Hartman, linux-kernel, linux-usb, Fabio Estevam,
Sergei Shtylyov
On Fri, 18 Sep 2015, Sudip Mukherjee wrote:
> On Wed, Sep 16, 2015 at 12:54:03PM -0400, Alan Stern wrote:
> > On Wed, 16 Sep 2015, Sudip Mukherjee wrote:
> >
> > > On error find_tt() returns either a NULL pointer or the error value in
> > > ERR_PTR. But we were dereferencing it directly without even checking if
> > > find_tt() returned a valid pointer or not.
> > >
> > > Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
> > > ---
> <snip>
> > > @@ -1373,6 +1375,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
> >
> > This patch isn't needed. In both reserve_release_intr_bandwidth() and
> > reserve_release_iso_bandwidth() it is known that find_tt() will return
> > a valid pointer.
> >
> > This is because each of those functions is called from only one place.
> > For example, reserve_release_intr_bandwidth() is called only at the end
> > of qh_schedule(). But near the start of qh_schedule() there is earlier
> > call to tt_find(), and there we do test for error pointers. If the
> > first call doesn't return an error then the second call won't either.
> >
> > The same sort of thing happens in reserve_release_iso_bandwidth().
> Yes, I should have looked more before sending. Sorry for the noise.
> But in those checkes for find_tt() only IS_ERR is checked, shouldn't we
> check for IS_ERR_OR_NULL as find_tt() can return NULL also?
I knew someone would ask about that! :-)
The NULL case is similar to the ERR_PTR case, but more complicated.
Basically, find_tt() returns NULL only when the device doesn't lie
below a TT -- all the other invalid returns are ERR_PTRs.
In reserve_release_intr_bandwidth(), for instance, the call to
find_tt() occurs only if tt_usecs = qh->ps.tt_usecs is nonzero. This
value is guaranteed to be 0 if the device doesn't run at low speed or
full speed -- see qh_make() in ehci-q.c, where qh->ps.tt_usecs is
initialized only when urb->dev->speed != USB_SPEED_HIGH.
To see that udev->tt is non-NULL whenever the speed isn't
USB_SPEED_HIGH, you have to look through the hub driver code. The
relevant routine is hub_port_init() in core/hub.c, the section headed
by the comment:
/* Set up TT records, if needed */
Similar reasoning applies to reserve_release_iso_bandwidth(); here the
condition is that stream->splits is nonzero, which is true only if the
device is full speed (see iso_stream_init()).
Alan Stern
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] USB: EHCI: fix dereference of ERR_PTR
2015-09-16 14:08 [PATCH] USB: EHCI: fix dereference of ERR_PTR Sudip Mukherjee
` (2 preceding siblings ...)
2015-09-16 16:22 ` [PATCH v2] " Sudip Mukherjee
@ 2015-09-21 2:48 ` Lu, Baolu
2015-09-21 4:49 ` Sudip Mukherjee
3 siblings, 1 reply; 9+ messages in thread
From: Lu, Baolu @ 2015-09-21 2:48 UTC (permalink / raw)
To: Sudip Mukherjee, Alan Stern, Greg Kroah-Hartman; +Cc: linux-kernel, linux-usb
On 09/16/2015 10:08 PM, Sudip Mukherjee wrote:
> On error find_tt() returns either a NULL pointer or the error value in
> ERR_PTR. But we were dereferencing it directly without even checking if
> find_tt() returned a valid pointer or not.
>
> Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
> ---
> drivers/usb/host/ehci-sched.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
> index f9a3327..27bced7 100644
> --- a/drivers/usb/host/ehci-sched.c
> +++ b/drivers/usb/host/ehci-sched.c
> @@ -257,6 +257,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 (!tt || IS_ERR(tt))
Why not IS_ERR_OR_NULL()?
> + return;
> if (sign > 0)
> list_add_tail(&qh->ps.ps_list, &tt->ps_list);
> else
> @@ -1373,6 +1375,8 @@ static void reserve_release_iso_bandwidth(struct ehci_hcd *ehci,
> }
>
> tt = find_tt(stream->ps.udev);
> + if (!tt || IS_ERR(tt))
> + return;
> if (sign > 0)
> list_add_tail(&stream->ps.ps_list, &tt->ps_list);
> else
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] USB: EHCI: fix dereference of ERR_PTR
2015-09-21 2:48 ` [PATCH] " Lu, Baolu
@ 2015-09-21 4:49 ` Sudip Mukherjee
0 siblings, 0 replies; 9+ messages in thread
From: Sudip Mukherjee @ 2015-09-21 4:49 UTC (permalink / raw)
To: Lu, Baolu; +Cc: Alan Stern, Greg Kroah-Hartman, linux-kernel, linux-usb
On Mon, Sep 21, 2015 at 10:48:52AM +0800, Lu, Baolu wrote:
>
>
> On 09/16/2015 10:08 PM, Sudip Mukherjee wrote:
> >On error find_tt() returns either a NULL pointer or the error value in
> >ERR_PTR. But we were dereferencing it directly without even checking if
> >find_tt() returned a valid pointer or not.
> >
> >Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
> >---
> > drivers/usb/host/ehci-sched.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> >diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
> >index f9a3327..27bced7 100644
> >--- a/drivers/usb/host/ehci-sched.c
> >+++ b/drivers/usb/host/ehci-sched.c
> >@@ -257,6 +257,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 (!tt || IS_ERR(tt))
>
> Why not IS_ERR_OR_NULL()?
This was v1, corrected in v2. And Alan has already explained why this
patch is not required.
regards
sudip
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-09-21 4:50 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-16 14:08 [PATCH] USB: EHCI: fix dereference of ERR_PTR Sudip Mukherjee
2015-09-16 14:16 ` Fabio Estevam
2015-09-16 14:25 ` Sergei Shtylyov
2015-09-16 16:22 ` [PATCH v2] " Sudip Mukherjee
2015-09-16 16:54 ` Alan Stern
2015-09-18 5:48 ` Sudip Mukherjee
2015-09-18 14:45 ` Alan Stern
2015-09-21 2:48 ` [PATCH] " Lu, Baolu
2015-09-21 4:49 ` Sudip Mukherjee
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).