From mboxrd@z Thu Jan 1 00:00:00 1970 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 2DE6EECAAA3 for ; Fri, 26 Aug 2022 15:16:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343778AbiHZPQA (ORCPT ); Fri, 26 Aug 2022 11:16:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244200AbiHZPOM (ORCPT ); Fri, 26 Aug 2022 11:14:12 -0400 Received: from mail-ed1-x549.google.com (mail-ed1-x549.google.com [IPv6:2a00:1450:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AF2425C59 for ; Fri, 26 Aug 2022 08:09:57 -0700 (PDT) Received: by mail-ed1-x549.google.com with SMTP id q18-20020a056402519200b0043dd2ff50feso1233166edd.9 for ; Fri, 26 Aug 2022 08:09:56 -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; bh=3xJV8lOEjvc/s3Zvuma5zSeTndu+UAUJOaQAKluuQYo=; b=iowtS53RHlpCL6qU/VWV5GQVG1CF6AM2cb2K8UF+xf9Eri/m9bP/5b0fP/Yv5g71u0 G4xosRyjwnbYFvqXAKPuwh/r0w9aoa69XWRuAOHrIhWmWSx0iV2XmDVoCP0JlE47FuAB nmm0HUugDUAGgo/u5XwfJyioj1O9wMPKtRlUGvvX8gKw+EEmNXhvxQbPL/ZKDRcZQQPf MtPg7V/4IJP2t5P4sgZyKRHmwuOCzbI6xunPoBepArW292PT19a5ne9C4DB1Q+Nr1eTB S6mxBrnLUZM9ZZ8fq3aL2JmDi/WAivgNEzeAkYRHzPgQwniErjEHU3w34yBn1hByADXw pmoQ== 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; bh=3xJV8lOEjvc/s3Zvuma5zSeTndu+UAUJOaQAKluuQYo=; b=RM+4WohDlZYthLFgaA+S+Zr+W9qiV4fbsmgZ0JEjtDLU8dWbb9WsPvgo6fGdHmz04h 8gQ9o2u4uuFFbDdu2L6He6LXHCZAg9fir7dV0S3cFviIOxQS4DPwbBnk9yC7Wdb0ZQHl StfoYCCFlw44kkcYz+lPEAt4TjKdwIL/E6+UBSSqvUyk5avE68vPo42CryeMbXEDCt07 /RnXH8S+1mhd7WBUYtxydpOvFUopDtcHiB8PpsMGJMiLGLgHlR+KlHOEcWBL0qnagsN/ g/3dNjOO7O8WEhifYkwvkq/DnRwNDY9snLnxkKaJaX8wStgg1dP23CtiaFMhZbKK7HWq FVtQ== X-Gm-Message-State: ACgBeo1z4IBZWPCNS23svZGVnKhmPJd51z2DNTM9FXGROQ93FLCY4aVW y/wtNP33IA+GU2a36LdBGpwKlnzCjNU= X-Google-Smtp-Source: AA6agR7ZtlC3yezkLYO1v2tXY0fliINor4H6Q3eNUkRHGD2H51HnwKZSVDlZC6/hqKT8jj4k53bs2dn79I8= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:5207:ac36:fdd3:502d]) (user=glider job=sendgmr) by 2002:a05:6402:3491:b0:446:ea7d:8d9c with SMTP id v17-20020a056402349100b00446ea7d8d9cmr7130674edc.184.1661526588030; Fri, 26 Aug 2022 08:09:48 -0700 (PDT) Date: Fri, 26 Aug 2022 17:07:57 +0200 In-Reply-To: <20220826150807.723137-1-glider@google.com> Mime-Version: 1.0 References: <20220826150807.723137-1-glider@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220826150807.723137-35-glider@google.com> Subject: [PATCH v5 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-arch@vger.kernel.org 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/I520c414f52c19f3ea22377a9c570fff0d5943a95 --- 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) { -- 2.37.2.672.g94769d06f0-goog