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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFB81C433F5 for ; Mon, 13 Dec 2021 21:54:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243291AbhLMVyt (ORCPT ); Mon, 13 Dec 2021 16:54:49 -0500 Received: from out0.migadu.com ([94.23.1.103]:19827 "EHLO out0.migadu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243279AbhLMVyq (ORCPT ); Mon, 13 Dec 2021 16:54:46 -0500 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=1639432484; 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=yORKjcCEUipyyeqk50NvnNF1FXzG3q2NQ93FJWpnTtQ=; b=EP1GPSuPZzFfSq1N2bShpv41TxC0tCljFweiiBucay4TjTyJUn5sKY7ua0UgdAWd9E27YL zYz93YZ5jjqB2/dRKEDbSvCIJUGQbD+tcQ8cZaP+FxzmgYlABn3uza6s4/P2T10agLk+RU BYhmLrrYfdlA72xAZ/vwH46HCeBk96A= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko , Andrew Morton Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, linux-mm@kvack.org, Vincenzo Frascino , Catalin Marinas , Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org, Peter Collingbourne , Evgenii Stepanov , linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm v3 25/38] kasan, vmalloc, arm64: mark vmalloc mappings as pgprot_tagged Date: Mon, 13 Dec 2021 22:54:21 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: andrey.konovalov@linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Add 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 Signed-off-by: Vincenzo Frascino --- Changes v2->v3: - Update patch description. --- 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 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; -- 2.25.1