From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::d44; helo=mail-io1-xd44.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) (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 4C50221122E49 for ; Fri, 7 Sep 2018 03:36:33 -0700 (PDT) Received: by mail-io1-xd44.google.com with SMTP id y10-v6so1161005ioa.10 for ; Fri, 07 Sep 2018 03:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=K1i7sFZT1hy+g/xdihlJme++ZduMvvZ3KnBmhgurO3Y=; b=Z4NP0zPwxJA6GFNu6m39yECxgvAOdjemdNtjh/o1fbLFpB3tqNSLDrK6tmXGygXs+Q mVbed/t/00kMJEwDmF58MZ7+FN5oXfvfxrnBrdETR79hzHFFDUnk6BfSXfcb95D+AlXo v0EC/BZrkklXpnsrKGmvwl8kYDeeF17DhXgdE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=K1i7sFZT1hy+g/xdihlJme++ZduMvvZ3KnBmhgurO3Y=; b=niy+bSbfpCR/oOKRjLavfP+2g3dnavlCUr6DOHmwVlDuZfxuTSwFLJT1P92BJvzN6t EwGJQt5WdHDuZn5QB8vQ4htQ29xb8EooN0kcFiBMLHRHhlpowJHvET4MamsGjSWsh/sq Bt3NDKZIvChyCOY1UADuHOAlO81Y4iLFrQ5oES904yazwXlVUktbKjMFpdb0iz9fdn11 WqgVHH1TIrMpchIcnFDyjF5zH1mj7KAp8fFzubL16KzFCkcUmEYIWJD3ETmUNrePw2Us 0AJcqG3R/ey/wm+LXtXgr+G77fzW5w9IwN41imXDUaK7SflXoUZUZlDQJphu2lbfv14z QDUA== X-Gm-Message-State: APzg51Bn/ghtxuN+bHKGO2fXbet2O/FYynRVg1sPIwtc4KxPH//8Rkzu r2UtMNZB8u4R8hZ6elH+BNlF4a93+0MxRyzZ/DgMNQ== X-Google-Smtp-Source: ANB0Vdb2P9Lmp3nqmix31nwX14jup6UGCLEfaJ0J4C8CBG5sF0B3dcKC+bCcvyp4xBtq9n1acEwiVNM2sGJj2mdV57k= X-Received: by 2002:a6b:4516:: with SMTP id s22-v6mr5836796ioa.60.1536316593114; Fri, 07 Sep 2018 03:36:33 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:1c06:0:0:0:0:0 with HTTP; Fri, 7 Sep 2018 03:36:32 -0700 (PDT) In-Reply-To: References: From: Ard Biesheuvel Date: Fri, 7 Sep 2018 12:36:32 +0200 Message-ID: To: Vladimir Olovyannikov , "Zeng, Star" Cc: "edk2-devel@lists.01.org" , Leif Lindholm , Ruiyu Ni Subject: Re: [PATCH 3/3] MdeModulePkg/NonDiscoverablePciDeviceDxe: add missing validation X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Sep 2018 10:36:34 -0000 Content-Type: text/plain; charset="UTF-8" On 6 September 2018 at 20:55, Vladimir Olovyannikov wrote: > UEFI SCT crashed and failed in NonDiscoverablePciDeviceDxe becase > required checks were not performed. Perform parameters validation in > NonDiscoverablePciDeviceDxe. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Vladimir Olovyannikov Reviewed-by: Ard Biesheuvel > --- > .../NonDiscoverablePciDeviceIo.c | 50 ++++++++++++++++++- > 1 file changed, 49 insertions(+), 1 deletion(-) > > diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c > index 0e42ae4bf6ec..07118d59fd68 100644 > --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c > +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c > @@ -52,6 +52,10 @@ GetBarResource ( > > BarIndex -= (UINT8)Dev->BarOffset; > > + if (BarIndex >= Dev->BarCount) { > + return EFI_UNSUPPORTED; > + } > + > for (Desc = Dev->Device->Resources; > Desc->Desc != ACPI_END_TAG_DESCRIPTOR; > Desc = (VOID *)((UINT8 *)Desc + Desc->Len + 3)) { > @@ -597,6 +601,19 @@ CoherentPciIoMap ( > EFI_STATUS Status; > NON_DISCOVERABLE_PCI_DEVICE_MAP_INFO *MapInfo; > > + if (Operation != EfiPciIoOperationBusMasterRead && > + Operation != EfiPciIoOperationBusMasterWrite && > + Operation != EfiPciIoOperationBusMasterCommonBuffer) { > + return EFI_INVALID_PARAMETER; > + } > + > + if (HostAddress == NULL || > + NumberOfBytes == NULL || > + DeviceAddress == NULL || > + Mapping == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > // > // If HostAddress exceeds 4 GB, and this device does not support 64-bit DMA > // addressing, we need to allocate a bounce buffer and copy over the data. > @@ -720,6 +737,11 @@ CoherentPciIoAllocateBuffer ( > return EFI_UNSUPPORTED; > } > > + if ((MemoryType != EfiBootServicesData) && > + (MemoryType != EfiRuntimeServicesData)) { > + return EFI_INVALID_PARAMETER; > + } > + > // > // Allocate below 4 GB if the dual address cycle attribute has not > // been set. If the system has no memory available below 4 GB, there > @@ -877,6 +899,10 @@ NonCoherentPciIoAllocateBuffer ( > NON_DISCOVERABLE_DEVICE_UNCACHED_ALLOCATION *Alloc; > VOID *AllocAddress; > > + if (HostAddress == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); > > Status = CoherentPciIoAllocateBuffer (This, Type, MemoryType, Pages, > @@ -995,6 +1021,19 @@ NonCoherentPciIoMap ( > EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor; > BOOLEAN Bounce; > > + if (HostAddress == NULL || > + NumberOfBytes == NULL || > + DeviceAddress == NULL || > + Mapping == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + if (Operation != EfiPciIoOperationBusMasterRead && > + Operation != EfiPciIoOperationBusMasterWrite && > + Operation != EfiPciIoOperationBusMasterCommonBuffer) { > + return EFI_INVALID_PARAMETER; > + } > + > MapInfo = AllocatePool (sizeof *MapInfo); > if (MapInfo == NULL) { > return EFI_OUT_OF_RESOURCES; > @@ -1228,8 +1267,17 @@ PciIoAttributes ( > NON_DISCOVERABLE_PCI_DEVICE *Dev; > BOOLEAN Enable; > > + #define DEV_SUPPORTED_ATTRIBUTES \ > + (EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) > + > Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); > > + if (Attributes) { > + if ((Attributes & (~(DEV_SUPPORTED_ATTRIBUTES))) != 0) { > + return EFI_UNSUPPORTED; > + } > + } > + > Enable = FALSE; > switch (Operation) { > case EfiPciIoAttributeOperationGet: > @@ -1243,7 +1291,7 @@ PciIoAttributes ( > if (Result == NULL) { > return EFI_INVALID_PARAMETER; > } > - *Result = EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE; > + *Result = DEV_SUPPORTED_ATTRIBUTES; > break; > > case EfiPciIoAttributeOperationEnable: > -- > 2.18.0 >