From: Anton Volkov <avolkov@ispras.ru>
To: tom.leiming@gmail.com
Cc: axboe@fb.com, osandov@fb.com, linux-kernel@vger.kernel.org,
ldv-project@linuxtesting.org, khoroshilov@ispras.ru,
Anton Volkov <avolkov@ispras.ru>
Subject: [PATCH] loop: fix to a race condition due to the early registration of device
Date: Thu, 3 Aug 2017 18:01:38 +0300 [thread overview]
Message-ID: <1501772498-28197-1-git-send-email-avolkov@ispras.ru> (raw)
In-Reply-To: <CACVXFVP-3gwmKkmATBUa=P-Tp1h1sZbZypfLkuOwDk60+E0PKQ@mail.gmail.com>
The early device registration made possible a race leading to allocations
of disks with wrong minors.
This patch moves the device registration further down the loop_init
function to make the race infeasible.
Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by: Anton Volkov <avolkov@ispras.ru>
---
drivers/block/loop.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index ef83349..2fbd4089 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1996,10 +1996,6 @@ static int __init loop_init(void)
struct loop_device *lo;
int err;
- err = misc_register(&loop_misc);
- if (err < 0)
- return err;
-
part_shift = 0;
if (max_part > 0) {
part_shift = fls(max_part);
@@ -2017,12 +2013,12 @@ static int __init loop_init(void)
if ((1UL << part_shift) > DISK_MAX_PARTS) {
err = -EINVAL;
- goto misc_out;
+ goto err_out;
}
if (max_loop > 1UL << (MINORBITS - part_shift)) {
err = -EINVAL;
- goto misc_out;
+ goto err_out;
}
/*
@@ -2041,6 +2037,11 @@ static int __init loop_init(void)
range = 1UL << MINORBITS;
}
+ err = misc_register(&loop_misc);
+ if (err < 0)
+ goto err_out;
+
+
if (register_blkdev(LOOP_MAJOR, "loop")) {
err = -EIO;
goto misc_out;
@@ -2060,6 +2061,7 @@ static int __init loop_init(void)
misc_out:
misc_deregister(&loop_misc);
+err_out:
return err;
}
--
2.7.4
next prev parent reply other threads:[~2017-08-03 15:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-28 15:55 Possible race in loop.ko Anton Volkov
2017-08-01 12:39 ` Ming Lei
2017-08-03 15:01 ` Anton Volkov [this message]
2017-08-07 2:39 ` [PATCH] loop: fix to a race condition due to the early registration of device Ming Lei
2017-08-07 12:37 ` Anton Volkov
2017-08-07 12:54 ` Johannes Thumshirn
2017-08-07 13:09 ` Anton Volkov
2017-08-07 13:24 ` Johannes Thumshirn
2017-08-08 22:00 ` Omar Sandoval
2017-08-10 15:46 ` Anton Volkov
2017-08-15 18:51 ` Jens Axboe
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=1501772498-28197-1-git-send-email-avolkov@ispras.ru \
--to=avolkov@ispras.ru \
--cc=axboe@fb.com \
--cc=khoroshilov@ispras.ru \
--cc=ldv-project@linuxtesting.org \
--cc=linux-kernel@vger.kernel.org \
--cc=osandov@fb.com \
--cc=tom.leiming@gmail.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;
as well as URLs for NNTP newsgroup(s).