Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp635078imm; Fri, 14 Sep 2018 04:07:33 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdai1LIxE+hOXRnkU0owcZhRr9p2A6C64FSbRUFjhnJZI4teJC/VB9Ou2ZFr8ciooyamtD8v X-Received: by 2002:a17:902:261:: with SMTP id 88-v6mr11649000plc.331.1536923253111; Fri, 14 Sep 2018 04:07:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536923253; cv=none; d=google.com; s=arc-20160816; b=bknJfcsN7nkC2hkBVRqmlRUcCXWGZLW9slSEyt5eksq/lB2RPQn/mIf89qujOtIfgI PBLNAha5ajsFdx1a53KCH9l396f8CnyqXnWhGifEv8bsj7qRY1wYax3JKByX8Qe8wwUt +7UBeNroDmDCr8ZSr/qRxDyBGuURuy95etoVW7Irh1yZdwgMw4QsU0Cg1dSaPPWKZX9T v7seQ0SsymKRk6RM3YGXggrzCutb2Xz4XyJ5mkn+sYZB41vYeWKWyaX27rpepYFy7w+Y G+vyU2nV3NXfDmEoXtcab1MlqXA92QHl75fqxJ+vVFanjUfImEi8K3Y5zWEqkegxyaCd +f+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=fkoE/S/UEp2GB1tNjgkLpD3Pkty6nPkuGykyosKUZTM=; b=Dh6np2zYSBVULsY/Yhx/huRD4AaJcH0mky0t0TPvLlmz5n/YETfYe2eWJKN+TOjqLi DNCmpVaBgc5A8oByZqJFeY6OgnxX59FdegmTs1a3y38CISbKVgr91TwQ2PoLh7ZEh9kv SwhSnjjy1bO6dhSlqYLgNgyaLyMMPbJdEvbPUxztPJAUcNuQYgtTS+e1iiBD7YVMqfdH QP05NPm0YFAN5kWY2SVJVMJVBNguO873kSsX7kx0St3T3EVX93i/ef4anAhD5w4wmnqx ro3CMrwCLl1xk3vAJ+drIMXuM+mA/ymYyf9cGd670bDbKJfuER59AjWABKzsHMJzo/Tt TS+A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k13-v6si6636333pgg.346.2018.09.14.04.07.17; Fri, 14 Sep 2018 04:07:33 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727992AbeINQVH (ORCPT + 99 others); Fri, 14 Sep 2018 12:21:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49958 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726872AbeINQVH (ORCPT ); Fri, 14 Sep 2018 12:21:07 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 95A2981DE9; Fri, 14 Sep 2018 11:07:07 +0000 (UTC) Received: from ws.net.home (ovpn-117-57.ams2.redhat.com [10.36.117.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EB6D1308BE75; Fri, 14 Sep 2018 11:07:05 +0000 (UTC) Date: Fri, 14 Sep 2018 13:07:03 +0200 From: "kzak@redhat.com" To: David Laight Cc: 'Eugene Korenevsky' , Davidlohr Bueso , "linux-efi@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Ard Biesheuvel Subject: Re: [PATCH v2] efi: take size of partition entry from GPT header Message-ID: <20180914110703.ishvqwcpcf5ozihy@ws.net.home> References: <20180911161527.GA30689@vnote> <20180912083844.iegei2kobcz4b7ag@ws.net.home> <6d349d22d37041c1a2942d8ed4c76b69@AcuMS.aculab.com> <2db38b2d1af34ab9b653c665d08872f1@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2db38b2d1af34ab9b653c665d08872f1@AcuMS.aculab.com> User-Agent: NeoMutt/20170912-66-504cd9 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 14 Sep 2018 11:07:07 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 14, 2018 at 09:01:48AM +0000, David Laight wrote: > From: Eugene Korenevsky > > Sent: 13 September 2018 20:48 > > > > > I suspect you also need a sanity check that the value isn't too small > > > or stupidly large. > > > > What would be the criterion for too large entries? > > Anything larger than the maximum size of the full GPT table > would be a start. > Even something like 64k would stop later calculations going wrong. > I presume there is a check elsewhere that the GPT table entries > are all inside the disk area that was read? is_gpt_valid() already contains pt_size = (u64)le32_to_cpu((*gpt)->num_partition_entries) * le32_to_cpu((*gpt)->sizeof_partition_entry); if (pt_size > KMALLOC_MAX_SIZE) pr_debug("GUID Partition Table is too large: %llu > %lu bytes\n", (unsigned long long)pt_size, KMALLOC_MAX_SIZE); goto fail; } I guess it good enough for sanity check. If you want to be really paranoid than you can also check that array is possible to store to the expected area on the disk: pt_size <= (gpt->first_usable_lba - gpt->partition_entry_lba) Note that is_gpt_valid() already compares the another LBAs with the device size to be sure GPT is no out of reality... Karel -- Karel Zak http://karelzak.blogspot.com