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::343; helo=mail-wm1-x343.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) (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 0CA47211B699F for ; Fri, 11 Jan 2019 10:07:35 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id t200so3267410wmt.0 for ; Fri, 11 Jan 2019 10:07:35 -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=y78Unq0YyR+q+jfGMvGfpGafMMPGpU0SO4pEoaTwIzQ=; b=YviB6zRwOhOD94my0XaLzxD/+spuQtonVBHbdloYutRpyuzTTCcN6G2OE/aNZr18Ks bTz2oo9lwwetK+ZtbQbFAX6F/S+oGpS8IsKLkpEQiCJglNal5cfLg9RTaPqIHDUBVDXt i+36jEy36cHBE/4HlOsuxHk6gtluDOCJ2rikU= 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=y78Unq0YyR+q+jfGMvGfpGafMMPGpU0SO4pEoaTwIzQ=; b=mKPx9tXHMdO65FL7mwJhmTWdLtjCJCfc+YyWiaa21VjxQDxH3FMbChJnqdgeVj2S/g KfCNYBtlZ5CFV9x10CUcRdG2M4StibjijaooYA8WX/Ad30l4pCS3y3GBc79jLdwWktlR Uw9eSl8kHTS0V4G/bj1p0xCYSnVuwH4LugBjIOABbSgC81SvEEpx5KwUywLlFsl6Ers0 OnvAb0MJoi9gx953y5307xlf796D990qGn/TS6uitFrAuXcm9khe8m0Sh9cOIFeTtMwC X3lAg68xb4euowuBXWrWQfSAO+5G7CcC27ff3+IJ4I88omsC7nIf636CPKc0Ls9ESKdy YwkQ== X-Gm-Message-State: AJcUukfqbc+knI66biyQLkewZc9QgqcMHalkrwGYBNibgty1HUCKnq6q PTWYkWKEcZEJwChuP2RaXK7YvnvmWkw= X-Google-Smtp-Source: ALg8bN4Ac3dcuLH7jmEpAVJ2v3wcB0tuEVwm57RxOKah6Y+wBi9q+krl4KW9sGHuBedHnB1WK5/CVg== X-Received: by 2002:a1c:2c6:: with SMTP id 189mr3131498wmc.21.1547230054511; Fri, 11 Jan 2019 10:07:34 -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 f10sm1792833wmb.35.2019.01.11.10.07.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jan 2019 10:07:33 -0800 (PST) Date: Fri, 11 Jan 2019 18:07:32 +0000 From: Leif Lindholm To: Ard Biesheuvel Cc: edk2-devel@lists.01.org Message-ID: <20190111180732.ea3dl7mxw2z4hfgm@bivouac.eciton.net> References: <20190104180432.24480-1-ard.biesheuvel@linaro.org> <20190104180432.24480-2-ard.biesheuvel@linaro.org> MIME-Version: 1.0 In-Reply-To: <20190104180432.24480-2-ard.biesheuvel@linaro.org> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [PATCH 2/2] ArmPkg/ArmMmuLib ARM: fix thinko in second level page table handling 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, 11 Jan 2019 18:07:36 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Jan 04, 2019 at 07:04:32PM +0100, Ard Biesheuvel wrote: > PopulateLevel2PageTable () is invoked for [parts of] mappings that > start or end on a non-1 MB aligned address (or both). The size of > the mapping depends on both the start address modulo 1 MB and the > length of the mapping, but the logic that calculates this size is > flawed: subtracting 'start address modulo 1 MB' could result in a > negative value for the remaining length, which is obviously wrong. > > So instead, take either RemainLength, or the rest of the 1 MB > block, whichever is smaller. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm > --- > ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c b/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c > index b237321a8d8b..3b3b20aa9b78 100644 > --- a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c > +++ b/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c > @@ -294,8 +294,8 @@ FillTranslationTable ( > PhysicalBase += TT_DESCRIPTOR_SECTION_SIZE; > RemainLength -= TT_DESCRIPTOR_SECTION_SIZE; > } else { > - PageMapLength = MIN (RemainLength, TT_DESCRIPTOR_SECTION_SIZE) - > - (PhysicalBase % TT_DESCRIPTOR_SECTION_SIZE); > + PageMapLength = MIN (RemainLength, TT_DESCRIPTOR_SECTION_SIZE - > + (PhysicalBase % TT_DESCRIPTOR_SECTION_SIZE)); > > // Case: Physical address aligned on the Section Size (1MB) && the length > // does not fill a section > -- > 2.17.1 >