]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
nbd: fix possible overflow on 'first_minor' in nbd_dev_add()
authorZhang Wensheng <zhangwensheng5@huawei.com>
Thu, 10 Mar 2022 09:32:24 +0000 (17:32 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Apr 2022 12:06:54 +0000 (14:06 +0200)
commitd42740aab3ea29578d11a042bb50ded12ad3aa8a
treeef0081a767186ca7f89993580509487d0700d1d5
parent7e11d8a32855313970dbc8302332f910a018853e
nbd: fix possible overflow on 'first_minor' in nbd_dev_add()

commit 6d35d04a9e18990040e87d2bbf72689252669d54 upstream.

When 'index' is a big numbers, it may become negative which forced
to 'int'. then 'index << part_shift' might overflow to a positive
value that is not greater than '0xfffff', then sysfs might complains
about duplicate creation. Because of this, move the 'index' judgment
to the front will fix it and be better.

Fixes: b0d9111a2d53 ("nbd: use an idr to keep track of nbd devices")
Fixes: 940c264984fd ("nbd: fix possible overflow for 'first_minor' in nbd_dev_add()")
Signed-off-by: Zhang Wensheng <zhangwensheng5@huawei.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Link: https://lore.kernel.org/r/20220310093224.4002895-1-zhangwensheng5@huawei.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/block/nbd.c