Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4670008imm; Tue, 11 Sep 2018 16:01:30 -0700 (PDT) X-Google-Smtp-Source: ANB0VdboN9LDd3GBliIIeprIyWFqsXLNikEUT/24RHhKQr6JvfmONT7ktrBunztWbilnwEl7MsaV X-Received: by 2002:a63:790b:: with SMTP id u11-v6mr30822551pgc.111.1536706890706; Tue, 11 Sep 2018 16:01:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536706890; cv=none; d=google.com; s=arc-20160816; b=vjDT2wilwlkWRBLytd1Z9C3sLV9VIuU4RqteF+zhWpziY/7TtfecrVJY2768kyfz0L bZSAkLRQXASUaPbpG2e7e5ug0uVN7VgGIizsZdb8USlvm8xNpTsALgRV5adQJX9POiEE AF1lX6m5AMi9xDA/bwcTa9J+W52hgsj0AN/kJ5SnSk3J4AclivsyzR3yaN6nlKNtCPeh cZ6TKOH7Y0lLvihqwFChmu7WKfPgYEI0Hy4AGhrp8v8PKj7TMb9RLvo+DYjg05DRu6x+ rI/DZtJtw+4A1b6Mj/PR9mols0eTHdsqMk0gXNxqdJuP6qV4MTAN2b5RpswRhZE8e1jt G8JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=I5ESdrhipRbibVthHVriYBdDUSjfzWMwFQGQJ70RB5Y=; b=DnPvslpLINspwXbxvmwAlIgmtGb7xCIU+vK5yhA5IerVk99Yu+7j+Gc2+LHzcyx7b8 ZbMK26WdHqJSdzZXcdV+4rcX0Dz28BxXxG8YciZ4/uOvESdpB7bVWz4MLq6Wwa01CcdC NXKqNlk0Exg3Fb3Gal22GUcQ3pnVetr+Wr76YD676RalmNnbQvCvm1tRR0ufn61a6RVF rMSmpxaN3Hpz833R4cUJXLDAIcru5PrL7Uasos0GaWtpDJ3Wy9sqP1F+vtYE13h4GIRE qElpbiYmbuYjmHRV+8eUZl0CwNtgRwaKgboeApZcVU5O6rx4DeT8ntddGkS+rpsSFl/e Uq/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="E/ievZ/B"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 64-v6si19856615plk.257.2018.09.11.16.01.14; Tue, 11 Sep 2018 16:01:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="E/ievZ/B"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725975AbeILEBT (ORCPT + 99 others); Wed, 12 Sep 2018 00:01:19 -0400 Received: from mail-it0-f43.google.com ([209.85.214.43]:55463 "EHLO mail-it0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725737AbeILEBT (ORCPT ); Wed, 12 Sep 2018 00:01:19 -0400 Received: by mail-it0-f43.google.com with SMTP id d10-v6so494608itj.5 for ; Tue, 11 Sep 2018 15:59:49 -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; bh=I5ESdrhipRbibVthHVriYBdDUSjfzWMwFQGQJ70RB5Y=; b=E/ievZ/BGH/EEOEmveCta2cby1N413pYyxD4+O0H3n25Y2iNQlKrI00uWEqTXnKrjR xEy/Q4EIgDV6S14c62vgrHVXY7u7eApk8nk6dKY1Rx6+IzIbN6UH/UySvSXxMLpeJpOE HDWDYFARgvBJJ4V+qJuHOekVVlPtZOiWytYvc= 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; bh=I5ESdrhipRbibVthHVriYBdDUSjfzWMwFQGQJ70RB5Y=; b=enkqrmPKrl4ARREIYayIG+mvHdEYwqPODduhRPcf4ytMK8ilBY2oMbFFgg23ogop86 TBBtEY5OoimhS0DQroLeQMrcKnw3TnZ+huoATsUrtTxbbAo5bcsmqjDJaY/gRGV8Vxjc GErnLAUDxzXGCGT5zUFzB9h8pFkHx67eu7zVtz421VDrlxgWEc2DdBOQCK4hPKDe+s49 o+eOi12bnDwLVMYnkRus6WmQQzcYBlDpTuF4F/jxYqsQNkW1VtYJcXhTCUGWtX/9qvP2 xe2JjpMZekJENZAH9Wk87FkstUk1vrWs/6bYlpWurzk981udYFmkilEZIYcXnUSGP6s6 wMYA== X-Gm-Message-State: APzg51B396ZmmPSKUxVKKkJLRcMQk2xa2Uwi2IIYWkO6cYNXA2+mUdgj 0AMyYOMjoaRSLuzuvqyi+JtVj2t4l4KqAy+HzZaE7w== X-Received: by 2002:a24:52cd:: with SMTP id d196-v6mr3590611itb.58.1536706788739; Tue, 11 Sep 2018 15:59:48 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:2848:0:0:0:0:0 with HTTP; Tue, 11 Sep 2018 15:59:47 -0700 (PDT) In-Reply-To: <20180911161527.GA30689@vnote> References: <20180911161527.GA30689@vnote> From: Ard Biesheuvel Date: Wed, 12 Sep 2018 00:59:47 +0200 Message-ID: Subject: Re: [PATCH v2] efi: take size of partition entry from GPT header To: Eugene Korenevsky , Davidlohr Bueso , linux-efi , Linux Kernel Mailing List , Ard Biesheuvel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11 September 2018 at 18:15, Eugene Korenevsky wrote: > Use gpt_header.sizeof_partition_entry instead of sizeof(gpt_entry) > for GPT entry size. > According to UEFI 2.7 spec 5.3.1 "GPT overview":, the size of a GUID Partition > Entry element is defined in the Size Of Partition Entry field of GPT header. > The GPT with entries sized more than sizeof(gpt_entry) is not illegal. > OVMF firmware from EDK2 perfectly works with it, see edk2-tianocore source > code. > > Changes since v1: refactoring (extract get_gpt_entry function), > fix (&ptes[i] -> pte) > > Signed-off-by: Eugene Korenevsky > --- > block/partitions/efi.c | 32 ++++++++++++++++++-------------- > 1 file changed, 18 insertions(+), 14 deletions(-) > > diff --git a/block/partitions/efi.c b/block/partitions/efi.c > index 39f70d968754..724f7c0805a2 100644 > --- a/block/partitions/efi.c > +++ b/block/partitions/efi.c > @@ -428,11 +428,6 @@ static int is_gpt_valid(struct parsed_partitions *state, u64 lba, > (unsigned long long)le64_to_cpu((*gpt)->first_usable_lba)); > goto fail; > } > - /* Check that sizeof_partition_entry has the correct value */ > - if (le32_to_cpu((*gpt)->sizeof_partition_entry) != sizeof(gpt_entry)) { > - pr_debug("GUID Partition Entry Size check failed.\n"); > - goto fail; > - } > As I asked you before, can we keep this sanity check but change != to < ? > /* Sanity check partition table size */ > pt_size = (u64)le32_to_cpu((*gpt)->num_partition_entries) * > @@ -670,6 +665,11 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt, > return 0; > } > > +static gpt_entry *get_gpt_entry(gpt_header *gpt_hdr, gpt_entry *ptes, u32 index) > +{ > + return (gpt_entry *)((u8 *)ptes + gpt->sizeof_partition_entry * index); > +} > + > /** > * efi_partition(struct parsed_partitions *state) > * @state: disk parsed partitions > @@ -704,32 +704,36 @@ int efi_partition(struct parsed_partitions *state) > > pr_debug("GUID Partition Table is valid! Yea!\n"); > > - for (i = 0; i < le32_to_cpu(gpt->num_partition_entries) && i < state->limit-1; i++) { > + for (i = 0; > + i < le32_to_cpu(gpt->num_partition_entries) && i < state->limit-1; > + i++) { > + gpt_entry *pte = get_gpt_entry(gpt, ptes, i); > struct partition_meta_info *info; > unsigned label_count = 0; > unsigned label_max; > - u64 start = le64_to_cpu(ptes[i].starting_lba); > - u64 size = le64_to_cpu(ptes[i].ending_lba) - > - le64_to_cpu(ptes[i].starting_lba) + 1ULL; > + u64 start = le64_to_cpu(pte->starting_lba); > + u64 size = le64_to_cpu(pte->ending_lba) - > + le64_to_cpu(pte->starting_lba) + 1ULL; > > - if (!is_pte_valid(&ptes[i], last_lba(state->bdev))) > + if (!is_pte_valid(pte, last_lba(state->bdev))) > continue; > > put_partition(state, i+1, start * ssz, size * ssz); > > /* If this is a RAID volume, tell md */ > - if (!efi_guidcmp(ptes[i].partition_type_guid, PARTITION_LINUX_RAID_GUID)) > + if (!efi_guidcmp( > + pte->partition_type_guid, PARTITION_LINUX_RAID_GUID)) > state->parts[i + 1].flags = ADDPART_FLAG_RAID; > > info = &state->parts[i + 1].info; > - efi_guid_to_str(&ptes[i].unique_partition_guid, info->uuid); > + efi_guid_to_str(&pte->unique_partition_guid, info->uuid); > > /* Naively convert UTF16-LE to 7 bits. */ > label_max = min(ARRAY_SIZE(info->volname) - 1, > - ARRAY_SIZE(ptes[i].partition_name)); > + ARRAY_SIZE(pte->partition_name)); > info->volname[label_max] = 0; > while (label_count < label_max) { > - u8 c = ptes[i].partition_name[label_count] & 0xff; > + u8 c = pte->partition_name[label_count] & 0xff; > if (c && !isprint(c)) > c = '!'; > info->volname[label_count] = c; > -- > 2.18.0 >