From patchwork Mon Sep 5 12:24:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12966065 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 4EAC6ECAAD3 for ; Mon, 5 Sep 2022 12:26:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DAA9D8D0089; Mon, 5 Sep 2022 08:26:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D59298D0076; Mon, 5 Sep 2022 08:26:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAC6C8D0089; Mon, 5 Sep 2022 08:26:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AB15B8D0076 for ; Mon, 5 Sep 2022 08:26:32 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 88BF414035D for ; Mon, 5 Sep 2022 12:26:32 +0000 (UTC) X-FDA: 79877955024.12.16FFEDD Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf15.hostedemail.com (Postfix) with ESMTP id 422F9A0062 for ; Mon, 5 Sep 2022 12:26:32 +0000 (UTC) Received: by mail-wm1-f73.google.com with SMTP id a17-20020a05600c349100b003a545125f6eso7401211wmq.4 for ; Mon, 05 Sep 2022 05:26:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=VswCSWA+rV4PC5eDv8SsttMbBbTb1fmAEKvfw1RwEtM=; b=FaysfHPUHEI9xDQ+DizkafuJSz2Euxr4w8pch7JyeIF7w+mm9SpixN7VAttRnhIcf1 iHLsEV9jw/pLNwUY4C8KGw1A06689EYkbOQFe18iHyK1OO4vYcFXMfZ5ltlCGAVJ5Riu XG1siZwi0o/mlCR+V64/HPoH407x/VrsCnkDyjBQzBqc2hGL0yRU8s5mEz8P1N59BhTg hzG3VGefRSfd/eN++lt3E3Gg+z8Tl5riHtwzfLnKb+uWX3YCISAS21Fwh0ERlJq81TyF KZxD8W4yBHXpc4Lq6Y1MBvt4ESwZqiGITUw1+GV0SilDaebvQNF1YZTejeneVonkFaZs QPng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=VswCSWA+rV4PC5eDv8SsttMbBbTb1fmAEKvfw1RwEtM=; b=h6Xu0yIw2urB0QI+p9cE/wo0SJ0TDiKGYbvfSJv5waXeM8JMlIEBExt3Q7j/Te9kpr eB+ZF7U76//2K201hYf6m+3aGTwXFLeGkQh1CdXlitoGZr4iGuCNIm25UoI06caJKTh+ xnwDh3k1TFLdhll4OAw+SX4yWF47ksEuxasxe8txCJ/f8OTwOtXacp/MSULkF7t7QTrO u05wuVaMaIMXpng6TXx7Jal7fcOLryuSwBJOVEy/U0eIxvseY2R6XJVPCDgzAFqDtU8m 6Wu0KS6H7nM7RrfgRw73dHXRUB5ZwxrfpJg5jyxWyG+PkiKTPrs35NhDb5V/6M3uyF9w xEnw== X-Gm-Message-State: ACgBeo0rtmZrYhtqD4npC/V6NUJLQcYA87VKlmRh58jnHwZYjE6ZLvL0 /DiUp2TJJY4kphb7uNLAqk0MjDDla/8= X-Google-Smtp-Source: AA6agR4gbeELzWeJ61Je42r5xKh3pLfxGhHrG+p/6kCfXsLn7Q35sPMS2Mz+9NAgIsEblPfRPD+7AHIMdIQ= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:b808:8d07:ab4a:554c]) (user=glider job=sendgmr) by 2002:a5d:4448:0:b0:226:82ff:f3e6 with SMTP id x8-20020a5d4448000000b0022682fff3e6mr25180706wrr.115.1662380790918; Mon, 05 Sep 2022 05:26:30 -0700 (PDT) Date: Mon, 5 Sep 2022 14:24:42 +0200 In-Reply-To: <20220905122452.2258262-1-glider@google.com> Mime-Version: 1.0 References: <20220905122452.2258262-1-glider@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220905122452.2258262-35-glider@google.com> Subject: [PATCH v6 34/44] 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=1662380792; a=rsa-sha256; cv=none; b=vFMpRgj9xGJB1L1adGnApIRkTCBNUlX9b8kAfRGeQ4dDxJqbCpHH3WlwJWTMtZV5ptYY+M QPrDLUyNTmBaRYaIAypadmSmIT+jLnMqWo/b0zvQ56VgqC4N2P2rUyG5a3mvuC+KPo8doe ldPfw8lPJ0BUbSMfPMCtL0oPavj4I6w= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FaysfHPU; spf=pass (imf15.hostedemail.com: domain of 39uoVYwYKCEMlqnijwlttlqj.htrqnsz2-rrp0fhp.twl@flex--glider.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=39uoVYwYKCEMlqnijwlttlqj.htrqnsz2-rrp0fhp.twl@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662380792; 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=VswCSWA+rV4PC5eDv8SsttMbBbTb1fmAEKvfw1RwEtM=; b=JCZa3JZyaCvbEw1zuZWzJMWi74OzVjwzUUrvHVcb64rbJirmiZZIhFVn73R0zk3noCCy3u bZYEue6WGlTKrBIL1BsAik3vTAsDWZOTLuTubYCR0mHMdHCwGzNSjYqzF6DlQB4LRIAxFs o2s1XdEzG8sgywKi09GzUYWJ43puTb4= Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FaysfHPU; spf=pass (imf15.hostedemail.com: domain of 39uoVYwYKCEMlqnijwlttlqj.htrqnsz2-rrp0fhp.twl@flex--glider.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=39uoVYwYKCEMlqnijwlttlqj.htrqnsz2-rrp0fhp.twl@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam01 X-Rspam-User: X-Stat-Signature: qey4y9to4jbgtg7gm1k78dxim36xppbx X-Rspamd-Queue-Id: 422F9A0062 X-HE-Tag: 1662380792-125969 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 --- 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. v5: -- 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) {