zram: avoid access beyond the zram device
Function valid_io_request() should verify the entire request are within the zram device address range. Otherwise it may cause invalid memory access when accessing/modifying zram->meta->table[index] because the 'index' is out of range. Then it may access non-exist memory, randomly modify memory belong to other subsystems, which is hard to track down. Signed-off-by: Jiang Liu <jiang.liu@huawei.com> Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
65c484609a
commit
12a7ad3b81
@ -420,13 +420,20 @@ out:
|
|||||||
*/
|
*/
|
||||||
static inline int valid_io_request(struct zram *zram, struct bio *bio)
|
static inline int valid_io_request(struct zram *zram, struct bio *bio)
|
||||||
{
|
{
|
||||||
if (unlikely(
|
u64 start, end, bound;
|
||||||
(bio->bi_sector >= (zram->disksize >> SECTOR_SHIFT)) ||
|
|
||||||
(bio->bi_sector & (ZRAM_SECTOR_PER_LOGICAL_BLOCK - 1)) ||
|
/* unaligned request */
|
||||||
(bio->bi_size & (ZRAM_LOGICAL_BLOCK_SIZE - 1)))) {
|
if (unlikely(bio->bi_sector & (ZRAM_SECTOR_PER_LOGICAL_BLOCK - 1)))
|
||||||
|
return 0;
|
||||||
|
if (unlikely(bio->bi_size & (ZRAM_LOGICAL_BLOCK_SIZE - 1)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
start = bio->bi_sector;
|
||||||
|
end = start + (bio->bi_size >> SECTOR_SHIFT);
|
||||||
|
bound = zram->disksize >> SECTOR_SHIFT;
|
||||||
|
/* out of range range */
|
||||||
|
if (unlikely(start >= bound || end >= bound || start > end))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
/* I/O request is valid */
|
/* I/O request is valid */
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user