Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3542634pxb; Mon, 24 Jan 2022 11:49:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJhTRD/etDTZFXVzygWbJF7xEx1Yw48MvNLzBikEpGyY67ff8QUSoOWMLaffdUpZJ1o0fV X-Received: by 2002:a63:f962:: with SMTP id q34mr7224527pgk.86.1643053788045; Mon, 24 Jan 2022 11:49:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643053788; cv=none; d=google.com; s=arc-20160816; b=NCYZWSx411+eDnkVzYw/dCFhUSzuwVUgPxnRfmSMZqLwjXoSxLCIoHSrql4D9eZMe0 8YGQb3RedcWoPmmYHoLD3AgbhEhRe3mC+A74zVTvDwr7V/vKhkkVs4td+akqNejeHFc/ fhAZXUuno2pS8FzHsgR/6aFWlicvRYHc2lSRCMHyDFQ6HP9cRUDVfSB5/qniV1M2KZjg HFHQR1e6EyAwUpDO841OFrn4dWfSCDzJ3pabaeXHi6yt4bYYxqoVGZCwQJjco25LinHO q6SxXfWifRXAEIgl+y77VjMsHnoz6HCHTZsabI9UfnkiniyfM1fRXJ/k4yCK0XNCttU2 zOvw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EP4tI+Rouw15xYzxaTB6yeKX8++pBPS4+JzWpz9l86E=; b=dt+MH6FJZ+jQfWaTjojJALgynHI2FzsQjBtEF6usNl1DOZaKaG8+gi+oAell/wx9wz Ua9TiK929s1hwH1m/3TBF0ociekqLHUBD5tZ3wwHr0Hnt70biSH+73XgOX1H03i2BvVK 7mhQzXe7ZjaISEqXYxkKNJVc3R4uihRrSZD+Vw/6e8pTE/VAVLb0/70wfXhGz305CeGA jH8XfagS6ro8OrDguGzbPjVv3mJqrncAYt4ORiOCE4+fyNghVjTn7O11EllAshVc2x2p uVt0auL4C7XasA3ipZrnkY+Mm8aY3iWu26uzMcnYv6KzxN9AKKatfoIJxR/x6Pc5d1LS 3Rog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=urMo9kR2; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bo7si227758pjb.54.2022.01.24.11.49.35; Mon, 24 Jan 2022 11:49:48 -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=@linux.dev header.s=key1 header.b=urMo9kR2; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245055AbiAXSG2 (ORCPT + 99 others); Mon, 24 Jan 2022 13:06:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245006AbiAXSGY (ORCPT ); Mon, 24 Jan 2022 13:06:24 -0500 Received: from out0.migadu.com (out0.migadu.com [IPv6:2001:41d0:2:267::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D0A8C06173B for ; Mon, 24 Jan 2022 10:06:24 -0800 (PST) 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=1643047582; 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=EP4tI+Rouw15xYzxaTB6yeKX8++pBPS4+JzWpz9l86E=; b=urMo9kR2/OaUAzrXCyCRxF1GiQSN2C8+PM+wk13aeeDAIN+SjiV+pGVOej2R7oSbLpzLpE +LNS0YyMcwSPDvzfR28Hnd9TluQ4o6ClvB8+IUBZ/jCaKjZOiIf0HuBK/sHJTsvcjd+xFl 7fzeyqRxoOABNT0oVg7o3MtdOdE+CVQ= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , 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 v6 25/39] kasan, vmalloc, arm64: mark vmalloc mappings as pgprot_tagged Date: Mon, 24 Jan 2022 19:04:59 +0100 Message-Id: <983fc33542db2f6b1e77b34ca23448d4640bbb9e.1643047180.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: 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 v3->v4: - Rename arch_vmalloc_pgprot_modify() to arch_vmap_pgprot_tagged() to be consistent with other arch vmalloc hooks. - Move checks from arch_vmap_pgprot_tagged() to __vmalloc_node_range() as the same condition is used for other things in subsequent patches. Changes v2->v3: - Update patch description. --- arch/arm64/include/asm/vmalloc.h | 6 ++++++ include/linux/vmalloc.h | 7 +++++++ mm/vmalloc.c | 9 +++++++++ 3 files changed, 22 insertions(+) diff --git a/arch/arm64/include/asm/vmalloc.h b/arch/arm64/include/asm/vmalloc.h index b9185503feae..38fafffe699f 100644 --- a/arch/arm64/include/asm/vmalloc.h +++ b/arch/arm64/include/asm/vmalloc.h @@ -25,4 +25,10 @@ static inline bool arch_vmap_pmd_supported(pgprot_t prot) #endif +#define arch_vmap_pgprot_tagged arch_vmap_pgprot_tagged +static inline pgprot_t arch_vmap_pgprot_tagged(pgprot_t prot) +{ + return pgprot_tagged(prot); +} + #endif /* _ASM_ARM64_VMALLOC_H */ diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 87f8cfec50a0..7b879c77bec5 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_vmap_pgprot_tagged +static inline pgprot_t arch_vmap_pgprot_tagged(pgprot_t prot) +{ + return prot; +} +#endif + /* * Highlevel APIs for driver use */ diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 15e1a4fdfe0b..92e635b7490c 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3108,6 +3108,15 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, goto fail; } + /* + * Modify protection bits to allow tagging. + * This must be done before mapping by __vmalloc_area_node(). + */ + if (kasan_hw_tags_enabled() && + pgprot_val(prot) == pgprot_val(PAGE_KERNEL)) + prot = arch_vmap_pgprot_tagged(prot); + + /* Allocate physical pages and map them into vmalloc space. */ addr = __vmalloc_area_node(area, gfp_mask, prot, shift, node); if (!addr) goto fail; -- 2.25.1