]> git.baikalelectronics.ru Git - kernel.git/commitdiff
loop: don't allow deleting an unspecified loop device
authorChristoph Hellwig <hch@lst.de>
Wed, 23 Jun 2021 14:59:06 +0000 (16:59 +0200)
committerJens Axboe <axboe@kernel.dk>
Wed, 30 Jun 2021 21:34:13 +0000 (15:34 -0600)
Passing a negative index to loop_lookup while return any unbound device.
Doing that for a delete does not make much sense, so add check to
explicitly reject that case.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20210623145908.92973-8-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/loop.c

index c18e2930ca11fabc76e5ce052f6c2058df7d67ac..b217065a6d67e0caf1fdb85539629789accf4998 100644 (file)
@@ -2404,6 +2404,11 @@ static int loop_control_remove(int idx)
 {
        struct loop_device *lo;
        int ret;
+
+       if (idx < 0) {
+               pr_warn("deleting an unspecified loop device is not supported.\n");
+               return -EINVAL;
+       }
                
        ret = mutex_lock_killable(&loop_ctl_mutex);
        if (ret)