* Re: [PATCH] usb: renesas_usbhs: fix NULL pointer dereference in dma_release_channel()
2015-01-30 6:58 [PATCH] usb: renesas_usbhs: fix NULL pointer dereference in dma_release_channel() Yoshihiro Shimoda
@ 2015-01-30 9:59 ` Geert Uytterhoeven
2015-01-30 13:38 ` Simon Horman
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2015-01-30 9:59 UTC (permalink / raw)
To: linux-sh
Hi Shimoda-san,
On Fri, Jan 30, 2015 at 7:58 AM, Yoshihiro Shimoda
<yoshihiro.shimoda.uh@renesas.com> wrote:
> This patch fixes an issue that the following commit causes NULL
> pointer dereference in dma_release_channel().
> "usb: renesas_usbhs: add support for requesting DT DMA"
> (commit id abd2dbf6bb1b5f3a03a8c76b1a8879da1dd30caa)
Thanks for your patch!
> The usbhsf_dma_init_dt() should set fifo->{t,r}x_chan to NULL if
> dma_request_slave_channel_reason() returns IS_ERR value.
> Otherwise, usbhsf_dma_quit() will call dma_release_channel(), and then
> NULL pointer dereference happens.
I guess it also causes other problems?
The return value of usbhsf_dma_chan_get() is not checked for an error
code in many callsites.
> Reported-by: Simon Horman <horms@verge.net.au>
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---
> This patch is based on Felipe's usb.git / testing/next branch.
> (commit id }b3990cb707ff91cd6507d53a0a730afe97)
>
> drivers/usb/renesas_usbhs/fifo.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c
> index 4c086b1..d891bff 100644
> --- a/drivers/usb/renesas_usbhs/fifo.c
> +++ b/drivers/usb/renesas_usbhs/fifo.c
> @@ -1072,7 +1072,11 @@ static void usbhsf_dma_init_pdev(struct usbhs_fifo *fifo)
> static void usbhsf_dma_init_dt(struct device *dev, struct usbhs_fifo *fifo)
> {
> fifo->tx_chan = dma_request_slave_channel_reason(dev, "tx");
> + if (IS_ERR(fifo->tx_chan))
> + fifo->tx_chan = NULL;
> fifo->rx_chan = dma_request_slave_channel_reason(dev, "rx");
> + if (IS_ERR(fifo->rx_chan))
> + fifo->rx_chan = NULL;
> }
My first thought was: shouldn't it be handled in usbhsf_dma_init() instead,
so it applies to both the legacy platform data and the DT case?
But apparently dma_request_channel() returns NULL on failure, while
dma_request_slave_channel_reason() returns an error code. Oh well...
Remapping the error to NULL does mean the driver doesn't handle
-EPROBE_DEFER, but that's tricky with DMA engines anyway, cfr. commit
55f5f9862a31e2ac ("i2c: sh_mobile: rework deferred probing")
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] usb: renesas_usbhs: fix NULL pointer dereference in dma_release_channel()
2015-01-30 6:58 [PATCH] usb: renesas_usbhs: fix NULL pointer dereference in dma_release_channel() Yoshihiro Shimoda
2015-01-30 9:59 ` Geert Uytterhoeven
@ 2015-01-30 13:38 ` Simon Horman
2015-02-02 5:40 ` yoshihiro shimoda
2015-02-02 6:03 ` yoshihiro shimoda
3 siblings, 0 replies; 5+ messages in thread
From: Simon Horman @ 2015-01-30 13:38 UTC (permalink / raw)
To: linux-sh
On Fri, Jan 30, 2015 at 03:58:23PM +0900, Yoshihiro Shimoda wrote:
> This patch fixes an issue that the following commit causes NULL
> pointer dereference in dma_release_channel().
> "usb: renesas_usbhs: add support for requesting DT DMA"
> (commit id abd2dbf6bb1b5f3a03a8c76b1a8879da1dd30caa)
>
> The usbhsf_dma_init_dt() should set fifo->{t,r}x_chan to NULL if
> dma_request_slave_channel_reason() returns IS_ERR value.
> Otherwise, usbhsf_dma_quit() will call dma_release_channel(), and then
> NULL pointer dereference happens.
>
> Reported-by: Simon Horman <horms@verge.net.au>
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
I have tested this on the lager and koelsch boards using
shmobile_defconfig and next-20150129 as a base. The environment
where I originally observed the problem.
Tested-by: Simon Horman <horms+renesas@verge.net.au>
> ---
> This patch is based on Felipe's usb.git / testing/next branch.
> (commit id }b3990cb707ff91cd6507d53a0a730afe97)
>
> drivers/usb/renesas_usbhs/fifo.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c
> index 4c086b1..d891bff 100644
> --- a/drivers/usb/renesas_usbhs/fifo.c
> +++ b/drivers/usb/renesas_usbhs/fifo.c
> @@ -1072,7 +1072,11 @@ static void usbhsf_dma_init_pdev(struct usbhs_fifo *fifo)
> static void usbhsf_dma_init_dt(struct device *dev, struct usbhs_fifo *fifo)
> {
> fifo->tx_chan = dma_request_slave_channel_reason(dev, "tx");
> + if (IS_ERR(fifo->tx_chan))
> + fifo->tx_chan = NULL;
> fifo->rx_chan = dma_request_slave_channel_reason(dev, "rx");
> + if (IS_ERR(fifo->rx_chan))
> + fifo->rx_chan = NULL;
> }
>
> static void usbhsf_dma_init(struct usbhs_priv *priv,
> --
> 1.7.9.5
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] usb: renesas_usbhs: fix NULL pointer dereference in dma_release_channel()
2015-01-30 6:58 [PATCH] usb: renesas_usbhs: fix NULL pointer dereference in dma_release_channel() Yoshihiro Shimoda
2015-01-30 9:59 ` Geert Uytterhoeven
2015-01-30 13:38 ` Simon Horman
@ 2015-02-02 5:40 ` yoshihiro shimoda
2015-02-02 6:03 ` yoshihiro shimoda
3 siblings, 0 replies; 5+ messages in thread
From: yoshihiro shimoda @ 2015-02-02 5:40 UTC (permalink / raw)
To: linux-sh
SGkgR2VlcnQtc2FuLA0KDQo+IEhpIFNoaW1vZGEtc2FuLA0KPiANCj4gT24gRnJpLCBKYW4gMzAs
IDIwMT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JvciBjb2RlLiBPaCB3ZWxsLi4uDQo+IA0KPiBSZW1hcHBpbmcgdGhlIGVycm9yIHRvIE5V
TEwgZG9lcyBtZWFuIHRoZSBkcml2ZXIgZG9lc24ndCBoYW5kbGUNCj4gLUVQUk9CRV9ERUZFUiwg
YnV0IHRoYXQncyB0cmlja3kgd2l0aCBETUEgZW5naW5lcyBhbnl3YXksIGNmci4gY29tbWl0DQo+
IDU1ZjVmOTg2MmEzMWUyYWMgKCJpMmM6IHNoX21vYmlsZTogcmV3b3JrIGRlZmVycmVkIHByb2Jp
bmciKQ0KPiANCj4gR3J7b2V0amUsZWV0aW5nfXMsDQo+IA0KPiAgICAgICAgICAgICAgICAgICAg
ICAgICBHZWVydA0KPiANCj4gLS0NCj4gR2VlcnQgVXl0dGVyaG9ldmVuIC0tIFRoZXJlJ3MgbG90
cyBvZiBMaW51eCBiZXlvbmQgaWEzMiAtLSBnZWVydEBsaW51eC1tNjhrLm9yZw0KPiANCj4gSW4g
cGVyc29uYWwgY29udmVyc2F0aW9ucyB3aXRoIHRlY2huaWNhbCBwZW9wbGUsIEkgY2FsbCBteXNl
bGYgYSBoYWNrZXIuIEJ1dA0KPiB3aGVuIEknbSB0YWxraW5nIHRvIGpvdXJuYWxpc3RzIEkganVz
dCBzYXkgInByb2dyYW1tZXIiIG9yIHNvbWV0aGluZyBsaWtlIHRoYXQuDQo+ICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgLS0gTGludXMgVG9ydmFsZHMNCg=
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] usb: renesas_usbhs: fix NULL pointer dereference in dma_release_channel()
2015-01-30 6:58 [PATCH] usb: renesas_usbhs: fix NULL pointer dereference in dma_release_channel() Yoshihiro Shimoda
` (2 preceding siblings ...)
2015-02-02 5:40 ` yoshihiro shimoda
@ 2015-02-02 6:03 ` yoshihiro shimoda
3 siblings, 0 replies; 5+ messages in thread
From: yoshihiro shimoda @ 2015-02-02 6:03 UTC (permalink / raw)
To: linux-sh
Hi Simon-san,
>
> On Fri, Jan 30, 2015 at 03:58:23PM +0900, Yoshihiro Shimoda wrote:
> > This patch fixes an issue that the following commit causes NULL
> > pointer dereference in dma_release_channel().
> > "usb: renesas_usbhs: add support for requesting DT DMA"
> > (commit id abd2dbf6bb1b5f3a03a8c76b1a8879da1dd30caa)
> >
> > The usbhsf_dma_init_dt() should set fifo->{t,r}x_chan to NULL if
> > dma_request_slave_channel_reason() returns IS_ERR value.
> > Otherwise, usbhsf_dma_quit() will call dma_release_channel(), and then
> > NULL pointer dereference happens.
> >
> > Reported-by: Simon Horman <horms@verge.net.au>
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
>
> I have tested this on the lager and koelsch boards using
> shmobile_defconfig and next-20150129 as a base. The environment
> where I originally observed the problem.
>
> Tested-by: Simon Horman <horms+renesas@verge.net.au>
Thank you for the test!
Best regards,
Yoshihiro Shimoda
> > ---
> > This patch is based on Felipe's usb.git / testing/next branch.
> > (commit id }b3990cb707ff91cd6507d53a0a730afe97)
> >
> > drivers/usb/renesas_usbhs/fifo.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c
> > index 4c086b1..d891bff 100644
> > --- a/drivers/usb/renesas_usbhs/fifo.c
> > +++ b/drivers/usb/renesas_usbhs/fifo.c
> > @@ -1072,7 +1072,11 @@ static void usbhsf_dma_init_pdev(struct usbhs_fifo *fifo)
> > static void usbhsf_dma_init_dt(struct device *dev, struct usbhs_fifo *fifo)
> > {
> > fifo->tx_chan = dma_request_slave_channel_reason(dev, "tx");
> > + if (IS_ERR(fifo->tx_chan))
> > + fifo->tx_chan = NULL;
> > fifo->rx_chan = dma_request_slave_channel_reason(dev, "rx");
> > + if (IS_ERR(fifo->rx_chan))
> > + fifo->rx_chan = NULL;
> > }
> >
> > static void usbhsf_dma_init(struct usbhs_priv *priv,
> > --
> > 1.7.9.5
> >
^ permalink raw reply [flat|nested] 5+ messages in thread