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 AE023C433FE for ; Mon, 6 Dec 2021 21:46:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353157AbhLFVtx (ORCPT ); Mon, 6 Dec 2021 16:49:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352983AbhLFVtn (ORCPT ); Mon, 6 Dec 2021 16:49:43 -0500 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D910C061359 for ; Mon, 6 Dec 2021 13:46:14 -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=1638827172; 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=nHVI23+3UF63ZVUN3WDdsPua2nJbVrQ0CU8a80/ebmM=; b=ujYKIeajFpP/PIrY0lYCB4MCZN3i1pSExHZJXIcrpXgbnsJzMD4EgICHob7YlR6kne7Tiz gbfuUVKVkF9Q1Cy4b9XwYxyjRHGj4uvef0TupKTFXNk0N5EnuAzM6PwXz1nXkBVCiiv3mg UwHPb9ND+kz9nrNsKy7uzIxwP7b++e0= 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 , Mark Rutland , linux-arm-kernel@lists.infradead.org, Evgenii Stepanov , linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 22/34] kasan, fork: don't tag stacks allocated with vmalloc Date: Mon, 6 Dec 2021 22:43:59 +0100 Message-Id: <92424a5bd4ceaabe6412da558624f2340d107756.1638825394.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 will start getting tagged if CONFIG_VMAP_STACK is enabled. Reset the tag of kernel stack pointers after allocation. 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 pointer 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 --- kernel/fork.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/fork.c b/kernel/fork.c index 3244cc56b697..062d1484ef42 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; } -- 2.25.1