From patchwork Mon May 23 15:09:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9132067 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4C929607D5 for ; Mon, 23 May 2016 15:36:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42E3228219 for ; Mon, 23 May 2016 15:36:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37DD328237; Mon, 23 May 2016 15:36:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6F4F428219 for ; Mon, 23 May 2016 15:36:14 +0000 (UTC) Received: from localhost ([::1]:48939 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4rtt-0008OZ-He for patchwork-qemu-devel@patchwork.kernel.org; Mon, 23 May 2016 11:36:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4rUx-0002MO-4C for qemu-devel@nongnu.org; Mon, 23 May 2016 11:10:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b4rUs-00048O-4S for qemu-devel@nongnu.org; Mon, 23 May 2016 11:10:26 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33992) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4rUr-00048D-To; Mon, 23 May 2016 11:10:22 -0400 Received: by mail-wm0-x242.google.com with SMTP id n129so16053183wmn.1; Mon, 23 May 2016 08:10:21 -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:in-reply-to:references; bh=jNEUeyv7U1VBZB93i7EGMFshRJNRX56qqb1sCcUHHGc=; b=oBD1N66K7BLnYfbRFkHajKlyv0uoYu3wDaIkuC5gpuazALWpJ8zNPEN9kNMJaJGNX7 NxuWLelXXtc4/sz6bXnTMyRhpy9sT9sTE23Xm0drnPzxcgYJ6MLgBkHflwhVUZqC4mdK i3EUmIpa0dA/xHr7Jlz0hSa+WP+GPivn5xp1nLP2r6s3uGzE8A4ATHYjxBVJY3gu0cDE xMyIW8v6P93qYmz+MQSlafMPqmCG3B7AB2M/k4h97mlrmI9BhuTAmKyPryhQ5Yyt/X5M h0Lx/psN6yPUmb+oGGELlZI4zCwQGa8qe3b7cufVTbT6KUG/f1aBfGvqTRPwcizxO5cd WTgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=jNEUeyv7U1VBZB93i7EGMFshRJNRX56qqb1sCcUHHGc=; b=g0wQjkUAsJSfuwJenaENOE+R/ZyFMBeOYWvPTLF26zX5imMwh+6sh+Z/ZAMobTpWma 8WbJJxqvvsvKo0dIfplLAZ+Zki5D5o+iEMFXOfuIpAVdbvNQAc7I947T8Q6ozd6pIo3/ uvgzOuUV19wWL1KwdCwuPh/TeBDlBPFhLKf69EPaWPO/2L4d4jqz6XzVQtXopLTOmykZ BV1Art/RhVG0A9Gf/VWZPobLziGFrjQAYvMd5Pp1QyfMrDYtPzPpVylDxBA8GnTrpxlr rEXY5eY9jiAji64A75MxKwfY+Q4wiVq2ANtkvU+9vntLifaCb/346iDBqoLM8VvP+qJl hQVA== X-Gm-Message-State: ALyK8tId2O5OufbOCWIFI6GSXAjh0Hy342uJnB8HVbwkSbg9i4MwFue1czfw1PZAymWKvg== X-Received: by 10.28.111.215 with SMTP id c84mr11734950wmi.95.1464016221369; Mon, 23 May 2016 08:10:21 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-252-58.clienti.tiscali.it. [78.12.252.58]) by smtp.gmail.com with ESMTPSA id ac2sm19250359wjc.35.2016.05.23.08.10.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 May 2016 08:10:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 23 May 2016 17:09:54 +0200 Message-Id: <1464016199-43768-20-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1464016199-43768-1-git-send-email-pbonzini@redhat.com> References: <1464016199-43768-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PULL 19/24] esp: check dma length before reading scsi command(CVE-2016-4441) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Prasad J Pandit , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Prasad J Pandit The 53C9X Fast SCSI Controller(FSC) comes with an internal 16-byte FIFO buffer. It is used to handle command and data transfer. Routine get_cmd() uses DMA to read scsi commands into this buffer. Add check to validate DMA length against buffer size to avoid any overrun. Fixes CVE-2016-4441. Reported-by: Li Qiang Cc: qemu-stable@nongnu.org Signed-off-by: Prasad J Pandit Message-Id: <1463654371-11169-3-git-send-email-ppandit@redhat.com> Signed-off-by: Paolo Bonzini --- hw/scsi/esp.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 01497e6..591c817 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -82,7 +82,7 @@ void esp_request_cancelled(SCSIRequest *req) } } -static uint32_t get_cmd(ESPState *s, uint8_t *buf) +static uint32_t get_cmd(ESPState *s, uint8_t *buf, uint8_t buflen) { uint32_t dmalen; int target; @@ -92,6 +92,9 @@ static uint32_t get_cmd(ESPState *s, uint8_t *buf) dmalen = s->rregs[ESP_TCLO]; dmalen |= s->rregs[ESP_TCMID] << 8; dmalen |= s->rregs[ESP_TCHI] << 16; + if (dmalen > buflen) { + return 0; + } s->dma_memory_read(s->dma_opaque, buf, dmalen); } else { dmalen = s->ti_size; @@ -166,7 +169,7 @@ static void handle_satn(ESPState *s) s->dma_cb = handle_satn; return; } - len = get_cmd(s, buf); + len = get_cmd(s, buf, sizeof(buf)); if (len) do_cmd(s, buf); } @@ -180,7 +183,7 @@ static void handle_s_without_atn(ESPState *s) s->dma_cb = handle_s_without_atn; return; } - len = get_cmd(s, buf); + len = get_cmd(s, buf, sizeof(buf)); if (len) { do_busid_cmd(s, buf, 0); } @@ -192,7 +195,7 @@ static void handle_satn_stop(ESPState *s) s->dma_cb = handle_satn_stop; return; } - s->cmdlen = get_cmd(s, s->cmdbuf); + s->cmdlen = get_cmd(s, s->cmdbuf, sizeof(s->cmdbuf)); if (s->cmdlen) { trace_esp_handle_satn_stop(s->cmdlen); s->do_cmd = 1;