From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::442; helo=mail-wr1-x442.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) (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 3E03821191F4C for ; Fri, 30 Nov 2018 03:38:34 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id l9so4951609wrt.13 for ; Fri, 30 Nov 2018 03:38:34 -0800 (PST) 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=fRPKwu1yM2AfCZWfQB+AuT904BSRRx8uBcWSMjgkz6I=; b=A8w5+aUqKumu9HpqfxvVRj5QpGiH2PYChIAaLzhEfF6EdrJzrFd9tpuLhJnQiLvQen UBAyxrhTBVuna9lXUf88NwPX6sOSBr+ngIlQJlUzs1XQygAXggGxAxArY+5Ect13kvdz AlwElPqouMq1M85LYMjJobAF3O3OCwju3N8U4= 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=fRPKwu1yM2AfCZWfQB+AuT904BSRRx8uBcWSMjgkz6I=; b=VrTUSyvIg2gNeoGHZ3FBfN/T//cJuECj000nF3h1eQlkNi02rxA+CHEeIrU105O3Oi iymQWRFuRV70+XsFzFMiI3phiqtXxjJLd7FOwThqEDK8rFTj9qibfayCMKu102JtTqg7 MEl24Q2XKhJ7OId5uepNTl9gqXPOEnWJK7fDbSAtGSNKk5XQ3Svk2UoMJyWGgWgE3mBt 8CsQ5ffDqCOQcdXv2/p1zKIuWAfQNl5oZtGS97/JRT09TCIsawI2tA1Za1RTTQ7+b9fA DNZt8EgbrXQZM7bWsHp9avxohYo69Y4JB9NmzIRs5PhMW4A5/zjr00YeJOdX+d776GgO xzmA== X-Gm-Message-State: AA+aEWZcnoQgJKzx1j9M5e7fYFnyNGTSzXWDeOYn/BS8x5NbVNpGUkWV qecIMuUMbL5VO0g1p5VRnsWKhJG9oS0= X-Google-Smtp-Source: AFSGD/XhFCkTMFJ0gPklqNZZ4niB2ZYUn5nubA3r5jfoYFN/kJwK2eg83KIIGS6zM97nmnQ5YjCQuQ== X-Received: by 2002:adf:ce02:: with SMTP id p2mr5048516wrn.185.1543577913504; Fri, 30 Nov 2018 03:38:33 -0800 (PST) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id j24sm5659170wrd.86.2018.11.30.03.38.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Nov 2018 03:38:32 -0800 (PST) Date: Fri, 30 Nov 2018 11:38:31 +0000 From: Leif Lindholm To: Ard Biesheuvel Cc: edk2-devel@lists.01.org, Laszlo Ersek , Eric Auger , Andrew Jones , Philippe Mathieu-Daude Message-ID: <20181130113831.sexqquxaqeeawnw5@bivouac.eciton.net> References: <20181130112829.12173-1-ard.biesheuvel@linaro.org> <20181130112829.12173-2-ard.biesheuvel@linaro.org> MIME-Version: 1.0 In-Reply-To: <20181130112829.12173-2-ard.biesheuvel@linaro.org> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [PATCH v2 1/4] ArmPkg/ArmMmuLib ARM: handle unmapped section in GetMemoryRegion() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Nov 2018 11:38:35 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Nov 30, 2018 at 12:28:26PM +0100, Ard Biesheuvel wrote: > GetMemoryRegion() is used to obtain the attributes of an existing > mapping, to permit permission attribute changes to be optimized > away if the attributes don't actually change. > > The current ARM code assumes that a section mapping or a page mapping > exists for any region passed into GetMemoryRegion(), but the region > may be unmapped entirely, in which case the code will crash. So check > if a section mapping exists before dereferencing it. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm > --- > ArmPkg/Drivers/CpuDxe/Arm/Mmu.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c b/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c > index 12ca5b26673e..3b29d33d0a9c 100644 > --- a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c > +++ b/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c > @@ -457,6 +457,9 @@ GetMemoryRegion ( > > // Get the section at the given index > SectionDescriptor = FirstLevelTable[TableIndex]; > + if (!SectionDescriptor) { > + return EFI_NOT_FOUND; > + } > > // If 'BaseAddress' belongs to the section then round it to the section boundary > if (((SectionDescriptor & TT_DESCRIPTOR_SECTION_TYPE_MASK) == TT_DESCRIPTOR_SECTION_TYPE_SECTION) || > -- > 2.19.1 >