Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2305640pxb; Fri, 5 Feb 2021 14:30:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJxioGxAHJxrn0hP1TA2nUoUt5Zi5KYlnm8Dw0YsSw9np02VoDHel5tw3YUsydOVLu3UVJb6 X-Received: by 2002:a17:906:5043:: with SMTP id e3mr6065388ejk.260.1612564240514; Fri, 05 Feb 2021 14:30:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612564240; cv=none; d=google.com; s=arc-20160816; b=ebYJD0QD//HVufEeMDqIhPj94DRdw0iaCCwfZgNSLpZcQPLWhiFCaJp806A4OQKgTI dG3QGzffHspUT0Xk43of59PA9w5tz9Gudxlvv7xhCG8bvDPUV6rwdGydGg//ZmGbYZJ0 j2KatBWGsdi+KcuOtYiAM/hSKSEuUoDsyPHgB3WK7YjMsVpdjSEl1kKAWd/7JQ14vV0e 0b4nbtHYEp4fwGgY6lJS+FX/3NITfjt7kT0bjtyyAbJlNskRYPWp/uM36NsLhhzoaGTW g5V2loORP7asrj2vK5jOfBkPC9MDfy4jItOgPDHhcm8fid0SyNYL+LO9lvlmFPkHcbzv LbIA== 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=xqkcJOq4ZsSmhnTKSswc1c+hugo69bNWuZRzdDGrAXA=; b=NWA3u45ouTSo/G7sDPBwySIbEiuFRKeyKfhtKFNw5lLLZL8EGFTW/HSoAnJUGWFbDn hNaeTPdCQikkZuypHkLNhuZfHVkkFV8S1gBHms8p3bkX6xzGtTmRChNQicL69czWETlQ sC8eBnVqBuTcKaIKikO6btjwfs4nqtJf8x/a56/XudDsNV8jmdMahTC7mrIi5T64Tt3s 4fGqic+I+3owfLJ08Qgn/qbI1/yYzVymwHkNzYnlW282xvmFRSLytIWRsHoETnMlu1V0 LM5GXfFaU+lr/Qow0M0MzHvWPfRlurFFoPGFbq94RrW8yWgA+ZaJs3Hn8y3O3YBb0jVt Sk9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hJKNk9bK; 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 hs28si6424355ejc.141.2021.02.05.14.30.14; Fri, 05 Feb 2021 14:30:40 -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=hJKNk9bK; 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 S229702AbhBEW3i (ORCPT + 99 others); Fri, 5 Feb 2021 17:29:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:44982 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230170AbhBEOyw (ORCPT ); Fri, 5 Feb 2021 09:54:52 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4D51D6505A; Fri, 5 Feb 2021 14:12:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612534349; bh=JDTuSXzEilPQorvKVII5BkHu2GyI2daOiBcGSTjm18Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hJKNk9bKoali/bpdvV1CatnDnYJ4kD9Y+VkWwp7/muVksRyIukhBgkM1frzcQvvwA +aRgAykPY9t7R4QL/mEUFhiW3bqleI4Kv34ruD5V0TXZHIX6Iz3EzYq6x6bCefU98T x0NNe84Kp+NgV8TTEh4z2droTyGfQcY5jQoqwZm0= 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.4 06/32] arm64: Fix kernel address detection of __is_lm_address() Date: Fri, 5 Feb 2021 15:07:21 +0100 Message-Id: <20210205140652.618550818@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210205140652.348864025@linuxfoundation.org> References: <20210205140652.348864025@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 @@ -247,11 +247,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)