Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4265744imm; Tue, 11 Sep 2018 09:16:05 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYImfsyTd7fmwfGFwa/mfj1S62ArOrn7aGwjItXzse2ov4uY4zFsGwzlFdsQu0vbPisoj6R X-Received: by 2002:a17:902:528a:: with SMTP id a10-v6mr27669557pli.199.1536682565542; Tue, 11 Sep 2018 09:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536682565; cv=none; d=google.com; s=arc-20160816; b=xhfh78FNfmebhI2sV7FBwQLbCTDXcl4oaZbq2eMAEbGjrxud1AhaOzjoaaQr1x5AB9 0SLeB4AGxLaPLjllHnZaQ1IDGiuS1L51fGk8tpf3LnhtuewKANL2Q9IUYxwoL6WNu97R kecOVxN1sgv4D52mfmpe6fLWlyHJKwg2A+D+fMmWVcRc/VpEaPs/Dt9IsWNHMmXm8Rmi GnNd0v6R1ucHAbl3vo1RFpCiYNp2MEdUSpbKfYo7fF9boQe/Klte3wrQ1Oaa+LXP+z69 geG16u/4HQdgXQacAjbWgd+7k7dVYfCE3/+NrYj1uxspSoSXvquKoeX3JaBfNz9DQzgk LvFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:mail-followup-to:message-id:subject:to:from:date :dkim-signature; bh=wz44kfLkKQJU68NWsi2wFVq4c2klOJNm/qjEh5ldOUg=; b=DWqBzTIWEF7J03g889OO/awAIzgPxG7hr/r5N1VqPtGLJQK9M8pB/ROdmy4sPYT6TK mQ/Bn1BS+anGytZMZxC3pDgIe6IU5aV6m8g+ubx4jWQqqNUGR3Xp28NvRt3damZdC1FQ TeRr9lxHX9s+XxqJNjx2IarBm46372F+5fnnViEg2Te0ojx7tSofBXeG+nFKewiQhbIV dXpLDWUO1+WDSgdpOhr48vKyIsTTOOt9FWZVe0eA8Gl3JMlivyiphMwRwuYrWV554gL5 Md959tvdThQLGUPi8GOvbtH3/IAS71O7sIUZfEWxSnpJ3JFyIBYs8ZfbJJTjRlGNfG9F mUKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=L5oPAkZe; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r130-v6si19546828pgr.456.2018.09.11.09.15.39; Tue, 11 Sep 2018 09:16:05 -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=@gmail.com header.s=20161025 header.b=L5oPAkZe; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726983AbeIKVPe (ORCPT + 99 others); Tue, 11 Sep 2018 17:15:34 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:42728 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726800AbeIKVPd (ORCPT ); Tue, 11 Sep 2018 17:15:33 -0400 Received: by mail-lf1-f68.google.com with SMTP id z11-v6so20812841lff.9; Tue, 11 Sep 2018 09:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition:user-agent; bh=wz44kfLkKQJU68NWsi2wFVq4c2klOJNm/qjEh5ldOUg=; b=L5oPAkZezgdbG/LqZPy0DTZQzHZx1Pip8le51lvDcikPjRrt9capG3cl2e2zwCSQbb SFg5FJZLsLovT0p3S9KIUSVVcC6V/WY89k8lg6p/IPgwtJZKVqhVvjtDpsqR1U8YAtzi LOIkQ+IHq7j+k7rPM7rNI1KR3lvurMZLuPLnH05dJ7WkWZ/3S68uPS3Sjcc6edL9Dg7y f3se8697WbomRRTuo4Jj+dJws6GCaqsR03b+7Et+J125Zc3vQDXZCGpOjErWWjHY+J+S jK5dPCuGQrTo4WXjBhZBDZrR/rC2u/Ei6pDvB0kvFfDb7hStThhOJ0KxNmwKbcMuy9Mg nFuQ== 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:subject:message-id:mail-followup-to :mime-version:content-disposition:user-agent; bh=wz44kfLkKQJU68NWsi2wFVq4c2klOJNm/qjEh5ldOUg=; b=VUVK+xyT1a2yFMX+JYm1QmZ637sQRXRuOvb8Ed/k50DV39k1EXcM0NftkkU0j/SRzO xanc3uKAmFeg461uzPyE/AYAwmiXsirIaTwZ8Dyb86INbwHq2Ta2Itb7r8J20wXDUDPw 3rxYpZ6AZ161TTT5JlvBu2PJFCCofcUgWvoCrmKCjTdUkt6NJGAXid36Ltx9WRG87dDO xym/EpBvP7gu4lV5NrX53zR4Gu9BIWEabiHZy5DKL3zsovseZzU12KzJ/LRqnADFVOn0 8ZGSstaqHGQI+Dx2fnC/sZdhMVjl1KbQZIE6zB8zM4asQODEWwhHDjGJBMy93j3wT0tT bLUA== X-Gm-Message-State: APzg51Cc0N+4eT3VIt2QXMOnPPx7tb++VRIU5RQqwoPs4kFcW97SINKJ ZMBUOZaBtBYsM2e5jkv6NDg= X-Received: by 2002:a19:f20:: with SMTP id e32-v6mr15754294lfi.2.1536682530878; Tue, 11 Sep 2018 09:15:30 -0700 (PDT) Received: from vnote ([95.72.40.207]) by smtp.gmail.com with ESMTPSA id r4-v6sm3333027ljd.70.2018.09.11.09.15.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Sep 2018 09:15:30 -0700 (PDT) Date: Tue, 11 Sep 2018 19:15:27 +0300 From: Eugene Korenevsky To: Davidlohr Bueso , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Ard Biesheuvel Subject: [PATCH v2] efi: take size of partition entry from GPT header Message-ID: <20180911161527.GA30689@vnote> Mail-Followup-To: Eugene Korenevsky , Davidlohr Bueso , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Ard Biesheuvel MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; - } /* 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