From patchwork Wed Jul 1 18:01:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1321125 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=k+Ub+Nh3; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yBC16Vmsz9sR4 for ; Thu, 2 Jul 2020 18:31:25 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B05C582170; Thu, 2 Jul 2020 10:21:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="k+Ub+Nh3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1A80D81A2A; Wed, 1 Jul 2020 20:02:11 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8AF078044A for ; Wed, 1 Jul 2020 20:02:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1593626526; bh=ti7mAJ0J1lGqOlqcV2QKUAt/mtwHVkJsgxTGXHUfSKI=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=k+Ub+Nh3ovgeLbYPTkl+rtkzAcCWuZVxN4sLUgpgUYiU4Z7SJi5lpLKwiR9yBaFhH dV+XsY9xXyIhoiTt/3U+v8CupASMynbS/7HnuStsv+Blfix9Um9oJ1MIBkzJojN9eD kUFo1cFMSE/Ubt/hgDWKc2UuFvCeVWZsPLbY9S38= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from workstation4.fritz.box ([88.152.145.75]) by mail.gmx.com (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MA7KU-1jgGff3wxG-00BY6Q; Wed, 01 Jul 2020 20:02:06 +0200 From: Heinrich Schuchardt To: AKASHI Takahiro Cc: Alexander Graf , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 1/2] efi_loader: fix efi_image_region_add() Date: Wed, 1 Jul 2020 20:01:52 +0200 Message-Id: <20200701180153.165337-2-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701180153.165337-1-xypron.glpk@gmx.de> References: <20200701180153.165337-1-xypron.glpk@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e9A2JqWZWWtMNrnlohWS6Msw8jnyPQQRzOtJ4Zm V3BHeF/6kJezq0ziuhtncZ8ztUhNeW659AKe0zAXk2KYoKd4aTdEYtBqkWu5aFvLkWdV0pzNk bCz9R1qQ1G4Kq8dOTputRJo86wjK8GXmhXVsB3SBt6Zus84xhKPg3oHbRT3r4YIKEAYCBeAgc OAVxGqLtasX9A5RzJMLrvgq5LO1kC1Uix8tzprhByPHP5vm2iurBRjac8bMqyUWEMV9eBXVQP EQQQa7EebJ+kk408KGmTTP9DXW8KRXGFCbhqPsHb9Z+421PxvmxAPTnSpYMwXUMCB1EDbXDiU xanavTr1XHo56KF/81Sf4U6U50xr6coJ3L0Pn/Aj3vVww4QsHpg9SXTC6h7s3JlueZcU+UhY5 cbxs+MuuiSrWfbQdYvqP6GIshcXcX3yTbqrTHyfyaYF0/9Fw+pR51EHLpV9Ur9szTJhtw= X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Use start and end address consistently as half-open interval. Simplify the code. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_signature.c | 35 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) -- 2.27.0 diff --git a/lib/efi_loader/efi_signature.c b/lib/efi_loader/efi_signature.c index 6685253856..f63a18cb8f 100644 --- a/lib/efi_loader/efi_signature.c +++ b/lib/efi_loader/efi_signature.c @@ -519,15 +519,19 @@ out: } /** - * efi_image_region_add - add an entry of region + * efi_image_region_add() - add an entry of region * @regs: Pointer to array of regions - * @start: Start address of region - * @end: End address of region + * @start: Start address of region (included) + * @end: End address of region (excluded) * @nocheck: flag against overlapped regions * - * Take one entry of region [@start, @end] and append it to the list - * pointed to by @regs. If @nocheck is false, overlapping among entries - * will be checked first. + * Take one entry of region [@start, @end[ and insert it into the list. + * + * * If @nocheck is false, the list will be sorted ascending by address. + * Overlapping entries will not be allowed. + * + * * If @nocheck is true, the list will be sorted ascending by sequence + * of adding the entries. Overlapping is allowed. * * Return: status code */ @@ -551,22 +555,21 @@ efi_status_t efi_image_region_add(struct efi_image_regions *regs, if (nocheck) continue; - if (start > reg->data + reg->size) + /* new data after registered region */ + if (start >= reg->data + reg->size) continue; - if ((start >= reg->data && start < reg->data + reg->size) || - (end > reg->data && end < reg->data + reg->size)) { - debug("%s: new region already part of another\n", - __func__); - return EFI_INVALID_PARAMETER; - } - - if (start < reg->data && end < reg->data + reg->size) { + /* new data preceding registered region */ + if (end <= reg->data) { for (j = regs->num - 1; j >= i; j--) - memcpy(®s->reg[j], ®s->reg[j + 1], + memcpy(®s->reg[j + 1], ®s->reg[j], sizeof(*reg)); break; } + + /* new data overlapping registered region */ + debug("%s: new region already part of another\n", __func__); + return EFI_INVALID_PARAMETER; } reg = ®s->reg[i];