From patchwork Fri Jul 1 14:22:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12903391 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 C6346C433EF for ; Fri, 1 Jul 2022 14:24:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 620886B007D; Fri, 1 Jul 2022 10:24:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D0686B0082; Fri, 1 Jul 2022 10:24:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44AE06B0088; Fri, 1 Jul 2022 10:24:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 322866B007D for ; Fri, 1 Jul 2022 10:24:52 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 091AB60AF6 for ; Fri, 1 Jul 2022 14:24:52 +0000 (UTC) X-FDA: 79638752424.30.FB5CCC1 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) by imf07.hostedemail.com (Postfix) with ESMTP id A4E7B40052 for ; Fri, 1 Jul 2022 14:24:51 +0000 (UTC) Received: by mail-ej1-f73.google.com with SMTP id hq41-20020a1709073f2900b00722e5ad076cso854405ejc.20 for ; Fri, 01 Jul 2022 07:24:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=J/zoX+mhuBfgzG0v9rZx6dvFzp5UyG4GyQqVH6m9IHs=; b=ReTKlob9Qp/FLxAV1DvlHkuUYXTYWPxzPkj5a7irIhWUye1sNVXC5MtER1Ls2z92mp 8Wo25eNrT33XToY0e8nz5feDu3mHb7QFF4VgDm2uDBb8l81TfyIVkddhJcjSsD9ufnM1 Rv9mKSVb0IZG3XVbqV42jTmV3T2Pq2cwTiXOWbvBXBTxw7dePWe5s9bn8qm8wQ8Lt42Z FJrd9KclhBhbHdq39ThpfJZtYbwUVP4vwFJvGlzf7CSyuOSqxyBQ2Qn2zplQeikVadq4 zV+wZJlGCyvmNqBwk6OsqxzwzJFz8qkWXt5LmJX5amCREhfg4UTcaupAIQUr4KVgADMB h0og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=J/zoX+mhuBfgzG0v9rZx6dvFzp5UyG4GyQqVH6m9IHs=; b=qmcEXCzNTKj5owOHQI73Co0ufwZVrpvkzli2DvngWL5dlsaFsgdqIzdP3BumSM9nJ0 KDUSJOWb1u9NFcgPt85o78BVX4flFtfHDFiW7Ec1bBBr8ZXcpoivcHKkrHLQpdc21YtH +XM+Ddocvm60+9qyxh09Q2wc+LVgduYK7UfEoetv/OlalL3yUl+MjhBYbcROzdk78mqt L+I9/PFUgmkb4qByLDyFgEydtG5jNPUqEti2W0ZR7TiK1wQgYtoDofDq/ofbhGGhihRO uxzPmQWnnnLBtrYtyeHT3kBNOqqBUi1dURId6URp/8TXjsRLc7K7nbJk8vYiTwOvAlew OXjQ== X-Gm-Message-State: AJIora+3LWkfiUGSiFJRSanzb2XzhqTtPvd0GzB973WoDn/0HVm+lBzi Ho6b6JdZhaUufZLQPYaY3JiJOV/YBws= X-Google-Smtp-Source: AGRyM1txu7w54o9DaeQXovmZ5qxDTEHTCqPpNip+hr7dMrgvfv9CAiY8ULpNYkP1mTZY+VlfmYuBRFUAtEM= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:a6f5:f713:759c:abb6]) (user=glider job=sendgmr) by 2002:a17:907:a05c:b0:72a:3959:43db with SMTP id gz28-20020a170907a05c00b0072a395943dbmr13506354ejc.359.1656685490466; Fri, 01 Jul 2022 07:24:50 -0700 (PDT) Date: Fri, 1 Jul 2022 16:22:59 +0200 In-Reply-To: <20220701142310.2188015-1-glider@google.com> Message-Id: <20220701142310.2188015-35-glider@google.com> Mime-Version: 1.0 References: <20220701142310.2188015-1-glider@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 34/45] x86: kmsan: skip shadow checks in __switch_to() From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , Alexei Starovoitov , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Mark Rutland , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656685491; a=rsa-sha256; cv=none; b=jA9F96RE3t0bvyI+2CbiEJOhhpFzPvaIinyjbNsZPOShu6tODn4U+P4Ku5qB+FqJNRwgvm 9OnVj+cPYwDowviwX9NVD5CZIN/lItdQPM1SQnnF3mD2ZyilpF80whn7Sd7eeUrY0qbWCe pt27ovlsNqDNdjbrzUpxQqo22tlKSWU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ReTKlob9; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 3sgO_YgYKCNE38501E3BB381.zB985AHK-997Ixz7.BE3@flex--glider.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=3sgO_YgYKCNE38501E3BB381.zB985AHK-997Ixz7.BE3@flex--glider.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656685491; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=J/zoX+mhuBfgzG0v9rZx6dvFzp5UyG4GyQqVH6m9IHs=; b=x4kJ1c4gm314IulI5OSM+Hhq6Di8y5B6VMwqJ9qHsiWosTYOlRDLZLY+QgzZNqomBxxEUB ShVOhF80oOl2pKzcMXzgwmuUN9+25Oj42UUlo4Fh4wfelFO3je96JgTBsDWPsHSSpsCgmx b1wHFZ6lM3f+vvvza1RkIRxqC4gxdgw= X-Stat-Signature: cgyg7ouq3ftykgrmn93hn1sswzb1tiza X-Rspamd-Queue-Id: A4E7B40052 Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ReTKlob9; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 3sgO_YgYKCNE38501E3BB381.zB985AHK-997Ixz7.BE3@flex--glider.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=3sgO_YgYKCNE38501E3BB381.zB985AHK-997Ixz7.BE3@flex--glider.bounces.google.com X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1656685491-83313 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: When instrumenting functions, KMSAN obtains the per-task state (mostly pointers to metadata for function arguments and return values) once per function at its beginning, using the `current` pointer. Every time the instrumented function calls another function, this state (`struct kmsan_context_state`) is updated with shadow/origin data of the passed and returned values. When `current` changes in the low-level arch code, instrumented code can not notice that, and will still refer to the old state, possibly corrupting it or using stale data. This may result in false positive reports. To deal with that, we need to apply __no_kmsan_checks to the functions performing context switching - this will result in skipping all KMSAN shadow checks and marking newly created values as initialized, preventing all false positive reports in those functions. False negatives are still possible, but we expect them to be rare and impersistent. Suggested-by: Marco Elver Signed-off-by: Alexander Potapenko Link: https://linux-review.googlesource.com/id/Ib7d4d70946f08128ade207519c1ee405fd812839 --- v2: -- This patch was previously called "kmsan: skip shadow checks in files doing context switches". Per Mark Rutland's suggestion, we now only skip checks in low-level arch-specific code, as context switches in common code should be invisible to KMSAN. We also apply the checks to precisely the functions performing the context switch instead of the whole file. v4: -- Replace KMSAN_ENABLE_CHECKS_process_64.o with __no_kmsan_checks Link: https://linux-review.googlesource.com/id/I45e3ed9c5f66ee79b0409d1673d66ae419029bcb --- arch/x86/kernel/process_64.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 1962008fe7437..6b3418bff3261 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -553,6 +553,7 @@ void compat_start_thread(struct pt_regs *regs, u32 new_ip, u32 new_sp, bool x32) * Kprobes not supported here. Set the probe on schedule instead. * Function graph tracer not supported too. */ +__no_kmsan_checks __visible __notrace_funcgraph struct task_struct * __switch_to(struct task_struct *prev_p, struct task_struct *next_p) {