This is a note to let you know that I've just added the patch titled zram: avoid access beyond the zram device to the 3.10-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: zram-avoid-access-beyond-the-zram-device.patch and it can be found in the queue-3.10 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 12a7ad3b810e77137d0caf97a6dd97591e075b30 Mon Sep 17 00:00:00 2001 From: Jiang Liu <liuj97@xxxxxxxxx> Date: Fri, 7 Jun 2013 00:07:26 +0800 Subject: zram: avoid access beyond the zram device From: Jiang Liu <liuj97@xxxxxxxxx> commit 12a7ad3b810e77137d0caf97a6dd97591e075b30 upstream. 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@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/staging/zram/zram_drv.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -420,13 +420,20 @@ out: */ static inline int valid_io_request(struct zram *zram, struct bio *bio) { - if (unlikely( - (bio->bi_sector >= (zram->disksize >> SECTOR_SHIFT)) || - (bio->bi_sector & (ZRAM_SECTOR_PER_LOGICAL_BLOCK - 1)) || - (bio->bi_size & (ZRAM_LOGICAL_BLOCK_SIZE - 1)))) { + u64 start, end, bound; + + /* unaligned request */ + 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; - } /* I/O request is valid */ return 1; Patches currently in stable-queue which might be from liuj97@xxxxxxxxx are queue-3.10/zram-avoid-access-beyond-the-zram-device.patch queue-3.10/zram-protect-sysfs-handler-from-invalid-memory-access.patch queue-3.10/zram-avoid-double-free-in-function-zram_bvec_write.patch queue-3.10/zram-use-zram-lock-to-protect-zram_free_page-in-swap-free-notify-path.patch queue-3.10/zram-avoid-invalid-memory-access-in-zram_exit.patch queue-3.10/zram-destroy-all-devices-on-error-recovery-path-in-zram_init.patch -- To unsubscribe from this list: send the line "unsubscribe stable" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html