Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5061482pxb; Mon, 15 Feb 2021 08:30:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBqaugOTLAqS3F0kmKYpr66MQZn0Zdtf2Lubb+gOcIXyPl84rkmyMbryZT5JAIb6YcjVa9 X-Received: by 2002:a17:907:20e3:: with SMTP id rh3mr392957ejb.510.1613406629373; Mon, 15 Feb 2021 08:30:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613406629; cv=none; d=google.com; s=arc-20160816; b=glqVkmodKcDWpW3vtCtlSsIr1mKn0xyImIo9NQ7zPUzN91KReFhh0+Tu/O3eAcSUZo QIc0f6MymgTlr9bfifW+MDMgPXLgDylQYDAUpkrch9+gTCsLkHL5AiKYW9h/BWO1xqYO 2nreuBBGGbuYbYW9ZOubKcNddGwtfoN9GsQuYncXo+fh8XNyjTFSI9jU3XOWHXKjy3Ks PsFiOKJwI5af4hgYJsYjkzFGfZXR0w1LB16qdV9o95c9ZU5K8g0O6P8kq607U6xsUlX0 0M3FGGhduLyiK37xvvxaB/Hpu1Of24YhxnaifkXJTD5ulG1PT10uoScyZJSu/3MFwyVT 4FVg== 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=FgWQMnU6X+TZeziu/L0MLtMv/PIvgT1uQ59fnd/8GoQ=; b=048CrCwiV8q5kaG3sHY2qUEExJVj8Cc3eIQnYrmy6LQEME1z7QxAFrTdWFzxjmiaJX yp0L10AcBdd2nqcCxxJcF5BJ5QGsV6Gxu8bysv7fU5O9VLFZ3r+wCxGEW14jgTxNKLYI eVd5ZZqK4PLUCawZWenH5dT5qwhL9pgyDQ5BI2J7xXX5GYOKT0PBuPEcheWM2wSimMVi wGWzdoQbVLz2FqZdRJEh5ms6PL2NnhvSU0X4+KGaKpTgBTXHJvAWcSOHoas+Mphpvi+g 4fnXre76O+lUbIM0P7iS0LjNNSaxVZ/hUUKlwh2mOOXkRH5bjCXn40DB7v7JMomdVyvC 8HsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lVgdAeuT; 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 e1si12262533eja.255.2021.02.15.08.30.05; Mon, 15 Feb 2021 08:30:29 -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=lVgdAeuT; 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 S232427AbhBOQ2o (ORCPT + 99 others); Mon, 15 Feb 2021 11:28:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:50212 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231366AbhBOPhS (ORCPT ); Mon, 15 Feb 2021 10:37:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id ECC6A600EF; Mon, 15 Feb 2021 15:32:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403144; bh=ft/YBWz1t9UpptJmcSTd20AycxE77gRkYFZxdGCheSs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lVgdAeuT/cphymnYGk1HUBEEMlbjEKw1e+UtGds5VdSwcJdmMbcCm1clo3cOLnrBT m1xCz5NPbe92S77cvUrQPu3RzHNKAPiIHC0UcIMCCHQeK9BVnJXpgUq2El1f9ahXXr 4vjPcShFVcWiM9QLEeHgzzsPxbNOZXX/mcBcvGu0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexandre Ghiti , Atish Patra , Palmer Dabbelt , Sasha Levin Subject: [PATCH 5.10 037/104] riscv: virt_addr_valid must check the address belongs to linear mapping Date: Mon, 15 Feb 2021 16:26:50 +0100 Message-Id: <20210215152720.680761820@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152719.459796636@linuxfoundation.org> References: <20210215152719.459796636@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: Alexandre Ghiti [ Upstream commit 2ab543823322b564f205cb15d0f0302803c87d11 ] virt_addr_valid macro checks that a virtual address is valid, ie that the address belongs to the linear mapping and that the corresponding physical page exists. Add the missing check that ensures the virtual address belongs to the linear mapping, otherwise __virt_to_phys, when compiled with CONFIG_DEBUG_VIRTUAL enabled, raises a WARN that is interpreted as a kernel bug by syzbot. Signed-off-by: Alexandre Ghiti Reviewed-by: Atish Patra Signed-off-by: Palmer Dabbelt Signed-off-by: Sasha Levin --- arch/riscv/include/asm/page.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index 2d50f76efe481..64a675c5c30ac 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -135,7 +135,10 @@ extern phys_addr_t __phys_addr_symbol(unsigned long x); #endif /* __ASSEMBLY__ */ -#define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr))) +#define virt_addr_valid(vaddr) ({ \ + unsigned long _addr = (unsigned long)vaddr; \ + (unsigned long)(_addr) >= PAGE_OFFSET && pfn_valid(virt_to_pfn(_addr)); \ +}) #define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_NON_EXEC -- 2.27.0