From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:51607) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sum5I-0007i5-W6 for qemu-devel@nongnu.org; Fri, 27 Jul 2012 11:04:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sum5H-0007SO-Hg for qemu-devel@nongnu.org; Fri, 27 Jul 2012 11:04:08 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:59010) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sum5H-0007FU-Ba for qemu-devel@nongnu.org; Fri, 27 Jul 2012 11:04:07 -0400 Received: by mail-pb0-f45.google.com with SMTP id ro12so4974590pbb.4 for ; Fri, 27 Jul 2012 08:04:07 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 27 Jul 2012 17:02:46 +0200 Message-Id: <1343401379-19495-20-git-send-email-pbonzini@redhat.com> In-Reply-To: <1343401379-19495-1-git-send-email-pbonzini@redhat.com> References: <1343401379-19495-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 19/32] scsi-disk: improve the lba-out-of-range tests for read/write/verify List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Ronnie Sahlberg From: Ronnie Sahlberg Improve the tests for the LBA to cover more cases. For the 16 byte opcodes, the lba is a uint64, so we need to 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. Also verify that ALL requested blocks are available, not just the first one. Signed-off-by: Ronnie Sahlberg Signed-off-by: Paolo Bonzini --- hw/scsi-disk.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 526da4b..3c03159 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1777,7 +1777,8 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf) if (r->req.cmd.buf[1] & 0xe0) { goto illegal_request; } - if (r->req.cmd.lba > s->qdev.max_lba) { + if (r->req.cmd.lba > r->req.cmd.lba + len || + r->req.cmd.lba + len - 1 > s->qdev.max_lba) { goto illegal_lba; } r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512); @@ -1800,7 +1801,8 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf) if (r->req.cmd.buf[1] & 0xe0) { goto illegal_request; } - if (r->req.cmd.lba > s->qdev.max_lba) { + if (r->req.cmd.lba > r->req.cmd.lba + len || + r->req.cmd.lba + len - 1 > s->qdev.max_lba) { goto illegal_lba; } r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512); -- 1.7.10.4