From: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
To: Julia Lawall <Julia.Lawall@lip6.fr>
Cc: kernel-janitors@vger.kernel.org,
Mauro Carvalho Chehab <mchehab@redhat.com>,
Linux Media Mailing List <linux-media@vger.kernel.org>,
linux-kernel@vger.kernel.org,
Robert Jarzmik <robert.jarzmik@free.fr>
Subject: Re: [PATCH 1/2] drivers/media/platform/soc_camera/pxa_camera.c: reposition free_irq to avoid access to invalid data
Date: Mon, 7 Jan 2013 12:09:36 +0100 (CET) [thread overview]
Message-ID: <Pine.LNX.4.64.1301071111420.23972@axis700.grange> (raw)
In-Reply-To: <1357552816-6046-2-git-send-email-Julia.Lawall@lip6.fr>
(adding Robert to CC)
Hi Julia
Thanks for the patch.
On Mon, 7 Jan 2013, Julia Lawall wrote:
> From: Julia Lawall <Julia.Lawall@lip6.fr>
>
> The data referenced by an interrupt handler should not be freed before the
> interrupt is ended. The handler is pxa_camera_irq. This handler may call
> pxa_dma_start_channels, which references the channels that are freed on the
> lines before the call to free_irq.
I don't think any data is freed by pxa_free_dma(), it only disables DMA on
a certain channel. Theoretically there could be a different problem:
pxa_free_dma() deactivates DMA, whereas pxa_dma_start_channels() activates
it. But I think we're also protected against that: by the time
pxa_camera_remove() is called, and operation on the interface has been
stopped, client devices have been detached, pxa_camera_remove_device() has
been called, which has also stopped the interface clock. And with clock
stopped no interrupts can be generated. And the case of interrupt having
been generated before clk_disabled() and only delivered to the driver so
much later, that we're already unloading the module, seems really
impossible to me. Robert, you agree?
OTOH, it would be nice to convert also this driver to managed allocations,
which also would include devm_request(_threaded)_irq(), but that would
mean, that free_irq() would be called even later than now, also after
pxa_free_dma().
Speaking about managed allocations, those can be dangerous too: if you
request an IRQ before, say, remapping memory, or if you only use managed
IRQ requesting and ioremap() memory in your driver manually, that would be
wrong. But from a quick grep looks like most (all?) drivers get ir right -
first ioremap(), then request IRQ, but to be certain maybe coccinelle
could run a test for that too;-)
Thanks
Guennadi
> The semantic match that finds this problem is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @fn exists@
> expression list es;
> expression a,b;
> identifier f;
> @@
>
> if (...) {
> ... when any
> free_irq(a,b);
> ... when any
> f(es);
> ... when any
> return ...;
> }
>
> @@
> expression list fn.es;
> expression fn.a,fn.b;
> identifier fn.f;
> @@
>
> *f(es);
> ... when any
> *free_irq(a,b);
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
>
> ---
> Not compiled. I have not observed the problem in practice; the code just
> looks suspicious.
>
> drivers/media/platform/soc_camera/pxa_camera.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/soc_camera/pxa_camera.c b/drivers/media/platform/soc_camera/pxa_camera.c
> index f91f7bf..2a19aba 100644
> --- a/drivers/media/platform/soc_camera/pxa_camera.c
> +++ b/drivers/media/platform/soc_camera/pxa_camera.c
> @@ -1810,10 +1810,10 @@ static int pxa_camera_remove(struct platform_device *pdev)
>
> clk_put(pcdev->clk);
>
> + free_irq(pcdev->irq, pcdev);
> pxa_free_dma(pcdev->dma_chans[0]);
> pxa_free_dma(pcdev->dma_chans[1]);
> pxa_free_dma(pcdev->dma_chans[2]);
> - free_irq(pcdev->irq, pcdev);
>
> soc_camera_host_unregister(soc_host);
>
>
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
next prev parent reply other threads:[~2013-01-07 11:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-07 10:00 [PATCH 0/2] " Julia Lawall
2013-01-07 10:00 ` [PATCH 1/2] drivers/media/platform/soc_camera/pxa_camera.c: " Julia Lawall
2013-01-07 11:09 ` Guennadi Liakhovetski [this message]
2013-01-07 11:18 ` Julia Lawall
2013-01-07 11:33 ` Guennadi Liakhovetski
2013-01-07 20:08 ` Robert Jarzmik
2013-01-07 21:09 ` Julia Lawall
2013-01-07 10:00 ` [PATCH 2/2] drivers/crypto/bfin_crc.c: " Julia Lawall
2013-01-20 0:12 ` Herbert Xu
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=Pine.LNX.4.64.1301071111420.23972@axis700.grange \
--to=g.liakhovetski@gmx.de \
--cc=Julia.Lawall@lip6.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@redhat.com \
--cc=robert.jarzmik@free.fr \
/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
all inboxes | Powered by JetHome®