Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3543223pxb; Mon, 24 Jan 2022 11:50:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxoNKKHqa3xLJWhCibgYf+BX/9Daz+3dK+WiIzTjPO1FJJEBYclPmPw/9HuIyjz335hgyve X-Received: by 2002:a63:a84e:: with SMTP id i14mr13085275pgp.159.1643053848166; Mon, 24 Jan 2022 11:50:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643053848; cv=none; d=google.com; s=arc-20160816; b=ihr3UHC1ah11EvuSkD1Xt22UMllWAXINO6YoGjVnLBosWUiyNq94cjRdK6gv3yfDFC SWAp9/HbT+wZ4cQTz0D4/KFKj9vAZ6sRWgus+AftQuvkjXNRIGxkLLDizuwpGe0s6m/a H/2NVWs9TAVjcQymTA3gCfssmvHNArBMtC1HJYP8RcznVINvLYQdzBRPmXZ0lTg6QUYc Jk6IBj9A/RBlH67kgCKG8hbgViHRMpaVts9yRXR67hoAszxoKrgLpqtyCc92yg/AzEIT LdhrO6x1DU9EgXiHwrWDtUsGdLYIMjHaK5tCl8YJ7NDSCSm5Bx6YiimTJQqlmH8aw4PS 606w== 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=zMk+i6psUWRrJkriJ76ixSA3XRodREnil0b2HWyShlc=; b=aBalQMTeZ9IpH+Q9ELI9dOxi8z0R/oeEmuiGPp8pzT+bYhUottPEYt5v7pqFZglz40 Woj8V5M+A7G7J5aPQxgC6YpLb6MIhJz+wLwEqEFJVcCy4xLh88HXGMBBYwVD4tDJ02jY 43nBWyOnIiCG94vkSqsLYRB8zCA5CRgjLaES9NDCMaz7kcFjQ6sKB3PHJ3TvwyKe8IR7 8TNc4iSpXcmyF4ae/Ya5+UShhDFtOJ3Tn4kavlm52DSPRENRjhGsBMOzp1QVxkx3f1sU aj7YQ/OyOB+ruRevdmWoufXyFa6qs0NfGDV26hd3HHAoJKbeJkf1fKCGEzw+eJPd2vg8 B7Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=FjC5A+7G; 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 v13si15258210pgs.284.2022.01.24.11.50.36; Mon, 24 Jan 2022 11:50: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=FjC5A+7G; 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 S244972AbiAXSGW (ORCPT + 99 others); Mon, 24 Jan 2022 13:06:22 -0500 Received: from out0.migadu.com ([94.23.1.103]:18892 "EHLO out0.migadu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244898AbiAXSGW (ORCPT ); Mon, 24 Jan 2022 13:06:22 -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=1643047581; 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=zMk+i6psUWRrJkriJ76ixSA3XRodREnil0b2HWyShlc=; b=FjC5A+7GOe9KRmtrhi7rw0I5N5HCVKX3w1hCOWXf4I7jR6Pn6UIKPNHlUFhhYT8L/eagWa pwxLHDPVZnognMjvDlmwGiVsHmN4ua0xdOYLJlXd3OvwagLo/Pe3kB8Hh9rBfDLQCYkEmW b8/VX1LLWpHd9yC358Y0m2kftgjtuBc= 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 23/39] kasan, arm64: reset pointer tags of vmapped stacks Date: Mon, 24 Jan 2022 19:04:57 +0100 Message-Id: <698c5ab21743c796d46c15d075b9481825973e34.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 Once tag-based KASAN modes start tagging vmalloc() allocations, kernel stacks start getting tagged if CONFIG_VMAP_STACK is enabled. Reset the tag of kernel stack pointers after allocation in arch_alloc_vmap_stack(). For SW_TAGS KASAN, when CONFIG_KASAN_STACK is enabled, the instrumentation can't handle the SP register being tagged. For HW_TAGS KASAN, there's no instrumentation-related issues. However, the impact of having a tagged SP register needs to be properly evaluated, so keep it non-tagged for now. Note, that the memory for the stack allocation still gets tagged to catch vmalloc-into-stack out-of-bounds accesses. Signed-off-by: Andrey Konovalov Acked-by: Catalin Marinas --- Changes v2->v3: - Add this patch. --- arch/arm64/include/asm/vmap_stack.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/vmap_stack.h b/arch/arm64/include/asm/vmap_stack.h index 894e031b28d2..20873099c035 100644 --- a/arch/arm64/include/asm/vmap_stack.h +++ b/arch/arm64/include/asm/vmap_stack.h @@ -17,10 +17,13 @@ */ static inline unsigned long *arch_alloc_vmap_stack(size_t stack_size, int node) { + void *p; + BUILD_BUG_ON(!IS_ENABLED(CONFIG_VMAP_STACK)); - return __vmalloc_node(stack_size, THREAD_ALIGN, THREADINFO_GFP, node, + p = __vmalloc_node(stack_size, THREAD_ALIGN, THREADINFO_GFP, node, __builtin_return_address(0)); + return kasan_reset_tag(p); } #endif /* __ASM_VMAP_STACK_H */ -- 2.25.1