Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2273317pxb; Fri, 5 Feb 2021 13:27:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwShoW4RHzvozpHWohQeHLs9PoA+BNrznqPCpPPwE1FtZIK43MDAV3OMArddbnhY54QzJJf X-Received: by 2002:a17:906:688f:: with SMTP id n15mr5896152ejr.71.1612560439860; Fri, 05 Feb 2021 13:27:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612560439; cv=none; d=google.com; s=arc-20160816; b=APidgSAfPsPgvbYzqhd6krPiHxPYuVAFk3s438e2DmWb0IosasgIsQoaTS0ITKFgBc y+tUSCAgm2LMeJMErMdX+lQCMc+eOuLrVwGjXqEQiBIJkHxqMlYq52jATND8yzyArbal g6XjADX6RO4z/fnrp8/CHrEvlTvoc3fYltulmc64H9us2aUWbAeOYAsEVl+Q6BvR43gr y7UJtEtrUI9mw5qMSd6M8qkdckCaVewyblzEVg0VykyUME2pBP9exetALBk2AfcqbgMv 8etHOI212TFBQGEI4+iNg5gA7tNwPAHCIWTAPpExisXSCtlue4+3ZSfK/SRIQ0wtePD/ B3Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=flgeUFycnM3QnyTOyu3lIZKTTj/UDDt+rASZBNXaWdw=; b=CPnxFac+eNWJkxXccRlAHwDUGC4shjwfQE6DpoxVcr9w6PUxHndGw1rFvKK4myZF5w KgygwkUF8/QYbba8DOTEj+SSMiiPuO5BxQZAfL8vEwucPnP4hS8oYdj9X3X1UVfEhG14 PCiL3F0tPzGXweJDSrNlWM/1VwKms6C7aR+KHtjUModcNxrXJwiTRI7KXAuVX1sXs0+3 d5jGQuBRC/9zRSWd/0nfQPEt7xhD0w8IPWBFPJbslk8EqPCChmmmISsWZ4TjSBswevPN Tg+ucIPjmAubQXv76I5es7MeTyZXLuh4erUcgrxe3zgQTeGtk7roapHsP+0wYrM60bER oXXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ixH/GduN"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g5si5964890ejw.275.2021.02.05.13.26.55; Fri, 05 Feb 2021 13:27:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ixH/GduN"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233777AbhBEVYp (ORCPT + 99 others); Fri, 5 Feb 2021 16:24:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:45594 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233045AbhBEPCP (ORCPT ); Fri, 5 Feb 2021 10:02:15 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 95E9F64FD3; Fri, 5 Feb 2021 14:09:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612534165; bh=QZKkyRFyQyc5Crta/nJbyJUZDzbImuaHz7VxJhZUWw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ixH/GduNOWIcOSNLlHz+XfHsSBbQWx+PbBX1h0968dnMShwvwQRRVB70bb3i0tGaP MdNpalOQbpdS4bnBIY/Mz2fwghStRpNr4kLqEW7Uye4MdT2vRsDymmC4KsYwMbleHa oHXQIDTFKJh0r2t36VVGvTRZ85sa7yyjcwRp9+z8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Will Deacon , Catalin Marinas , Mark Rutland , Vincenzo Frascino Subject: [PATCH 5.10 13/57] arm64: Fix kernel address detection of __is_lm_address() Date: Fri, 5 Feb 2021 15:06:39 +0100 Message-Id: <20210205140656.544438617@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210205140655.982616732@linuxfoundation.org> References: <20210205140655.982616732@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vincenzo Frascino commit 519ea6f1c82fcdc9842908155ae379de47818778 upstream. Currently, the __is_lm_address() check just masks out the top 12 bits of the address, but if they are 0, it still yields a true result. This has as a side effect that virt_addr_valid() returns true even for invalid virtual addresses (e.g. 0x0). Fix the detection checking that it's actually a kernel address starting at PAGE_OFFSET. Fixes: 68dd8ef32162 ("arm64: memory: Fix virt_addr_valid() using __is_lm_address()") Cc: # 5.4.x Cc: Will Deacon Suggested-by: Catalin Marinas Reviewed-by: Catalin Marinas Acked-by: Mark Rutland Signed-off-by: Vincenzo Frascino Link: https://lore.kernel.org/r/20210126134056.45747-1-vincenzo.frascino@arm.com Signed-off-by: Catalin Marinas Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/memory.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -238,11 +238,11 @@ static inline const void *__tag_set(cons /* - * The linear kernel range starts at the bottom of the virtual address - * space. Testing the top bit for the start of the region is a - * sufficient check and avoids having to worry about the tag. + * Check whether an arbitrary address is within the linear map, which + * lives in the [PAGE_OFFSET, PAGE_END) interval at the bottom of the + * kernel's TTBR1 address range. */ -#define __is_lm_address(addr) (!(((u64)addr) & BIT(vabits_actual - 1))) +#define __is_lm_address(addr) (((u64)(addr) ^ PAGE_OFFSET) < (PAGE_END - PAGE_OFFSET)) #define __lm_to_phys(addr) (((addr) & ~PAGE_OFFSET) + PHYS_OFFSET) #define __kimg_to_phys(addr) ((addr) - kimage_voffset)