From f59f2ab6aba2623b7326bb0b87f2263741718e8c Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Sat, 28 Feb 2015 03:35:59 +0000 Subject: [PATCH] scst_disk: Avoid overflow for large max_hw_sectors values Avoid that max_sectors << block_shift overflows for large max_sectors values by changing the test ((max_sectors << block_shift) < PAGE_SIZE) into (max_sectors < (PAGE_SIZE >> block_shift)). Signed-off-by: Bart Van Assche git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6136 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_disk.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/scst/src/dev_handlers/scst_disk.c b/scst/src/dev_handlers/scst_disk.c index ad58fc438..cc2f27cba 100644 --- a/scst/src/dev_handlers/scst_disk.c +++ b/scst/src/dev_handlers/scst_disk.c @@ -381,7 +381,7 @@ static int disk_exec(struct scst_cmd *cmd) struct scatterlist *sg, *start_sg; int cur_sg_cnt; int sg_tablesize = cmd->dev->scsi_dev->host->sg_tablesize; - int max_sectors; + unsigned int max_sectors; int num, j, block_shift = dev->block_shift; TRACE_ENTRY(); @@ -392,15 +392,10 @@ static int disk_exec(struct scst_cmd *cmd) */ max_sectors = queue_max_hw_sectors(dev->scsi_dev->request_queue); - if (unlikely(((max_sectors << block_shift) & ~PAGE_MASK) != 0)) { - int mlen = max_sectors << block_shift; - int pg = ((mlen >> PAGE_SHIFT) + ((mlen & ~PAGE_MASK) != 0)) - 1; - int adj_len = pg << PAGE_SHIFT; - max_sectors = adj_len >> block_shift; - if (max_sectors == 0) { - PRINT_ERROR("Too low max sectors %d", max_sectors); - goto out_error; - } + if (unlikely(max_sectors < (PAGE_SIZE >> block_shift))) { + PRINT_ERROR("Too low max sectors: %u << %u < %lu", max_sectors, + block_shift, PAGE_SIZE); + goto out_error; } if (unlikely((cmd->bufflen >> block_shift) > max_sectors)) {