From patchwork Mon Oct 30 05:47:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary guo X-Patchwork-Id: 117439 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp2178564qgn; Sun, 29 Oct 2017 22:48:40 -0700 (PDT) X-Google-Smtp-Source: ABhQp+T9/vttiAjlf4LbgUnLOjCUKUlf4DSIXD7XoMXtQAq++PflkXXUw6qI66qqGdGYybAfxC9Z X-Received: by 10.84.216.9 with SMTP id m9mr6460125pli.16.1509342519998; Sun, 29 Oct 2017 22:48:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509342519; cv=none; d=google.com; s=arc-20160816; b=dOwzbvpC+9qOfEYuEiWIGr8C+luGWJ2n53OocMSiClGz2w7CWfhcNcmzTz+PNtGxdN kHQ+12QLWUJbXD/sLyBLO6U9F1Dlg41p7esN1XtOAYapGngnfZFzg6C9MVQSHmi2AmxA RG0Dzt0wazckVWuODu6XRIMzfR/CC8f6A80eJ38k/wWVuhitkL8/SX2uST98/6txLBDE 8F9oyxINa0kmrxCXOFQSlKg6dJ3FKDs5hiSy20sRgxqNZWdQrIFbX2vfBrHpCscwwoik 4MBmtEDzpIMJnL0ZE9J+ug5AARoZs2JQGpC3O2gIKbZpMG3c8LlYj/TazsQSkkRO7tZD vpXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=02XYb/8yHpwrVUL0n6CllRzulbPHOHbKVgIlXbziewI=; b=SKEexZf79KAJdwzKQA2GV1otziIQsQXnzYXXZEwZW4VM9Ee86gOwROmCEqkX90IxBv fdZFVkYgjYRWRszUIm2ha2HqxBq77KdxXJ3R3dGKXLXCDvEfziyP9j0A0nyyZOZBy6UH ETx3Iw7MVpcFVmUsDss5Z7YRGj72JY2rJagQMbFEom+nAyi+F8807k0uNGtuVME8yx4n HRgslMgqkXg4LFpplq3wl7+nLTu3fl7nhi9Mi72ZyiwIYipeX2LjaqvX5DFCMWB9infx 06dPMQZF8ndxF7ITWfljo2gJ2UVdhdVyMl6bYvM21v7skTvv41K9ZpPexmoRiXSWUV6n VS9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=QWIzU+xO; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id c6si5126041pgq.243.2017.10.29.22.48.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2017 22:48:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=QWIzU+xO; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 452182034CF98; Sun, 29 Oct 2017 22:44:48 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c00::244; helo=mail-pf0-x244.google.com; envelope-from=heyi.guo@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pf0-x244.google.com (mail-pf0-x244.google.com [IPv6:2607:f8b0:400e:c00::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id F04EE2034CF7F for ; Sun, 29 Oct 2017 22:44:46 -0700 (PDT) Received: by mail-pf0-x244.google.com with SMTP id a8so10150778pfc.0 for ; Sun, 29 Oct 2017 22:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=n6eIqCoLWuxCZ2ISCom4UDuDLJACm5Ba5TS6u3oyEhw=; b=QWIzU+xOGUrIhDlod30Gu3cyKpHEauwiu4+FwsEVs3YwV3Wlqk1DTEyHzPGeA8TCPZ d3xt5Hp/iP24iaw03A9Nrwk3IL4zZDpO0m2naHgsQw0tNSBYARDP3otDimJVlmH6f7G4 Iy5GDnaGJlkzQRYZ2gQBNsnRe2mLSTV+JjygQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=n6eIqCoLWuxCZ2ISCom4UDuDLJACm5Ba5TS6u3oyEhw=; b=AsoEHPy325Iq02PklGK6W34FVsNQlTKOD1i9UZNJBQykUjIq9P68biW0Nxml2Xzm61 5HPu1EE6SWwfjaEh2UXmp+oEfaOMTeXHX2wPqBqATVqRX+FqQK4fijJfQwIGB0iQ0hbW mV5gvW7ut+xvf01QSbPh6XpiYkY9cMmvAbh3tVvjPnPuNKKTIYRiI6HxmMP/Aj1EZCGk hNVo7/EpKAUUGXo3R80WTg+EbnYtGwB3ubjWsGBE2PgQexSU//I2PpunCe9nYaEgTqdB 39+WK1WYmMWvCb+QHs/uhVZhi2zN2r9bL10dEBgAsBw6q7z3DDw7WK9H7DaIdZdeMe5L yJzQ== X-Gm-Message-State: AMCzsaURYMZ0CChrSGd1486jVPwuK2pS8G+mfuXdVFibWMit7AoVsrZJ mOl03HgzrTR8S35OHOOOmFxXe6SlI9I= X-Received: by 10.101.82.1 with SMTP id o1mr6707840pgp.261.1509342516654; Sun, 29 Oct 2017 22:48:36 -0700 (PDT) Received: from szxbz956.huaweiobz.com ([89.47.15.73]) by smtp.gmail.com with ESMTPSA id u186sm22060545pgb.84.2017.10.29.22.48.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 29 Oct 2017 22:48:36 -0700 (PDT) From: Heyi Guo To: linaro-uefi@lists.linaro.org, edk2-devel@lists.01.org Date: Mon, 30 Oct 2017 13:47:52 +0800 Message-Id: <1509342472-1688-1-git-send-email-heyi.guo@linaro.org> X-Mailer: git-send-email 2.7.2.windows.1 Subject: [edk2] [PATCH] MdeModulePkg/NonDiscoverable: fix memory override bug X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Heyi Guo , Eric Dong , Star Zeng , Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" For PciIoPciRead interface, memory prior to Buffer would be written with zeros if Offset was larger than sizeof (Dev->ConfigSpace), which would cause serious system exception. So we add a pre-check branch to avoid memory override. Cc: Star Zeng Cc: Eric Dong Cc: Ard Biesheuvel Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Heyi Guo --- .../Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c | 5 +++++ 1 file changed, 5 insertions(+) -- 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Ard Biesheuvel Signed-off-by: Heyi Guo diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c index c836ad6..0e42ae4 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c @@ -465,6 +465,11 @@ PciIoPciRead ( Address = (UINT8 *)&Dev->ConfigSpace + Offset; Length = Count << ((UINTN)Width & 0x3); + if (Offset >= sizeof (Dev->ConfigSpace)) { + ZeroMem (Buffer, Length); + return EFI_SUCCESS; + } + if (Offset + Length > sizeof (Dev->ConfigSpace)) { // // Read all zeroes for config space accesses beyond the first