From nobody Sun May 5 14:40:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1509342520205156.78254391095754; Sun, 29 Oct 2017 22:48:40 -0700 (PDT) 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) 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) 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) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.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 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-Google-Smtp-Source: ABhQp+Tn4PjmxUI5j+DUerdtpTFnNdHvLdPU/30zzQDAg0J06V7XTzWfJjXC+Gvj2UBp/+/vxWyjFw== X-Received: by 10.101.82.1 with SMTP id o1mr6707840pgp.261.1509342516654; 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 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Ard Biesheuvel --- .../Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c | 5 += ++++ 1 file changed, 5 insertions(+) diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverab= lePciDeviceIo.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDisco= verablePciDeviceIo.c index c836ad6..0e42ae4 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceIo.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceIo.c @@ -465,6 +465,11 @@ PciIoPciRead ( Address =3D (UINT8 *)&Dev->ConfigSpace + Offset; Length =3D Count << ((UINTN)Width & 0x3); =20 + if (Offset >=3D 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 --=20 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel