Received: by 2002:ac2:5a04:0:0:0:0:0 with SMTP id q4csp372061lfn; Wed, 2 Mar 2022 09:02:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzc+70CM2ImU8dtQfqgLmpi5mgTJruIYzXg5ggiwCB3iW4lycJGFvTo+5zXhywQSZgKvJC+ X-Received: by 2002:a17:907:1611:b0:6da:81d0:89d3 with SMTP id hb17-20020a170907161100b006da81d089d3mr1128782ejc.306.1646240566309; Wed, 02 Mar 2022 09:02:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646240566; cv=none; d=google.com; s=arc-20160816; b=b34hYaZzdOp84mKPBByChfuCQBx+hPWol0A48VY8eI87F+IQPCJPXO1gszoK3M+7mH R4+cyVp3n4xrtCPH1q6gw0rjbhgB9z6hd1tciXdVLHiCHmBqI65mOGb85htk4AC2NJpP WISJUwYz6QEnnyqm7EhfPYfoIWKSilccgvum6GomI8fGWZ8iYEFxChP5MJCaacE3p6po gLqJJUfFraA/Ni0ft+M71Q7tyHg4r6/pqDuu4g61JnMFP/FEmagUNxbgpiDXAHn7dc/S b9U3+xV8Den2lcpRk2hiB4W1cDSfOEahZ9NhzilYQCsgKlBRbC/57KtNC/Cg3SqMNqrR Coaw== 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=j3qLOT6ZMaAmt2b0mGfPQFqvAJBBG++PkHqA3Cl101c=; b=QMY+NbwWymoxN0aCKvlGHeTDvPHhaNHqf8oSt0OZtM8A8m/XHMKmZLzJloeCejojl4 q/RuFZMh1gkSnDuump69PUJVFvSlnmkQzCvv1dhdEodlgLDeaL1PIsFkeYKl6qLhzOt3 7hruu5B21klBQ0v6jkZjTzwPzh1ucVRN6MZ4cGvaQMBeg6l7THxn2tdB7+X3j84C66aP N3lZQNL/1LkrWZuQmoqrx+Hf8hKmfk1EDT/72uee5ggYQTnTNbJZisDCILKYF6NAcKNc ipj/c5RflR3yRDa5768nl8Upqn03fQ/IzqQLPRbxUtdknaDsNBm2qQGe+fhpnwyVM2RD /6zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=CSGzfx3o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r12-20020a170906704c00b006cfffe0553bsi9810143ejj.173.2022.03.02.09.02.22; Wed, 02 Mar 2022 09:02:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=CSGzfx3o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S243411AbiCBPO1 (ORCPT + 99 others); Wed, 2 Mar 2022 10:14:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243406AbiCBPOZ (ORCPT ); Wed, 2 Mar 2022 10:14:25 -0500 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D24279C79 for ; Wed, 2 Mar 2022 07:13:42 -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=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 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) -- 2.25.1