From patchwork Wed Mar 2 15:13:30 2022 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: 12766216 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 E39EBC433F5 for ; Wed, 2 Mar 2022 15:13:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C0358D0002; Wed, 2 Mar 2022 10:13:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 36ED98D0001; Wed, 2 Mar 2022 10:13:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25F878D0002; Wed, 2 Mar 2022 10:13:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 1A1798D0001 for ; Wed, 2 Mar 2022 10:13:40 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E4A4B622CE for ; Wed, 2 Mar 2022 15:13:39 +0000 (UTC) X-FDA: 79199790558.06.3904849 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf05.hostedemail.com (Postfix) with ESMTP id 2DBAF100007 for ; Wed, 2 Mar 2022 15:13:38 +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=1646234017; 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; bh=yvhkHe8ffV7l7JQy8kWEX/L6d0v7GNlMNTEjcsXtnAI=; b=pf//kUiq5UreQmNoe4O7ZsvF78erL2mztEQ2l5rSDlszRje9RmOReAttOq4tgQdKAT0DLl VJwX4JW6HEzyj28mIrTJsP4nryvL+dEeHxdk7CC3Rcy2Azt/Q/zoIAlvtBPdHAEyo+QJA+ YvKCnSEN8ESN95bQJppuNyQ4S6XcJZY= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Will Deacon , Sami Tolvanen , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 1/2] fix for "kasan, vmalloc: only tag normal vmalloc allocations" Date: Wed, 2 Mar 2022 16:13:30 +0100 Message-Id: <9230ca3d3e40ffca041c133a524191fd71969a8d.1646233925.git.andreyknvl@google.com> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 2DBAF100007 X-Stat-Signature: entza1d4s5j3a3f98cqka4d6sm31kh7x Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="pf//kUiq"; spf=pass (imf05.hostedemail.com: domain of andrey.konovalov@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspam-User: X-HE-Tag: 1646234018-757247 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 Pass KASAN_VMALLOC_PROT_NORMAL to kasan_unpoison_vmalloc() in the custom KASAN instrumentation for Shadow Call Stack, as Shadow Call Stack mappings are not executable and thus can be poisoned. Signed-off-by: Andrey Konovalov --- kernel/scs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/scs.c b/kernel/scs.c index b83bc9251f99..1033a76a3284 100644 --- a/kernel/scs.c +++ b/kernel/scs.c @@ -32,7 +32,8 @@ static void *__scs_alloc(int node) for (i = 0; i < NR_CACHED_SCS; i++) { s = this_cpu_xchg(scs_cache[i], NULL); if (s) { - kasan_unpoison_vmalloc(s, SCS_SIZE, KASAN_VMALLOC_NONE); + kasan_unpoison_vmalloc(s, SCS_SIZE, + KASAN_VMALLOC_PROT_NORMAL); memset(s, 0, SCS_SIZE); return s; } @@ -78,7 +79,7 @@ void scs_free(void *s) if (this_cpu_cmpxchg(scs_cache[i], 0, s) == NULL) return; - kasan_unpoison_vmalloc(s, SCS_SIZE, KASAN_VMALLOC_NONE); + kasan_unpoison_vmalloc(s, SCS_SIZE, KASAN_VMALLOC_PROT_NORMAL); vfree_atomic(s); } From patchwork Wed Mar 2 15:13:31 2022 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: 12766217 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 3F1DDC433FE for ; Wed, 2 Mar 2022 15:13:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 917CB8D0003; Wed, 2 Mar 2022 10:13:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C6358D0001; Wed, 2 Mar 2022 10:13:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B7568D0003; Wed, 2 Mar 2022 10:13:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id 6F5AA8D0001 for ; Wed, 2 Mar 2022 10:13:41 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0CB149F5EA for ; Wed, 2 Mar 2022 15:13:41 +0000 (UTC) X-FDA: 79199790642.23.03A3434 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf23.hostedemail.com (Postfix) with ESMTP id 7E1F4140003 for ; Wed, 2 Mar 2022 15:13:40 +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=1646234019; 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=j3qLOT6ZMaAmt2b0mGfPQFqvAJBBG++PkHqA3Cl101c=; b=CSGzfx3omDRUovLYXrhVK8m9urx3lpO3DcOk9bq+9xGjlT+cQYnASWoP6YbsvHSRFuNMRW smrOixVneQODj8G11tW7sOlh84DaazE0fumZw7INvWjG13xijjvbp8/+viKkJ+emwI5Hkk epQ9S8WDLJVnFFr2Nu9SQGAzTTa9xuY= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Will Deacon , Sami Tolvanen , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 2/2] kasan, scs: support tagged vmalloc mappings Date: Wed, 2 Mar 2022 16:13:31 +0100 Message-Id: <2f6605e3a358cf64d73a05710cb3da356886ad29.1646233925.git.andreyknvl@google.com> In-Reply-To: <9230ca3d3e40ffca041c133a524191fd71969a8d.1646233925.git.andreyknvl@google.com> References: <9230ca3d3e40ffca041c133a524191fd71969a8d.1646233925.git.andreyknvl@google.com> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Rspamd-Queue-Id: 7E1F4140003 X-Stat-Signature: wk9suuy4z7ebhi5qtahpthgq4xbiom4u X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=CSGzfx3o; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf23.hostedemail.com: domain of andrey.konovalov@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev X-Rspamd-Server: rspam03 X-HE-Tag: 1646234020-760746 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 Fix up the custom KASAN instrumentation for Shadow Call Stack to support vmalloc() mappings and pointers being tagged. - Use the tagged pointer returned by kasan_unpoison_vmalloc() in __scs_alloc() when calling memset() to avoid false-positives. - Do not return a tagged Shadow Call Stack pointer from __scs_alloc(), as this might lead to conflicts with the instrumentation. Signed-off-by: Andrey Konovalov --- Andrew, please put this patch after "kasan, vmalloc: only tag normal vmalloc allocations". --- kernel/scs.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/scs.c b/kernel/scs.c index 1033a76a3284..b7e1b096d906 100644 --- a/kernel/scs.c +++ b/kernel/scs.c @@ -32,16 +32,19 @@ static void *__scs_alloc(int node) for (i = 0; i < NR_CACHED_SCS; i++) { s = this_cpu_xchg(scs_cache[i], NULL); if (s) { - kasan_unpoison_vmalloc(s, SCS_SIZE, - KASAN_VMALLOC_PROT_NORMAL); + s = kasan_unpoison_vmalloc(s, SCS_SIZE, + KASAN_VMALLOC_PROT_NORMAL); memset(s, 0, SCS_SIZE); - return s; + goto out; } } - return __vmalloc_node_range(SCS_SIZE, 1, VMALLOC_START, VMALLOC_END, + s = __vmalloc_node_range(SCS_SIZE, 1, VMALLOC_START, VMALLOC_END, GFP_SCS, PAGE_KERNEL, 0, node, __builtin_return_address(0)); + +out: + return kasan_reset_tag(s); } void *scs_alloc(int node)