From: Eric Biggers <ebiggers3@gmail.com>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: syzbot
<bot+4684a000d5abdade83fac55b1e7d1f935ef1936e@syzkaller.appspotmail.com>,
axboe@kernel.dk, linux-block@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
syzkaller-bugs@googlegroups.com
Subject: Re: possible deadlock in blkdev_reread_part
Date: Sun, 5 Nov 2017 12:18:34 -0800 [thread overview]
Message-ID: <20171105201834.GA8126@zzz.localdomain> (raw)
In-Reply-To: <CACT4Y+bGjnajib6P4a0SxYkNUJpg_x8abEkec8AR+oBmC=-QUQ@mail.gmail.com>
On Wed, Nov 01, 2017 at 10:02:44PM +0300, 'Dmitry Vyukov' via syzkaller-bugs wrote:
>
> Still happens on linux-next 36ef71cae353f88fd6e095e2aaa3e5953af1685d (Oct 20).
> Note repro needs to be compiled with -m32
>
> [ 243.819514] ======================================================
> [ 243.820949] WARNING: possible circular locking dependency detected
> [ 243.822417] 4.14.0-rc5-next-20171018 #15 Not tainted
> [ 243.823592] ------------------------------------------------------
> [ 243.825012] a.out/11871 is trying to acquire lock:
> [ 243.826182] (&bdev->bd_mutex){+.+.}, at: [<ffffffff8245f13e>]
> blkdev_reread_part+0x1e/0x40
> [ 243.828317]
> [ 243.828317] but task is already holding lock:
> [ 243.829669] (&lo->lo_ctl_mutex#2){+.+.}, at: [<ffffffff83867189>]
> lo_compat_ioctl+0x119/0x150
> [ 243.831728]
> [ 243.831728] which lock already depends on the new lock.
> [ 243.831728]
> [ 243.833373]
Here's a simplified reproducer:
#include <fcntl.h>
#include <linux/loop.h>
#include <sys/ioctl.h>
#include <unistd.h>
int main()
{
int loopfd, fd;
struct loop_info info = { .lo_flags = LO_FLAGS_PARTSCAN };
loopfd = open("/dev/loop0", O_RDWR);
fd = open("/bin/ls", O_RDONLY);
ioctl(loopfd, LOOP_SET_FD, fd);
ioctl(loopfd, LOOP_SET_STATUS, &info);
}
It still needs to be compiled with -m32. The reason is that lo_ioctl() has:
mutex_lock_nested(&lo->lo_ctl_mutex, 1);
but lo_compat_ioctl() has:
mutex_lock(&lo->lo_ctl_mutex);
But ->lo_ctl_mutex isn't actually being nested under itself, so I don't think
the "nested" annotation is actually appropriate.
It seems that ->bd_mutex is held while opening and closing block devices, which
should rank it above both ->lo_ctl_mutex and loop_index_mutex (see lo_open() and
lo_release()).
But blkdev_reread_part(), which takes ->bd_mutex, is called from some of the
ioctls while ->lo_ctl_mutex is held.
Perhaps we should call blkdev_reread_part() at the end of the ioctls, after
->lo_ctl_mutex has been dropped? But it looks like that can do I/O to the
device, which probably could race with loop_clr_fd()...
Or perhaps we should just take both locks for the ioctls, in the order
->bd_mutex, then ->lo_ctl_mutex -- and then use __blkdev_reread_part()?
Eric
next prev parent reply other threads:[~2017-11-05 20:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <001a11446e86e97ceb055cf07f4e@google.com>
2017-11-01 19:02 ` possible deadlock in blkdev_reread_part Dmitry Vyukov
2017-11-05 20:18 ` Eric Biggers [this message]
[not found] ` <201804162302.GBI43737.OLFSOFQHVJMFtO@I-love.SAKURA.ne.jp>
[not found] ` <201804202306.FGC05220.OOJFMFOSFHtLQV@I-love.SAKURA.ne.jp>
2018-05-09 10:54 ` [PATCH v2] block/loop: Serialize ioctl operations Tetsuo Handa
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=20171105201834.GA8126@zzz.localdomain \
--to=ebiggers3@gmail.com \
--cc=axboe@kernel.dk \
--cc=bot+4684a000d5abdade83fac55b1e7d1f935ef1936e@syzkaller.appspotmail.com \
--cc=dvyukov@google.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=syzkaller-bugs@googlegroups.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