From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE2F7C433F5 for ; Mon, 20 Dec 2021 21:38:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 630916B0071; Mon, 20 Dec 2021 16:38:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5DFF56B0073; Mon, 20 Dec 2021 16:38:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A8096B0074; Mon, 20 Dec 2021 16:38:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0182.hostedemail.com [216.40.44.182]) by kanga.kvack.org (Postfix) with ESMTP id 3AF756B0071 for ; Mon, 20 Dec 2021 16:38:56 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id EC910181AC9CC for ; Mon, 20 Dec 2021 21:38:55 +0000 (UTC) X-FDA: 78939487830.30.E9AC192 Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) by imf28.hostedemail.com (Postfix) with ESMTP id 96C6CC0030 for ; Mon, 20 Dec 2021 21:38:55 +0000 (UTC) Received: by mail-io1-f45.google.com with SMTP id x6so14971184iol.13 for ; Mon, 20 Dec 2021 13:38:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jXmZ+qTH7fz9THsh6sRW8Beptw0SkxxLv33cz0RQxd4=; b=UTnVYe+GGThhIyDprEn2wZxqDP8Z8xBG/uLPp6XFIAwW/suw6+1ow5LRtu+Pg6xcDT 0ZriIG8pD3L6q8OKmD3XhK08zCmLCxXwzPDTZjEaebPrXyHNRYYIQ5F1vp92FdEPkX0O qTuHVrqJTWm/flACUWoG8zNAYX/DH01bPhEF3R+1SC7TlqiqOlYgzPqlsa7+MuJsxlVW /b5vlapxs8iLpdFEIbwyZ5vKAla5BG74+5wq85yBVU9VNbZlqGU/9oHc5vuZqDD2JObC q1SCUCRdxBP3SCOSn85B5ga/PZeW2zYhlzCQ/HEoT3tbFNayjSvgFCTE6aLKJ24oA39l 7EAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jXmZ+qTH7fz9THsh6sRW8Beptw0SkxxLv33cz0RQxd4=; b=F2EhoxiupYvYNxC5on8ClFGaEV6bgmXVHvMaIMdui2bBtJ0F7hTDPtlqnxkob9tDBC zMYoa8ml4Uk3XOaWrYBVbhY5UmyCtm4BOra2zRrIWVM5CgtQj8kP27yUta2Q1ndobkmq E1vrtfol4RaYqJvQfQFf7dU+R2Vsplx//fFPTPBWFpZY1Ot4+pg8ercaK+vRak6+S57S ki3t8xHnPlhCT8vprJeYaFGuUhm56cmCwn4zFDPvFPQ6vhiD3KxMeIBa/aJVotqTCjs+ 2dcMrlLQJ4RS0fTcJQeULfzbfkZpYUojxtWoS52Nekjb+obI7sQCfnaFms/HcO5TN3FW Tfvg== X-Gm-Message-State: AOAM530CXJViy6tg9Hg/vuNoWDb6ZJi2htI5O6r41trie2qKicFmVeJw dVgBHETi/z0z8sqqU6JIgzzxqbSH2deglZporCw= X-Google-Smtp-Source: ABdhPJxeyUmnDdbXsgknOTn/FLvRFgBHRyYMqPetQbqBWRZhXny15fWy7BL16oR/ZDRe+WVEIdyrjNidsqhGx2LWSXg= X-Received: by 2002:a05:6638:2512:: with SMTP id v18mr104863jat.22.1640036334760; Mon, 20 Dec 2021 13:38:54 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Andrey Konovalov Date: Mon, 20 Dec 2021 22:38:43 +0100 Message-ID: Subject: Re: [PATCH mm v3 25/38] kasan, vmalloc, arm64: mark vmalloc mappings as pgprot_tagged To: Catalin Marinas Cc: andrey.konovalov@linux.dev, Marco Elver , Alexander Potapenko , Andrew Morton , Dmitry Vyukov , Andrey Ryabinin , kasan-dev , Linux Memory Management List , Vincenzo Frascino , Will Deacon , Mark Rutland , Linux ARM , Peter Collingbourne , Evgenii Stepanov , LKML , Andrey Konovalov Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=UTnVYe+G; spf=pass (imf28.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.166.45 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Queue-Id: 96C6CC0030 X-Stat-Signature: uh1d7tkm4d6hgza8bjkuoppnhbwk8kf5 X-Rspamd-Server: rspam04 X-HE-Tag: 1640036335-731762 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Dec 14, 2021 at 8:27 PM Catalin Marinas wrote: > > On Tue, Dec 14, 2021 at 07:27:09PM +0100, Andrey Konovalov wrote: > > On Tue, Dec 14, 2021 at 6:11 PM Catalin Marinas wrote: > > > On Mon, Dec 13, 2021 at 10:54:21PM +0100, andrey.konovalov@linux.dev wrote: > > > > diff --git a/arch/arm64/include/asm/vmalloc.h b/arch/arm64/include/asm/vmalloc.h > > > > index b9185503feae..3d35adf365bf 100644 > > > > --- a/arch/arm64/include/asm/vmalloc.h > > > > +++ b/arch/arm64/include/asm/vmalloc.h > > > > @@ -25,4 +25,14 @@ static inline bool arch_vmap_pmd_supported(pgprot_t prot) > > > > > > > > #endif > > > > > > > > +#define arch_vmalloc_pgprot_modify arch_vmalloc_pgprot_modify > > > > +static inline pgprot_t arch_vmalloc_pgprot_modify(pgprot_t prot) > > > > +{ > > > > + if (IS_ENABLED(CONFIG_KASAN_HW_TAGS) && > > > > + (pgprot_val(prot) == pgprot_val(PAGE_KERNEL))) > > > > + prot = pgprot_tagged(prot); > > > > + > > > > + return prot; > > > > +} > > > > + > > > > #endif /* _ASM_ARM64_VMALLOC_H */ > > > > diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h > > > > index 28becb10d013..760caeedd749 100644 > > > > --- a/include/linux/vmalloc.h > > > > +++ b/include/linux/vmalloc.h > > > > @@ -115,6 +115,13 @@ static inline int arch_vmap_pte_supported_shift(unsigned long size) > > > > } > > > > #endif > > > > > > > > +#ifndef arch_vmalloc_pgprot_modify > > > > +static inline pgprot_t arch_vmalloc_pgprot_modify(pgprot_t prot) > > > > +{ > > > > + return prot; > > > > +} > > > > +#endif > > > > + > > > > /* > > > > * Highlevel APIs for driver use > > > > */ > > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > > > index 837ed355bfc6..58bd2f7f86d7 100644 > > > > --- a/mm/vmalloc.c > > > > +++ b/mm/vmalloc.c > > > > @@ -3060,6 +3060,8 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, > > > > return NULL; > > > > } > > > > > > > > + prot = arch_vmalloc_pgprot_modify(prot); > > > > + > > > > if (vmap_allow_huge && !(vm_flags & VM_NO_HUGE_VMAP)) { > > > > unsigned long size_per_node; > > > > > > I wonder whether we could fix the prot bits in the caller instead and we > > > won't need to worry about the exec or the module_alloc() case. Something > > > like: > > > > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > > index d2a00ad4e1dd..4e8c61255b92 100644 > > > --- a/mm/vmalloc.c > > > +++ b/mm/vmalloc.c > > > @@ -3112,7 +3112,7 @@ void *__vmalloc_node(unsigned long size, unsigned long align, > > > gfp_t gfp_mask, int node, const void *caller) > > > { > > > return __vmalloc_node_range(size, align, VMALLOC_START, VMALLOC_END, > > > - gfp_mask, PAGE_KERNEL, 0, node, caller); > > > + gfp_mask, pgprot_hwasan(PAGE_KERNEL), 0, node, caller); > > > } > > > /* > > > * This is only for performance analysis of vmalloc and stress purpose. > > > @@ -3161,7 +3161,7 @@ EXPORT_SYMBOL(vmalloc); > > > void *vmalloc_no_huge(unsigned long size) > > > { > > > return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END, > > > - GFP_KERNEL, PAGE_KERNEL, VM_NO_HUGE_VMAP, > > > + GFP_KERNEL, pgprot_hwasan(PAGE_KERNEL), VM_NO_HUGE_VMAP, > > > NUMA_NO_NODE, __builtin_return_address(0)); > > > } > > > EXPORT_SYMBOL(vmalloc_no_huge); > > > > > > with pgprot_hwasan() defined to pgprot_tagged() only if KASAN_HW_TAGS is > > > enabled. > > > > And also change kasan_unpoison_vmalloc() to tag only if > > pgprot_tagged() has been applied, I assume. > > > > Hm. Then __vmalloc_node_range() callers will never get tagged memory > > unless requested. I suppose that's OK, most of them untag the pointer > > anyway. > > > > But this won't work for SW_TAGS mode, which is also affected by the > > exec issue and needs those kasan_reset_tag()s in module_alloc()/BPF. > > We could invent some virtual protection bit for it and reuse > > pgprot_hwasan(). Not sure if this would be acceptable. > > Ah, a pgprot_hwasan() for the sw tags is probably not acceptable as this > requires an unnecessary pte bit. An alternative could be a GFP flag that > gets passed only from __vmalloc_node() etc. This will still leave the BPF JIT special case though. So I'm leaning towards keeping my approach. Thanks!