From patchwork Fri Jul 27 15:02:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 173716 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D8A932C008C for ; Sat, 28 Jul 2012 01:59:56 +1000 (EST) Received: from localhost ([::1]:60523 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SumxH-0005y3-3G for incoming@patchwork.ozlabs.org; Fri, 27 Jul 2012 11:59:55 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=Wr9e51fIDG/GbutMzeH78fNw+2i3zsncGT8WQp9wing=; b=WNH1J6no8huN6C0hVJBslG7ZTZYj+WiLaGHKE5ijh/Uu4DuuPfGC7MjCUGMk7R4imV +Ve5Rg4dwxegDWDj09Jw9fW68EacMjSJZp7xu9kh2d/F1X1OkKqy8sC656kJb58cvYeR Io8HEbNJgUQpN+5GRcXYoPKiq+1WpFkV/rRnpRoo+H/G1HJD+BE9y1ldCkeIVs9Ru9U7 gaVMM5sna6rY/Y7iLkrXXpYPpK6ft3o6Y2vmBXg9Fn0mtt7nU/EjT1b92wqGefPONtBL qDz5Qroic7zTVD9A62TMStbgA+md4rXz35DogakACMjVjBmWSn0FjE7ViUc+kWN9eBk4 2t9w== Received: by 10.68.216.72 with SMTP id oo8mr14596228pbc.82.1343401446982; Fri, 27 Jul 2012 08:04:06 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-189-113.ip51.fastwebnet.it. [93.34.189.113]) by mx.google.com with ESMTPS id nk3sm2062530pbc.27.2012.07.27.08.04.04 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 Jul 2012 08:04:06 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 27 Jul 2012 17:02:46 +0200 Message-Id: <1343401379-19495-20-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1343401379-19495-1-git-send-email-pbonzini@redhat.com> References: <1343401379-19495-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: Ronnie Sahlberg Subject: [Qemu-devel] [PATCH 19/32] scsi-disk: improve the lba-out-of-range tests for read/write/verify X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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);