From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.85.128.66; helo=mail-wm1-f66.google.com; envelope-from=philmd@redhat.com; receiver=edk2-devel@lists.01.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) (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 4DA222118EF7C for ; Mon, 3 Dec 2018 02:33:47 -0800 (PST) Received: by mail-wm1-f66.google.com with SMTP id y1so5154533wmi.3 for ; Mon, 03 Dec 2018 02:33:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=cBPGtx8Chbw1QB2zjbcIRzuZl0NVFU0mLbq21jMSnas=; b=Oh5AeK5QL5MG6S5bTCYGcne37yi4AHur6BhicFEm2eYV+y9qS3pFw6tC6bQ4pOGejf FxZxxpjz38zQzQ2fELnQJBBPyOu698VhKcyMowREoi5gEI1c38QEp8tWr60cbmcqeH/w HueZ17i3bnCAQ0duB3/ucT6V5/iOdfErgX8IbXDrfuCl/4ybuPqqR8JgWwD/bfVlCipE yqOY/o+mcFHHe5Tpo5BOB176NqUEZtRtPonlO/i1ifiapWybD66WHTXvafdoFnvHiYyK ckTiI/yy5k4Lf/HgzTiZAgXFVKEhvqdRFPvDIKu9ISAyoIkx7oRaqJYF48Zr8YTb1Bd5 K8+A== X-Gm-Message-State: AA+aEWYuN0Gz+FSSvvibvtTiz5613C5vJ/y3wXJo0V5yqjxW3VBzdDWp rjeTYsaKS7whv3A0mi1xGk5E8g== X-Google-Smtp-Source: AFSGD/Udry0Rl8iMm/nhJ8E3ZxP/1w6KC48OwRwksxg8c5V3rH7isTqInMDdo1flqf18JzF+c2LKiw== X-Received: by 2002:a1c:bd82:: with SMTP id n124mr7503342wmf.105.1543833226186; Mon, 03 Dec 2018 02:33:46 -0800 (PST) Received: from ?IPv6:2a01:cb1d:8a0a:f500:48c1:8eab:256a:caf9? ([2a01:cb1d:8a0a:f500:48c1:8eab:256a:caf9]) by smtp.gmail.com with ESMTPSA id w9sm6288984wme.47.2018.12.03.02.33.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 02:33:45 -0800 (PST) To: Ard Biesheuvel , edk2-devel@lists.01.org Cc: Leif Lindholm , Laszlo Ersek , Eric Auger , Andrew Jones References: <20181130112829.12173-1-ard.biesheuvel@linaro.org> <20181130112829.12173-2-ard.biesheuvel@linaro.org> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= Openpgp: id=89C1E78F601EE86C867495CBA2A3FD6EDEADC0DE; url=http://pgp.mit.edu/pks/lookup?op=get&search=0xA2A3FD6EDEADC0DE Message-ID: <73b6c2a5-cca4-0140-6767-9f043fa1c141@redhat.com> Date: Mon, 3 Dec 2018 11:33:44 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: <20181130112829.12173-2-ard.biesheuvel@linaro.org> 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: Mon, 03 Dec 2018 10:33:48 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit On 30/11/18 12:28, 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. Good catch! > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ard Biesheuvel Reviewed-by: Philippe Mathieu-Daudé > --- > 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) || >