public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Cc: Anton Volkov <avolkov@ispras.ru>,
	Linux-Kernel <linux-kernel@vger.kernel.org>,
	Alexey Khoroshilov <khoroshilov@ispras.ru>,
	ldv-project@linuxtesting.org, dmaengine@vger.kernel.org,
	vinod.koul@intel.com, geert+renesas@glider.be,
	niklas.soderlund+renesas@ragnatech.se
Subject: Re: Possible null pointer dereference in rcar-dmac.ko
Date: Wed, 09 Aug 2017 10:58:28 +0300	[thread overview]
Message-ID: <1966479.zaHQfZ4vb1@avalon> (raw)
In-Reply-To: <871solfu5n.wl%kuninori.morimoto.gx@renesas.com>

Hello,

On Wednesday 09 Aug 2017 00:49:40 Kuninori Morimoto wrote:
> Hi Anton
> 
> # add Laurent
> 
> > While searching for races in the Linux kernel I've come across
> > "drivers/dma/sh/rcar-dmac.ko" module. Here is a question that I came
> > up with while analyzing results. Lines are given using the info from
> > Linux v4.12.
> > 
> > Consider the following case:
> > 
> > Thread 1:                            Thread 2:
> > rcar_dmac_probe
> > ->rcar_dmac_chan_probe
> > 
> >              (&dmac->channels[i])
> >     
> >     rchan = &dmac->channels[i]
> >     chan = &rchan->chan
> >     devm_request_threaded_irq(rchan)
> >     chan->device = &dmac->engine    rcar_dmac_isr_channel
> >     
> >                                     ->rcar_dmac_isr_transfer_end(chan)
> >                                     
> >                                       ->rcar_dmac_chan_start_xfer(chan)
> >   
> >   engine->dev = &pdev->dev;               <READ chan->chan.device->dev>
> >   (rcar-dmac.c: line 1828)                (rcar-dmac.c: line 351)
> > 
> > As far as I understand engine->dev is NULL before its initialization
> > in probe. Thus there might be a NULL pointer dereference in
> > rcar_dmac_chan_start_xfer while accessing chan->chan.device->dev which
> > is equal to (&dmac->engine)->dev. Is this possible from your point of
> > view?
> 
> Very rare case, but not impossible (?).
> I think these engine->xxx initialize should be done before
> of_dma_controller_register();
> engine.channels is initialized independently somehow...

There should be no interrupt pending at the time the interrupt handler is 
registered, but to be safe it's indeed a good practice to register the 
interrupt handler after everything else has been initialized. Patches are 
welcome :-)

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2017-08-09  7:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-08 12:09 Possible null pointer dereference in rcar-dmac.ko Anton Volkov
2017-08-09  0:49 ` Kuninori Morimoto
2017-08-09  7:58   ` Laurent Pinchart [this message]
2017-08-10  2:09     ` Kuninori Morimoto
2017-08-10 14:59       ` Laurent Pinchart
2017-08-21  6:15         ` Kuninori Morimoto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1966479.zaHQfZ4vb1@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=avolkov@ispras.ru \
    --cc=dmaengine@vger.kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=khoroshilov@ispras.ru \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=ldv-project@linuxtesting.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=niklas.soderlund+renesas@ragnatech.se \
    --cc=vinod.koul@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox