Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5038810pxb; Mon, 15 Feb 2021 08:00:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNN4blDq/10MD2Lr/4fYttrGiXOqly6zgVlOXP9TGdevQWd2DICpiKO0sn8xQslNeo7Mrd X-Received: by 2002:aa7:d80b:: with SMTP id v11mr16390065edq.17.1613404850936; Mon, 15 Feb 2021 08:00:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613404850; cv=none; d=google.com; s=arc-20160816; b=ffQyYxPTeraujjjQIk+KsS7+dZLIDpVq0Vcsj68nojnQ6PV+5DMz+QjagDK2MCO5+N 1C4NCbWY/H6M/neBaKYeXLCOZo2ouFekrAc1FGngagUGn9H+gJLUMif3Btln8spzbvf7 9DX/HpC6zpF3vxLmTFYOzsnbaRFRgYvuyggxUs7s42GNzS8//0hOwdrkobzdrZrAs7fN lURw/1NtFuA/9AjCXjfWRScZRXyLgD9cnMkVmiy8qO7Kx2zGRKjUwb3Trt6qAgdwgeNr DJuNvxG9Y25Lllbm3xaBw7cpiwhrnobcHo9KKiNe7NzJvcEkAHG4saXGF9vr/ji8KjXt FCHA== 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=K/TTbBNG/5lQeruJT3Dhojj8VGefZ8XEqH+jHtkQMvs=; b=fzezDxynRNKH6o8F26of5Ex+gTZnT8sxBfR0QchrczqiIBXJBJRBxVb4tfq2E+VK+U vwxgcGmpxrjrvQwLxGgPFVUA2rf8cG0vlPX3ejhC3RALMMzSJdEbPmQPW+e4/GZ6V+hy Xd2R/2tkyQ3oUQlnYgfYs+i6i3tkJuBZa+5C+DvSW1oDv7To4nURwbsS7FGVb31GGc18 lxAf7EJYwUxHEV9WGJ6I7CjqHYq/4rsMGUYm9MLOkMUdU84lIsp8l8XMpKA/ggeoaxOM Yf5RDmAOxLZ3BajP/gf9rX2YmyhY0rFEs7El4uGlk+49gAlnXn29MVxQ0ExQnHiOyRYZ eILA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=N5nIyt3d; 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 o6si6874112ejx.460.2021.02.15.08.00.24; Mon, 15 Feb 2021 08:00:50 -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=N5nIyt3d; 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 S232030AbhBOP5K (ORCPT + 99 others); Mon, 15 Feb 2021 10:57:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:45566 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231269AbhBOPcp (ORCPT ); Mon, 15 Feb 2021 10:32:45 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6E9DB64EA9; Mon, 15 Feb 2021 15:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403012; bh=N3IHvP9qsEjKvZNs4XAG/Gl7HN0ZoAJSQ1mcVF/2Ll4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N5nIyt3d6EKrCAVpatwt4CMBI1TV3YrPjJilYyHdjche986v94X1kgYP2S5FatEeu m+jA79dMY1eUrJslBjqa+MwDVaZim3ygTYrMv41I/BHF1RHxJkP+ExvFx8iC0MuSn5 O1lKUHmCEhlJZ/v3OQIwdwiDybxLsCcLDLi02I6U= 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.4 19/60] riscv: virt_addr_valid must check the address belongs to linear mapping Date: Mon, 15 Feb 2021 16:27:07 +0100 Message-Id: <20210215152715.984119907@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152715.401453874@linuxfoundation.org> References: <20210215152715.401453874@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 3db261c4810fc..6a30794aa1eea 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -119,7 +119,10 @@ extern unsigned long min_low_pfn; #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_READ | VM_WRITE | \ VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) -- 2.27.0