From patchwork Mon Dec 13 21:54:18 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: 12674675 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 B9AB3C433EF for ; Mon, 13 Dec 2021 22:04:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 767336B009A; Mon, 13 Dec 2021 16:54:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7176A6B0088; Mon, 13 Dec 2021 16:54:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B8BA6B009A; Mon, 13 Dec 2021 16:54:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay034.a.hostedemail.com [64.99.140.34]) by kanga.kvack.org (Postfix) with ESMTP id 4DA426B0074 for ; Mon, 13 Dec 2021 16:54:48 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0919020412 for ; Mon, 13 Dec 2021 21:54:38 +0000 (UTC) X-FDA: 78914125836.02.539EAA1 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by imf22.hostedemail.com (Postfix) with ESMTP id 49CE2C0011 for ; Mon, 13 Dec 2021 21:54:36 +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=1639432476; 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=IMzV1X5Nd86e4oY4hBFTxC35nepZUwTPpD8+HwJgmqo=; b=udatEMOwk5I3nWvaD5ENT7vRiUqEyQkL/DfK/zBcriZ9wlQF9FOmWKvt13GARWO4Rk5Eqp 3mNhKVcYTU8GR0gPh1QA7psqKuUvElQkZ+FNvHMtgGt+5+HwjGFmaA13fJTmcJw3Q8tr8j 3U724pXY8+/BLDAXWHfk+1rd/rfuXdI= 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 22/38] kasan, fork: reset pointer tags of vmapped stacks Date: Mon, 13 Dec 2021 22:54:18 +0100 Message-Id: <4f7e671a95dd4b2cc1b9188da0da23302a94f6a7.1639432170.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: andrey.konovalov@linux.dev X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 49CE2C0011 X-Stat-Signature: zmmi4whjibdsgx9fgxizm6qjicyacws5 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=udatEMOw; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf22.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev X-HE-Tag: 1639432476-618475 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 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 alloc_thread_stack_node(). 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 --- Changes v2->v3: - Update patch description. --- kernel/fork.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/fork.c b/kernel/fork.c index 2993a0058f9b..9e488921424e 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -253,6 +253,7 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node) * so cache the vm_struct. */ if (stack) { + stack = kasan_reset_tag(stack); tsk->stack_vm_area = find_vm_area(stack); tsk->stack = stack; }