From patchwork Tue Nov 30 22:07:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 12648283 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 2DCD6C433F5 for ; Tue, 30 Nov 2021 22:12:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 31DF06B0085; Tue, 30 Nov 2021 17:08:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2CC866B0087; Tue, 30 Nov 2021 17:08:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 16DCC6B0088; Tue, 30 Nov 2021 17:08:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0037.hostedemail.com [216.40.44.37]) by kanga.kvack.org (Postfix) with ESMTP id 04C356B0085 for ; Tue, 30 Nov 2021 17:08:12 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B7C2D181D46EE for ; Tue, 30 Nov 2021 22:08:01 +0000 (UTC) X-FDA: 78866985162.05.C4196A8 Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by imf04.hostedemail.com (Postfix) with ESMTP id C584950000B2 for ; Tue, 30 Nov 2021 22:07:54 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1638310079; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kpH+33k/GfROSS5YE3KBLshkOEFVObuKhNsDDFbF7nk=; b=EI9KMQ0FE2Lga3NDzFUbaaJ4h/QgEzQUWHGYegJ9U1GdIRaVRw6aRTZkgZC9HJreyXnPis 44n3p7Z+73FtjBBI40KCmU/QGO5IR2KeRiV4AhMD/4sMp//KWNEUuYQN4V5AEhoJumX3cd qswX90tNF0TxfaZ5a+vJUDUwuoIlXcg= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko , Vincenzo Frascino , Catalin Marinas , Peter Collingbourne Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, Will Deacon , linux-arm-kernel@lists.infradead.org, Evgenii Stepanov , linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 24/31] kasan, vmalloc, arm64: mark vmalloc mappings as pgprot_tagged Date: Tue, 30 Nov 2021 23:07:56 +0100 Message-Id: <8557e32739e38d3cdf409789c2b3e1b405c743f4.1638308023.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C584950000B2 X-Stat-Signature: r91ipiidusky5uqbcdjtgrw4k6s86c1q Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=EI9KMQ0F; spf=pass (imf04.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.121.223.63 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-HE-Tag: 1638310074-791298 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: From: Andrey Konovalov HW_TAGS KASAN relies on ARM Memory Tagging Extension (MTE). With MTE, a memory region must be mapped as MT_NORMAL_TAGGED to allow setting memory tags via MTE-specific instructions. This change adds proper protection bits to vmalloc() allocations. These allocations are always backed by page_alloc pages, so the tags will actually be getting set on the corresponding physical memory. Signed-off-by: Andrey Konovalov Co-developed-by: Vincenzo Frascino --- arch/arm64/include/asm/vmalloc.h | 10 ++++++++++ include/linux/vmalloc.h | 7 +++++++ mm/vmalloc.c | 2 ++ 3 files changed, 19 insertions(+) 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 b22369f540eb..965c4bf475f1 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -108,6 +108,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 7be18b292679..f37d0ed99bf9 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3033,6 +3033,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;