Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1971572pxb; Fri, 29 Jan 2021 09:36:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJznaZyH5zQm3sfyJVHNodP304OMC94RElx2tsT8TB3ClhtXCvtz+p45W8lJ4pXPLkva+Vdr X-Received: by 2002:a17:906:7cd8:: with SMTP id h24mr5591712ejp.511.1611941780330; Fri, 29 Jan 2021 09:36:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611941780; cv=none; d=google.com; s=arc-20160816; b=v/sissoylFzxPrnOZII9kajxTMIsw9wYSdolnQcrsPe7C/5pdn4hd8ZWgQqgsKhtzr 1BRg1CqQ69PecVuYDxl3QNxpbwz0waWqUqszGnupciDqDbCkPe1SW4Sf2ZUuOZohKueM cUCUKJoG1Pt1E+vKh09aKq9huIf19uedNThoDBA16sRzWqc7Vxz/6aYgpyzUX2oVvj2+ I/NizwGwQAvkQjaHha/bBX7efGBPg12eEhDreu2jLl1CXIObeDeUuzIFUT/SO1Ud7qRL jxb/DazSXUOKRXJHmTMJlIMUJWCIplrZ6/WP1nBGf88xe543snmbjCM2Idk4LE7pNTCX Ow8g== 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 :message-id:date:subject:cc:to:from; bh=L6gqJKDZC7u1x6UrPzhPwPjRqLqPoSuaYlamwAC5Z5g=; b=waoNLuwoJ7Y9gVfo5GCuU8YPNdsSgFqewYrV5oHT278LKHDczMCJZMDocJ1eLfSpQo FywDnXouMQH3u/GHDuStLSFaATmONEE/W5KuGPF7SjTf+GW28WH4obYsDGdyuzoguFGa YddQbhSkjCSTBt1lGDO7DKxknmI5UraMdNWa0mok8tCIO9w7safhQsI5WJAPSuZPnyg3 czs01FFtTD/ny0C2NcIVFf8GGxZSyQXV/3XN1XS+TAFnhonyigV1JnIxU5VaSx9Dl1ak 79dz+v5sO7v2u6jG2FcvwMa6kzumsdv4CkD6jvuNCliGIlVabF8ctvgU5Vhmg73AWC0Z I1sA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a59si5943806edf.278.2021.01.29.09.35.56; Fri, 29 Jan 2021 09:36:20 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232536AbhA2Reo (ORCPT + 99 others); Fri, 29 Jan 2021 12:34:44 -0500 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:50555 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232334AbhA2RcA (ORCPT ); Fri, 29 Jan 2021 12:32:00 -0500 X-Originating-IP: 92.91.220.130 Received: from debian.numericable.fr (130.220.91.92.rev.sfr.net [92.91.220.130]) (Authenticated sender: alex@ghiti.fr) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id DAEC6C0010; Fri, 29 Jan 2021 17:31:07 +0000 (UTC) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , dvyukov@google.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH] riscv: virt_addr_valid must check the address belongs to linear mapping Date: Fri, 29 Jan 2021 12:31:05 -0500 Message-Id: <20210129173105.22020-1-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 2d50f76efe48..64a675c5c30a 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.20.1