* [PATCH] loop: fix to a race condition due to the early registration of device
[not found] <CACVXFVN-pKP5zePBvUtKkpEkOi=1fr+ePsudxbciN993BHGzNA@mail.gmail.com>
@ 2017-08-07 12:37 ` Anton Volkov
2017-08-07 12:54 ` Johannes Thumshirn
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Anton Volkov @ 2017-08-07 12:37 UTC (permalink / raw)
To: tom.leiming
Cc: axboe, osandov, linux-kernel, linux-block, ldv-project,
khoroshilov, Anton Volkov
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>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
---
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] loop: fix to a race condition due to the early registration of device
2017-08-07 12:37 ` [PATCH] loop: fix to a race condition due to the early registration of device Anton Volkov
@ 2017-08-07 12:54 ` Johannes Thumshirn
2017-08-07 13:09 ` Anton Volkov
2017-08-08 22:00 ` Omar Sandoval
2017-08-15 18:51 ` Jens Axboe
2 siblings, 1 reply; 7+ messages in thread
From: Johannes Thumshirn @ 2017-08-07 12:54 UTC (permalink / raw)
To: Anton Volkov
Cc: tom.leiming, axboe, osandov, linux-kernel, linux-block,
ldv-project, khoroshilov
On Mon, Aug 07, 2017 at 03:37:50PM +0300, Anton Volkov wrote:
> +err_out:
> return err;
Any reason you can't just use return err; at the respective callsites?
Thanks,
Johannes
--
Johannes Thumshirn Storage
jthumshirn@suse.de +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] loop: fix to a race condition due to the early registration of device
2017-08-07 12:54 ` Johannes Thumshirn
@ 2017-08-07 13:09 ` Anton Volkov
2017-08-07 13:24 ` Johannes Thumshirn
0 siblings, 1 reply; 7+ messages in thread
From: Anton Volkov @ 2017-08-07 13:09 UTC (permalink / raw)
To: Johannes Thumshirn
Cc: tom.leiming, axboe, osandov, linux-kernel, linux-block,
ldv-project, khoroshilov
This is more of a style-oriented suggestion. This kind of template is
commonly used in other modules.
Regards,
Anton
On 07.08.2017 15:54, Johannes Thumshirn wrote:
> On Mon, Aug 07, 2017 at 03:37:50PM +0300, Anton Volkov wrote:
>> +err_out:
>> return err;
>
> Any reason you can't just use return err; at the respective callsites?
>
> Thanks,
> Johannes
>
-- Anton Volkov
Linux Verification Center, ISPRAS
web: http://linuxtesting.org
e-mail: avolkov@ispras.ru
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] loop: fix to a race condition due to the early registration of device
2017-08-07 13:09 ` Anton Volkov
@ 2017-08-07 13:24 ` Johannes Thumshirn
0 siblings, 0 replies; 7+ messages in thread
From: Johannes Thumshirn @ 2017-08-07 13:24 UTC (permalink / raw)
To: Anton Volkov
Cc: tom.leiming, axboe, osandov, linux-kernel, linux-block,
ldv-project, khoroshilov
On Mon, Aug 07, 2017 at 04:09:12PM +0300, Anton Volkov wrote:
> This is more of a style-oriented suggestion. This kind of template is
> commonly used in other modules.
Yes but there is no point in using gotos here (i.e. cleanup to be done), you
an just return directly.
And yes it is a minor nit.
Anyways,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
--
Johannes Thumshirn Storage
jthumshirn@suse.de +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] loop: fix to a race condition due to the early registration of device
2017-08-07 12:37 ` [PATCH] loop: fix to a race condition due to the early registration of device Anton Volkov
2017-08-07 12:54 ` Johannes Thumshirn
@ 2017-08-08 22:00 ` Omar Sandoval
2017-08-10 15:46 ` Anton Volkov
2017-08-15 18:51 ` Jens Axboe
2 siblings, 1 reply; 7+ messages in thread
From: Omar Sandoval @ 2017-08-08 22:00 UTC (permalink / raw)
To: Anton Volkov
Cc: tom.leiming, axboe, osandov, linux-kernel, linux-block,
ldv-project, khoroshilov
On Mon, Aug 07, 2017 at 03:37:50PM +0300, Anton Volkov wrote:
> 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>
> Reviewed-by: Ming Lei <ming.lei@redhat.com>
Hi, Anton,
Were you able to reproduce this issue or was it purely theoretical? If
the former, it'd be nice if you could add a test case to blktests [1].
1: https://github.com/osandov/blktests
Thanks!
Omar
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] loop: fix to a race condition due to the early registration of device
2017-08-08 22:00 ` Omar Sandoval
@ 2017-08-10 15:46 ` Anton Volkov
0 siblings, 0 replies; 7+ messages in thread
From: Anton Volkov @ 2017-08-10 15:46 UTC (permalink / raw)
To: Omar Sandoval
Cc: tom.leiming, axboe, osandov, linux-kernel, linux-block,
ldv-project, khoroshilov
Hello, Omar.
It was a purely theoretical race that had been considered to be possible
in real-life.
Regards,
Anton
On 09.08.2017 01:00, Omar Sandoval wrote:
> On Mon, Aug 07, 2017 at 03:37:50PM +0300, Anton Volkov wrote:
>> 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>
>> Reviewed-by: Ming Lei <ming.lei@redhat.com>
>
> Hi, Anton,
>
> Were you able to reproduce this issue or was it purely theoretical? If
> the former, it'd be nice if you could add a test case to blktests [1].
>
> 1: https://github.com/osandov/blktests
>
> Thanks!
> Omar
>
-- Anton Volkov
Linux Verification Center, ISPRAS
web: http://linuxtesting.org
e-mail: avolkov@ispras.ru
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] loop: fix to a race condition due to the early registration of device
2017-08-07 12:37 ` [PATCH] loop: fix to a race condition due to the early registration of device Anton Volkov
2017-08-07 12:54 ` Johannes Thumshirn
2017-08-08 22:00 ` Omar Sandoval
@ 2017-08-15 18:51 ` Jens Axboe
2 siblings, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2017-08-15 18:51 UTC (permalink / raw)
To: Anton Volkov, tom.leiming
Cc: osandov, linux-kernel, linux-block, ldv-project, khoroshilov
On 08/07/2017 06:37 AM, Anton Volkov wrote:
> 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).
Added for 4.14, thanks.
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-08-15 18:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CACVXFVN-pKP5zePBvUtKkpEkOi=1fr+ePsudxbciN993BHGzNA@mail.gmail.com>
2017-08-07 12:37 ` [PATCH] loop: fix to a race condition due to the early registration of device 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox