From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::243; helo=mail-wr0-x243.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) (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 AF94C21332110 for ; Wed, 13 Jun 2018 06:17:21 -0700 (PDT) Received: by mail-wr0-x243.google.com with SMTP id h10-v6so2707512wrq.8 for ; Wed, 13 Jun 2018 06:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=IUItpZdzIskVB3p2eC9IQfXtBSkTqjAmMHK5+s4+yI8=; b=GB7T1V7Px+b1OmbVFZOObKxpZtG97hBZSv0wCqp9wt3FKXgTfGwUAkhPlUTu4UYb3k Ti4BZw8qEu3dwgkaqmFu27TqyKAD+KWLsfdgKPPYPZXdIsGISOkbgjXiGYxCFUy+Tj7x yYQV2zBb6pchhXYXH5pHyge15v0l+8mA4KniA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=IUItpZdzIskVB3p2eC9IQfXtBSkTqjAmMHK5+s4+yI8=; b=qh7xUrVDp+4uiMrcs9hbF/gVcMIrnmb718U8i0kalrfUOfKz4cxnEkxaX1HDPzHA/s dSFtzjNy4LS1oZYNRWkbTBh7Io6eYaALJgcNzPqZDFyQ4YpW0JWEw/MuWlS/a8ktYEhU u37tndDZ8X/586AhptCcIV4duL3GPdOiSCBlSvElXH/KP/aV6NvUomoYASDeorzWct7/ XOlz/TmiIuaRo5Z/XxG9nqj2V2hyAfLwVqBx+233SrKAdtCa/8OLi3us89Hp6bE/s+xs A4MZYUq06pul26OsVFZANtTC1b5b3KuVNMlgiYzxsTFJ8fZY1UwXy/7yfWzNFo2DikZC teoA== X-Gm-Message-State: APt69E2/rB+yN4Rak9M1gYxEnovtLPvv9HAFiUrGKkCQZrygMIzzV3cv bYE8XcotE7RaBl0Pc3gDQfTPNQ== X-Google-Smtp-Source: ADUXVKJOjbcABEIcNoHtCBDgnLBlPgw9LFlTvr0q16w+VnUGoY7BL8udNc18WbClWCB+zLq+Lqu/Qg== X-Received: by 2002:adf:b691:: with SMTP id j17-v6mr4334187wre.10.1528895840039; Wed, 13 Jun 2018 06:17:20 -0700 (PDT) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id u7-v6sm2184756wrp.44.2018.06.13.06.17.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Jun 2018 06:17:16 -0700 (PDT) Date: Wed, 13 Jun 2018 14:17:13 +0100 From: Leif Lindholm To: Ard Biesheuvel Cc: "edk2-devel@lists.01.org" Message-ID: <20180613131713.qiy7f7hgtrobvlsd@bivouac.eciton.net> References: <20180607150818.14393-1-ard.biesheuvel@linaro.org> <20180607150818.14393-2-ard.biesheuvel@linaro.org> <20180612230325.vkcjj4iuvpq2vbuk@bivouac.eciton.net> MIME-Version: 1.0 In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [PATCH edk2-platforms 1/2] Silicon/SynQuacerPlatformFlashAccessLib: relax FV address check X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jun 2018 13:17:22 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Jun 13, 2018 at 02:06:00PM +0200, Ard Biesheuvel wrote: > On 13 June 2018 at 01:03, Leif Lindholm wrote: > > On Thu, Jun 07, 2018 at 05:08:17PM +0200, Ard Biesheuvel wrote: > >> In commit 913fdda9f4b9 ("Silicon/SynQuacerPlatformFlashAccessLib: don't > >> dereference FVB header fields"), we dropped all accesses to FVB header > >> field, which was necessary because the flash partition may not in fact > >> contain such a header. Instead, only an exact match on the base address > >> of the FV compared to the base address of the capsule payload would > >> result in a match, making it difficult to create capsules that only > >> update a subset of the flash contents. > >> > >> Given that the FVB protocol provides a GetBlockSize() method that also > >> returns the number of consecutive blocks of that size, and does not rely > >> on the FVB header contents, we can actually infer the size of the flash > >> partition, and use it to decide whether a capsule payload targets an > >> area that is covered by this partition entirely. > >> > >> This optimization allows us to extend the FV description to include the > >> SCP firmware partition without requiring us to actually provide a > >> payload for that partition immediately, which is useful as a preparatory > >> step. > >> > >> Contributed-under: TianoCore Contribution Agreement 1.1 > >> Signed-off-by: Ard Biesheuvel > >> --- > >> Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c | 53 +++++++++----------- > >> 1 file changed, 25 insertions(+), 28 deletions(-) > >> > >> diff --git a/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c b/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c > >> index ebb6ce189aa5..a6843c949a28 100644 > >> --- a/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c > >> +++ b/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c > >> @@ -44,8 +44,10 @@ STATIC > >> EFI_STATUS > >> GetFvbByAddress ( > >> IN EFI_PHYSICAL_ADDRESS Address, > >> + IN UINTN Length, > >> OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **OutFvb, > >> - OUT EFI_PHYSICAL_ADDRESS *FvbBaseAddress > >> + OUT EFI_LBA *Lba, > >> + OUT UINTN *BlockSize > >> ) > >> { > >> EFI_STATUS Status; > >> @@ -54,6 +56,8 @@ GetFvbByAddress ( > >> UINTN Index; > >> EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb; > >> EFI_FVB_ATTRIBUTES_2 Attributes; > >> + EFI_PHYSICAL_ADDRESS FvbBaseAddress; > >> + UINTN NumberOfBlocks; > >> > >> // > >> // Locate all handles with Firmware Volume Block protocol > >> @@ -84,7 +88,7 @@ GetFvbByAddress ( > >> // > >> // Checks if the address range of this handle contains parameter Address > >> // > >> - Status = Fvb->GetPhysicalAddress (Fvb, FvbBaseAddress); > >> + Status = Fvb->GetPhysicalAddress (Fvb, &FvbBaseAddress); > >> if (EFI_ERROR (Status)) { > >> continue; > >> } > >> @@ -102,8 +106,25 @@ GetFvbByAddress ( > >> continue; > >> } > >> > >> - if (Address == *FvbBaseAddress) { > >> + Status = Fvb->GetBlockSize (Fvb, 0, BlockSize, &NumberOfBlocks); > >> + if (EFI_ERROR (Status)) { > >> + DEBUG ((DEBUG_INFO, "%a: failed to get FVB blocksize - %r, ignoring\n", > >> + __FUNCTION__, Status)); > >> + continue; > >> + } > >> + > >> + if ((Length % *BlockSize) != 0) { > >> + DEBUG ((DEBUG_INFO, > >> + "%a: Length 0x%lx is not a multiple of the blocksize 0x%lx, ignoring\n", > >> + __FUNCTION__, Length, *BlockSize)); > >> + Status = EFI_INVALID_PARAMETER; > >> + continue; > >> + } > >> + > >> + if (Address >= FvbBaseAddress && > >> + (Address + Length) <= (FvbBaseAddress + *BlockSize * NumberOfBlocks)) { > > > > As I've already been giving Marcin a hard time about this today, could you add > > parentheses around "Address >= FvbBaseAddress" and "*BlockSize * NumberOfBlocks"? > > > > Sure. But to be consistent, shouldn't I also add parens around the > entire term after the && then? Strictly speaking, yes. The line break helps to demonstrate the separateness. > I.e., > > + if ((Address >= FvbBaseAddress) && > + ((Address + Length) <= (FvbBaseAddress + (*BlockSize * > NumberOfBlocks)))) { > > I'm not sure why we like redundant parentheses so much in Tianocore, > but I don't particularly mind either. Personally, it's because I neither have nor want the evaluation order of C expressions hard-wired into my visual cortex. I usually give * and / vs + and - the slip because I've failed to keep those out. / Leif > >> *OutFvb = Fvb; > >> + *Lba = (Address - FvbBaseAddress) / *BlockSize; > >> Status = EFI_SUCCESS; > >> break; > >> } > >> @@ -190,9 +211,7 @@ PerformFlashWriteWithProgress ( > >> EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb; > >> EFI_STATUS Status; > >> UINTN BlockSize; > >> - UINTN NumberOfBlocks; > >> EFI_LBA Lba; > >> - EFI_PHYSICAL_ADDRESS FvbBaseAddress; > >> UINTN NumBytes; > >> UINTN Remaining; > >> > >> @@ -216,7 +235,7 @@ PerformFlashWriteWithProgress ( > >> // that covers the system firmware > >> // > >> Fvb = NULL; > >> - Status = GetFvbByAddress (FlashAddress, &Fvb, &FvbBaseAddress); > >> + Status = GetFvbByAddress (FlashAddress, Length, &Fvb, &Lba, &BlockSize); > >> if (EFI_ERROR (Status)) { > >> DEBUG ((DEBUG_ERROR, > >> "%a: failed to locate FVB handle for address 0x%llx - %r\n", > >> @@ -224,28 +243,6 @@ PerformFlashWriteWithProgress ( > >> return Status; > >> } > >> > >> - Status = Fvb->GetBlockSize(Fvb, 0, &BlockSize, &NumberOfBlocks); > >> - if (EFI_ERROR (Status)) { > >> - DEBUG ((DEBUG_ERROR, "%a: failed to get FVB blocksize - %r\n", > >> - __FUNCTION__, Status)); > >> - return Status; > >> - } > >> - > >> - if ((Length % BlockSize) != 0) { > >> - DEBUG ((DEBUG_ERROR, > >> - "%a: Length 0x%lx is not a multiple of the blocksize 0x%lx\n", > >> - __FUNCTION__, Length, BlockSize)); > >> - return EFI_INVALID_PARAMETER; > >> - } > >> - > >> - Lba = (FlashAddress - FvbBaseAddress) / BlockSize; > >> - if (Lba > NumberOfBlocks - 1) { > >> - DEBUG ((DEBUG_ERROR, > >> - "%a: flash device with non-uniform blocksize not supported\n", > >> - __FUNCTION__)); > >> - return EFI_UNSUPPORTED; > >> - } > >> - > >> // > >> // Remap the region as device rather than uncached. > >> // > >> -- > >> 2.17.0 > >>