From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-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) 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 Cc: Heyi Guo , Star Zeng , Eric Dong , Ard Biesheuvel , Ruiyu Ni 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: [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: , X-List-Received-Date: Mon, 30 Oct 2017 05:44:47 -0000 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(+) 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 -- 1.9.1