From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:57064) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SpDSr-0000hg-7c for qemu-devel@nongnu.org; Thu, 12 Jul 2012 03:05:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SpDSl-0007Y6-DS for qemu-devel@nongnu.org; Thu, 12 Jul 2012 03:05:29 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:46795) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SpDSk-0007WW-Sf for qemu-devel@nongnu.org; Thu, 12 Jul 2012 03:05:23 -0400 Received: by mail-pb0-f45.google.com with SMTP id ro12so3458673pbb.4 for ; Thu, 12 Jul 2012 00:05:22 -0700 (PDT) From: Ronnie Sahlberg Date: Thu, 12 Jul 2012 17:05:12 +1000 Message-Id: <1342076712-27013-2-git-send-email-ronniesahlberg@gmail.com> In-Reply-To: <1342076712-27013-1-git-send-email-ronniesahlberg@gmail.com> References: <1342076712-27013-1-git-send-email-ronniesahlberg@gmail.com> Subject: [Qemu-devel] [PATCH] SCSI Improved checking for LBA out of range List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: pbonzini@redhat.com, qemu-devel@nongnu.org Cc: Ronnie Sahlberg Improve the tests for the LBA to cover more cases, the new test looks like this if (r->req.cmd.lba > r->req.cmd.lba + len || r->req.cmd.lba + len > s->qdev.max_lba + 1) { For the 16 byte opcodes, the lba is a uint64, so the first check is to make sure that we do not wrap. For example if an opcode would specify the LBA:0xffffffffffffffff and LEN:2 then lba+len would wrap to 1. The second part of the test is to verify that ALL requested blocks are available, not just the first one. Signed-off-by: Ronnie Sahlberg --- hw/scsi-disk.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index b2f3c0c..2c2be33 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1558,7 +1558,8 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf) if (r->req.cmd.buf[1] & 0xe0) { goto fail; } - if (r->req.cmd.lba > s->qdev.max_lba) { + if (r->req.cmd.lba > r->req.cmd.lba + len + || r->req.cmd.lba + len > s->qdev.max_lba + 1) { goto illegal_lba; } r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512); @@ -1581,7 +1582,8 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf) if (r->req.cmd.buf[1] & 0xe0) { goto fail; } - if (r->req.cmd.lba > s->qdev.max_lba) { + if (r->req.cmd.lba > r->req.cmd.lba + len + || r->req.cmd.lba + len > s->qdev.max_lba + 1) { goto illegal_lba; } r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512); -- 1.7.3.1