]> git.itanic.dy.fi Git - linux-stable/commit
blk-lib: fix blkdev_issue_secure_erase
authorMikulas Patocka <mpatocka@redhat.com>
Wed, 14 Sep 2022 20:55:51 +0000 (16:55 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 Sep 2022 12:14:05 +0000 (14:14 +0200)
commit46c716a31fcdfd94524bb4b99814428603e4d7bb
tree5e7ed7e5905b046bac69aec114c4278a99a0898e
parentc2c7f67fd12d82bb89a210f3442e392b5d781fda
blk-lib: fix blkdev_issue_secure_erase

commit c4fa368466cc1b60bb92f867741488930ddd6034 upstream.

There's a bug in blkdev_issue_secure_erase. The statement
"unsigned int len = min_t(sector_t, nr_sects, max_sectors);"
sets the variable "len" to the length in sectors, but the statement
"bio->bi_iter.bi_size = len" treats it as if it were in bytes.
The statements "sector += len << SECTOR_SHIFT" and "nr_sects -= len <<
SECTOR_SHIFT" are thinko.

This patch fixes it.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org # v5.19
Fixes: 44abff2c0b97 ("block: decouple REQ_OP_SECURE_ERASE from REQ_OP_DISCARD")
Link: https://lore.kernel.org/r/alpine.LRH.2.02.2209141549480.28100@file01.intranet.prod.int.rdu2.redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
block/blk-lib.c