From: Mauro Carvalho Chehab <m.chehab@samsung.com>
To: Alexey Khoroshilov <khoroshilov@ispras.ru>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
ldv-project@linuxtesting.org
Subject: Re: [PATCH] [media] dvb_demux: fix deadlock in dmx_section_feed_release_filter()
Date: Thu, 26 Sep 2013 14:08:08 -0300 [thread overview]
Message-ID: <20130926140808.729bad49@samsung.com> (raw)
In-Reply-To: <1376772531-8963-1-git-send-email-khoroshilov@ispras.ru>
Em Sat, 17 Aug 2013 23:48:51 +0300
Alexey Khoroshilov <khoroshilov@ispras.ru> escreveu:
> dmx_section_feed_release_filter() locks dvbdmx->mutex and
> if the feed is still filtering, it calls feed->stop_filtering(feed).
> stop_filtering() is implemented by dmx_section_feed_stop_filtering()
> that first of all try to lock the same mutex: dvbdmx->mutex.
> That leads to a deadlock.
>
> It does not happen often in practice because all callers of
> release_filter() stop filtering by themselves.
> So the problem can happen in case of race condition only.
>
> The patch proposes to unlock dvbdmx->mutex before call feed->stop_filtering(feed)
> and recheck feed->is_filtering after reacquiring mutex.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> ---
> drivers/media/dvb-core/dvb_demux.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/dvb-core/dvb_demux.c b/drivers/media/dvb-core/dvb_demux.c
> index 3485655..9d517af 100644
> --- a/drivers/media/dvb-core/dvb_demux.c
> +++ b/drivers/media/dvb-core/dvb_demux.c
> @@ -1027,8 +1027,11 @@ static int dmx_section_feed_release_filter(struct dmx_section_feed *feed,
> return -EINVAL;
> }
>
> - if (feed->is_filtering)
> + while (feed->is_filtering) {
Changing from if to while here can cause a dead lock, as, if the device
got removed, dmx_section_feed_stop_filtering() won't touch
feed->is_filtering. So, the loop will happen forever.
Except for that the patch looks correct on my eyes.
> + mutex_unlock(&dvbdmx->mutex);
Please add a small comment about why the mutex needs to be unlocked
there, as this looks ugly, and likely deserve some cleanups in the future
(as both the spinclock and the mutex are taken on both callback and at
the release filter function).
> feed->stop_filtering(feed);
> + mutex_lock(&dvbdmx->mutex);
> + }
>
> spin_lock_irq(&dvbdmx->lock);
> f = dvbdmxfeed->filter;
Thanks!
Mauro
next prev parent reply other threads:[~2013-09-26 17:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-17 20:48 [PATCH] [media] dvb_demux: fix deadlock in dmx_section_feed_release_filter() Alexey Khoroshilov
2013-09-26 17:08 ` Mauro Carvalho Chehab [this message]
2013-10-07 21:04 ` [PATCH v2] " Alexey Khoroshilov
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=20130926140808.729bad49@samsung.com \
--to=m.chehab@samsung.com \
--cc=khoroshilov@ispras.ru \
--cc=ldv-project@linuxtesting.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.