Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1030068iob; Fri, 13 May 2022 20:16:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIsS9KtiD+XKIkoA8Squ6D4QIoiHkGCYsci+iUsTGqsWY12epwRGfe4gHcHaTO3Pp3vE5b X-Received: by 2002:a05:6000:1815:b0:20a:deee:3cf0 with SMTP id m21-20020a056000181500b0020adeee3cf0mr6072604wrh.210.1652498212980; Fri, 13 May 2022 20:16:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652498212; cv=none; d=google.com; s=arc-20160816; b=mrJTe2+lwQjKrWqnggJNYqXWmnYWFdr7Tc9ytB59iTTT7zKIzxE9sfc+PFXqDR3uPv qIJ9UQpo7dW3jvgYcn427+p9RYcEtG39GyTDtI1r0jWO8MYOkWrIJvKN3mtvz8Du5qC6 gZGiA1VmT0nh4lvjL/9oYF62jt3424fKt8qllGzMsMktkGELKfc/GkbcQBtQCy5MQh3k CqvZv5Zf3HYhaX1FlTgcTONkHLd3aJhC9/jFyQwZ5HB7E/G2QnHDop0e+eWKhy91+VTe +ak2XMxZHoMOPWoD9MvwHwSvJYmuGxuLYPt5JD6Qh552fQpioP9xSN7KEIjd6BUBbR0l bpjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=hSX9OFf5tzvIcNgVCMLyCC6NV4cYH+8sLce95997SMQ=; b=0nQGJ4EVaNccpW0eBK+pr1tn6727kxoFuk1/58n7PCAWJwiVMnvNJ8DXtXJeGPXoE+ pL8n1f0n4+1AfQr+BYczfwEyRqVV8DSSBisPRRRV9fYEvTis4m8vDCgV7QResMfGyDmc 6aFWfNwXBRqgRlwwoM8kY2fVSYiAMAFrwSEVuze+2P4WY3okj3gkUIegPL6gzgbFyTjT AnFBwIzy+8EmsN3spYp7OYZQ/uijAcqSNc9wA4tlTxPr9ZcpJ3Gp9KrtVb2Lm1V/CXFZ sJvDVaWYFjOR6KdyIUpXpOlALpw206EZx2NHtXvn05/eZSTuQHQ2ziYdpiIHI1CNeoxw ciyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dNG6zwNh; dkim=neutral (no key) header.i=@linutronix.de header.b=GgB2jaA6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id e9-20020a056000034900b00207b0b61df3si3777260wre.495.2022.05.13.20.16.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 20:16:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dNG6zwNh; dkim=neutral (no key) header.i=@linutronix.de header.b=GgB2jaA6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5ADF63E3717; Fri, 13 May 2022 16:55:26 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235940AbiELQso (ORCPT + 99 others); Thu, 12 May 2022 12:48:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349749AbiELQsl (ORCPT ); Thu, 12 May 2022 12:48:41 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CB612685FE; Thu, 12 May 2022 09:48:40 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1652374118; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hSX9OFf5tzvIcNgVCMLyCC6NV4cYH+8sLce95997SMQ=; b=dNG6zwNhF9OUuVyKVZ3nmgj1iI9P+NOQjZMoo+ixnf6np32nRm7iOb/snaa6Yh6q4H7zJ+ u/uVMdw2BaGy43kBjD4QXWRY/2owMXR0MTVD3dqUi+eXHeHc34KgqYLGnl3/QxFyOGYTle HZYrCTB6AUYKRjzbRCNyEBs7omeeNxAPg9KnUpMODqWp9/+eMR4fQRIj1zXWD1g8VE74BM 5Vbq6Dqdd77zoaSWNBz4yMLNOrkWENhnz8Ajr60VtTgGavBnrDJ/CTm1rDV875uc13LI1x oNnZAD7v9H07fYlGuxRNjNdBhutYsoILILZnN07UAFUmT4BHYP+fTF1VVMY4Dg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1652374118; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hSX9OFf5tzvIcNgVCMLyCC6NV4cYH+8sLce95997SMQ=; b=GgB2jaA6SJpjjCA9C/bYLMwCZArP4xDXp8WFAObc2KO4QJQw2QMoX/09cNKaYH97nQRf1w FOGCByOo9GPjzdBg== To: Alexander Potapenko Cc: Alexander Viro , 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 , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev , Linux Memory Management List , Linux-Arch , LKML Subject: Re: [PATCH v3 28/46] kmsan: entry: handle register passing from uninstrumented code In-Reply-To: <87h75uvi7s.ffs@tglx> References: <20220426164315.625149-1-glider@google.com> <20220426164315.625149-29-glider@google.com> <87a6c6y7mg.ffs@tglx> <87y1zjlhmj.ffs@tglx> <878rrfiqyr.ffs@tglx> <87k0ayhc43.ffs@tglx> <87h762h5c2.ffs@tglx> <871qx2r09k.ffs@tglx> <87h75uvi7s.ffs@tglx> Date: Thu, 12 May 2022 18:48:38 +0200 Message-ID: <87ee0yvgrd.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Thu, May 12 2022 at 18:17, Thomas Gleixner wrote: > On Thu, May 12 2022 at 14:24, Alexander Potapenko wrote: >> We could try to figure out the places in idtentry code where normal >> kmsan_unpoison_memory() can be called in IRQ context, but as far as I >> can see it will depend on the type of the entry point. > > NMI is covered as it increments before it invokes the unpoison(). > > Let me figure out why we increment the preempt count late for > interrupts. IIRC it's for symmetry reasons related to softirq processing > on return, but let me double check. It's even documented: https://www.kernel.org/doc/html/latest/core-api/entry.html#interrupts-and-regular-exceptions But who reads documentation? :) So, I think the simplest and least intrusive solution is to have special purpose unpoison functions. See the patch below for illustration. The reasons why I used specific ones: 1) User entry Whether that's a syscall or interrupt/exception does not matter. It's always on the task stack and your machinery cannot be running at that point because it came from user space. 2) Interrupt/exception/NMI entry kernel Those can nest into an already active context, so you really want to unpoison @regs. Also while regular interrupts cannot nest because of interrupts staying disabled, exceptions triggered in the interrupt handler and NMIs can nest. -> device interrupt() irqentry_enter(regs) -> NMI() irqentry_nmi_enter(regs) -> fault() irqentry_enter(regs) --> debug_exception() irqentry_nmi_enter(regs) Soft interrupt processing on return from interrupt makes it more interesting: interrupt() handler() do_softirq() local_irq_enable() interrupt() NMI .... And everytime you get a new @regs pointer to deal with. Wonderful, isn't it? Thanks, tglx --- --- a/kernel/entry/common.c +++ b/kernel/entry/common.c @@ -24,6 +24,7 @@ static __always_inline void __enter_from user_exit_irqoff(); instrumentation_begin(); + unpoison_user(regs); trace_hardirqs_off_finish(); instrumentation_end(); } @@ -352,6 +353,7 @@ noinstr irqentry_state_t irqentry_enter( lockdep_hardirqs_off(CALLER_ADDR0); rcu_irq_enter(); instrumentation_begin(); + unpoison_irq(regs); trace_hardirqs_off_finish(); instrumentation_end(); @@ -367,6 +369,7 @@ noinstr irqentry_state_t irqentry_enter( */ lockdep_hardirqs_off(CALLER_ADDR0); instrumentation_begin(); + unpoison_irq(regs); rcu_irq_enter_check_tick(); trace_hardirqs_off_finish(); instrumentation_end(); @@ -452,6 +455,7 @@ irqentry_state_t noinstr irqentry_nmi_en rcu_nmi_enter(); instrumentation_begin(); + unpoison_irq(regs); trace_hardirqs_off_finish(); ftrace_nmi_enter(); instrumentation_end();