From patchwork Mon May 23 15:09:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9132007 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 7F09860761 for ; Mon, 23 May 2016 15:16:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75DD52822B for ; Mon, 23 May 2016 15:16:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6AB3728239; Mon, 23 May 2016 15:16:11 +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 C8B0A2822B for ; Mon, 23 May 2016 15:16:09 +0000 (UTC) Received: from localhost ([::1]:48825 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4raT-00077x-0O for patchwork-qemu-devel@patchwork.kernel.org; Mon, 23 May 2016 11:16:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37669) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4rUu-0002Im-Ms for qemu-devel@nongnu.org; Mon, 23 May 2016 11:10:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b4rUr-000485-Ct for qemu-devel@nongnu.org; Mon, 23 May 2016 11:10:24 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:36112) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4rUq-00047o-Uf; Mon, 23 May 2016 11:10:21 -0400 Received: by mail-wm0-x244.google.com with SMTP id q62so16005906wmg.3; Mon, 23 May 2016 08:10:20 -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=tLgn2ej8BSt+fXSs2qgysnWbcMqG2F+8LUq/8/mB+L4=; b=X+YNptzo6Xakia9XBJvhwav4OZ9nZqG3duslL0ajWn3XHvW1ABj8jK5Gz0dYPLwoAW KXNKzEiMpHaAe5mFcMa9lAyenkSBRkhsz96edquwVwDuiq22CbyoVQyjinqgvVW6ksuN P+r6we/d7MMZusCcpXlMNXqAsjlR8Hoc/gFki4EtpnQRS9lPeHUBnV8nS5ZIXatJw6KD r7SCEdAR66W1WNDm8+fv46m0Z8RUtv30VXkgCZxGTcvJyqGgOdSx7MM2n9Qa6LT4KFTX tginIhCWovKyl10n4JDQE4dq40y02eP7xwK2ca6IZHRS96ZMDA1MIwSBgXxhC24uIzPb tWvA== 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=tLgn2ej8BSt+fXSs2qgysnWbcMqG2F+8LUq/8/mB+L4=; b=jGrjRA6J+8b9ga0yMmcG9KkRKuuTp4CS2htnne0p0E9UOOU0ylQx7AsPgF+tQiiSW6 VvbHcJdeQZRcGhw6ObJf9BjGnxDrddKdO8Jyj/IbVfiJXJlgNCLNw5SIXdFcxmPi4TWD ERrypmbU5tD0vg1jMR5qOsA9GCBom7sFp46v1ByRkB6bMKTwxbjgEZONcy8IlHEGGyKm EvEX2VdgSaub+kC79aD1i9pVigBOgISOXfKYhKh8bhpMLIQ+HvHaMqN5eaxbmSXNX1J/ 1ndrFSrnjov1AmGhrIUmkt8o4If8a0gbr4rCJYuLQAyMxe6hHwdNiwOM6a3/T96K7l9A iOiQ== X-Gm-Message-State: AOPr4FXx7LAVaBfv7d0VDkMDBCipTi8BEJRE/FQFcD7f6iHfnAb4l4lj70jEH+g4Rtt6gA== X-Received: by 10.28.59.193 with SMTP id i184mr18451898wma.73.1464016220386; Mon, 23 May 2016 08:10:20 -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.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 May 2016 08:10:19 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 23 May 2016 17:09:53 +0200 Message-Id: <1464016199-43768-19-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::244 Subject: [Qemu-devel] [PULL 18/24] esp: check command buffer length before write(CVE-2016-4439) 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. While writing to this command buffer 's->cmdbuf[TI_BUFSZ=16]', a check was missing to validate input length. Add check to avoid OOB write access. Fixes CVE-2016-4439. Reported-by: Li Qiang Cc: qemu-stable@nongnu.org Signed-off-by: Prasad J Pandit Message-Id: <1463654371-11169-2-git-send-email-ppandit@redhat.com> Signed-off-by: Paolo Bonzini --- hw/scsi/esp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 8961be2..01497e6 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -448,7 +448,11 @@ void esp_reg_write(ESPState *s, uint32_t saddr, uint64_t val) break; case ESP_FIFO: if (s->do_cmd) { - s->cmdbuf[s->cmdlen++] = val & 0xff; + if (s->cmdlen < TI_BUFSZ) { + s->cmdbuf[s->cmdlen++] = val & 0xff; + } else { + trace_esp_error_fifo_overrun(); + } } else if (s->ti_size == TI_BUFSZ - 1) { trace_esp_error_fifo_overrun(); } else {