Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3111170pxb; Sun, 31 Jan 2021 04:43:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4Wu5X4eLKtnnutvduosnPPskSkAEEmlw4Tdq3stESqvgdeDolykBEPNYZFdb9bGiypc9M X-Received: by 2002:a17:906:3b0b:: with SMTP id g11mr12670944ejf.169.1612097001961; Sun, 31 Jan 2021 04:43:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612097001; cv=none; d=google.com; s=arc-20160816; b=LB2+LBtOAb9PU+nun/YfYV9gjePE0pdThcLJIIQO4JImc/ixgaQ1tyXmcCmmALZywA IfuUIeWV/zLFN0XzeCWaE5TxVu+5Y9uPEXQGK0PSw5LuzVhreGsxr99ZljQ/bii77fDu bdxyOj4sEVavZfL8/Q32jhR09D7yTmnfWYFrsR3NBZZixx7haZzN8Cq9H9AFzPaift5j GZNsZJ39QVYsldFtwTMrLfx0psvJ9bnTBQEx8WC/g34m8X4r1q1+ZRSc1D2UwsxvzIe6 7+LyJdLTALkAAB8qY9sFP/EmVFAa33m5x66LALcZFnXNOmAzlhcfHdmYxZbDnmYDs0jQ 61dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=6XPpC5iWPkqaZeLnJgI3weALZbBUAEPVHmKrFmfIhV4=; b=R2B9ANb1QfGKxtUghfZ3jef+DOQtMPaPCtv7WJl/AkaFcaA2dguggEfcL6AKc+2tjV jmQrpm7QsVtZWpkmJ01gSjFYoVoVIZ0iqn/rZ8ggG1uqLc48s01GBIBWnxAbxE6bDkRk 4CWCCFDt1UEuxaGEXIsRGMaAPDG+FEXwpm8rTd430Yh08Xaw4Ce9rV8uAtERKlZRM55t ttPP1HR09YxEP3gEOI7Z8eWCdS9egKrmcOplquszPNdH+7TxmaJBejFrw6AAbJzGgq69 nHa8jMtksf4ffNl7HCDRAiCvMf6TzamEX9Sa26jQdn3qBvFbWMyFe1uEOjcym+07sxLK JIrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=goNRaFYm; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p92si9404912edd.367.2021.01.31.04.42.44; Sun, 31 Jan 2021 04:43:21 -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=@google.com header.s=20161025 header.b=goNRaFYm; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231526AbhAaLk2 (ORCPT + 99 others); Sun, 31 Jan 2021 06:40:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230438AbhAaKGQ (ORCPT ); Sun, 31 Jan 2021 05:06:16 -0500 Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2634DC061574 for ; Sun, 31 Jan 2021 02:05:36 -0800 (PST) Received: by mail-qt1-x834.google.com with SMTP id o18so10079692qtp.10 for ; Sun, 31 Jan 2021 02:05:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6XPpC5iWPkqaZeLnJgI3weALZbBUAEPVHmKrFmfIhV4=; b=goNRaFYmTaG8BUEpJjI5+D7VkeSS8Vw3WCidmfh7z5F69eEYlCKPWjUYHKSNv4LlXW aA2wsdAZdn9Sn2JGUVVGTU1c2msJ9juf4It0P+1DcEF0Mh3MGD3mlp50tKxp3iZ0uL/z jmveZhNa4lNCDoakWYshbC2J/EpSiqo70LqMu5Fg6DOLLRcu83ookO0uLUlAasEfSKCm +ba3ahzhHF/IqcVnkG+BHkxjKv1fPtUGwLoUr91HM6N2pRJQgfcMHnu5xR0TBFf4uZZj 7iJTQKy48bkQfOcHJqGeTqA4rosGZkxoKQm4X4cXagGcZaIyK3lS6cptn3beUVZge2Mq PLHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6XPpC5iWPkqaZeLnJgI3weALZbBUAEPVHmKrFmfIhV4=; b=lS9jo55i56Rcc19AGObXnJi9UdM0BF1u/gYrMh+WWq0c5YS0jX0YqDyuMTzuxXoI1t QfsAS/ZJmYY+Li9lt+NV+ASBJRmNYMmU/l7ZM03aMuKifbBUMBd1L20RNPmupsdkykQd 9h0ohfClLIDJ6Q3/VmaErw8ARausb0mHg+YvyLRTvVghkbjv+8wRJPH+BPGyI1OHXeQh SBQHpSC0M0xiAsS09TSCS4oX5ZZ0nw7WvncZEBz11iCWAyPChA/Z7SmW+Quwhg/DVC1r mKsVcZG+kFoSdJ8R7vkyoJkLJT2jaZ0hP38A8iyn3Ipt9vxyVjYT6sIRHJY+H2W/Lec6 ecjw== X-Gm-Message-State: AOAM532zqgpvDVEui0jHAVN4miUv+0APPGz+oJQM5LbthOiiIdH6Pqip rFvGHp212GmpgmYFh3eH9EE8MScUl5su7jG8QriG+hG58CqFUA== X-Received: by 2002:a37:2716:: with SMTP id n22mr11570565qkn.265.1612087224408; Sun, 31 Jan 2021 02:00:24 -0800 (PST) MIME-Version: 1.0 References: <20210129173105.22020-1-alex@ghiti.fr> In-Reply-To: <20210129173105.22020-1-alex@ghiti.fr> From: Dmitry Vyukov Date: Sun, 31 Jan 2021 11:00:12 +0100 Message-ID: Subject: Re: [PATCH] riscv: virt_addr_valid must check the address belongs to linear mapping To: Alexandre Ghiti Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 29, 2021 at 6:31 PM Alexandre Ghiti wrote: > > 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. Thanks, Alexandre. Much appreciated. > 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 >