From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06A1E3CE48F for ; Tue, 12 May 2026 11:15:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778584528; cv=none; b=leKK4JDzjhLyYLpgCxHg6FU1oG2Nn+Eg9K/IzfKbbz9BNFJKFNOD77Yz35SsBFlD1zv2saw6JbcxOTNVSGbyKYpDg1AsqAJvpgTZHZDkeIJSPuCJwuqnjX/z7AMRoPQpInrcDrQQyvLgCrCKpEt8wzDgidfncDb1P+vUFmk4rww= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778584528; c=relaxed/simple; bh=aOYRzkPak9a6qjoUzNuZXEr/2P87M43Af449W+c67sE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mxAuhAyLqsXwFl8/y0yjgnsG6RnMELJemauuE7CilIyrc0VKyYec52RtfZNg2t7MGbGHcMv8J8Od8Pg6DTkVYAZvvibi4ZlcmAjf7oJJ+WllIGafhxSVgrOO58ljNeu2+XD4AXkVIoGRdXd5cQT+3khBGS63hZcSlrdr81C7Tbs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=ipZBxC96; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="ipZBxC96" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C75FF1691; Tue, 12 May 2026 04:15:20 -0700 (PDT) Received: from J2N7QTR9R3 (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1121F3F85F; Tue, 12 May 2026 04:15:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778584526; bh=aOYRzkPak9a6qjoUzNuZXEr/2P87M43Af449W+c67sE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ipZBxC96sQozblfDn8oMLUkRdNZ25Dylb1KjkvdjZG/ZK0KhVOD7TA7QB6v2nY3ad V8Pt3SV5GlUnCNSIJqvhN5kz1B0aeYjvtz5+iqR2J3GWiIbosgM/7O8N3C9cUV0SWy XBeu8Hav7wGMoPzjC2cDwD996oE9sGBzVOSWjlbE= Date: Tue, 12 May 2026 12:15:21 +0100 From: Mark Rutland To: Alexander Potapenko Cc: Thomas Gleixner , Dmitry Vyukov , syzbot , kasan-dev , linux-kernel@vger.kernel.org, luto@kernel.org, peterz@infradead.org, syzkaller-bugs@googlegroups.com, ruanjinjie@huawei.com Subject: Re: [syzbot] [kernel?] upstream test error: KMSAN: uninit-value in irqentry_exit_to_kernel_mode_preempt Message-ID: References: <69e7ee1f.a00a0220.17a17.001d.GAE@google.com> <87v7cu876c.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Tue, May 12, 2026 at 11:33:47AM +0200, Alexander Potapenko wrote: > On Mon, May 11, 2026 at 2:25 PM Thomas Gleixner wrote: > > > irqentry_exit_to_kernel_mode_preempt() is now checking for both `regs` > > > and `state`. > > > Because there is a lot of non-instrumented code around, we fail to > > > initialize these variables. > > > Instead, irqentry_enter_from_kernel_mode() explicitly calls > > > kmsan_unpoison_entry_regs(regs) to take care of the registers, but not > > > the state. > > > We should probably call `kmsan_unpoison_memory(&state, sizeof(state))` > > > at the same place. > > > > Good luck with unpoisoning 'state'. 'state' is not memory to begin with. > > My bad. Normally, the compiler would happily move `state` to memory if it is > address-taken, and make sure that its shadow is tracked properly. > But not in this case, because irqentry_enter_from_kernel_mode() is inlined into > a `noinstr` function. > > > > > Again. 'state' is a pure register value, which is handed to > > irqentry_exit() and irqentry_exit_to_kernel_mode_preempt(). > > There is no notion of a 'pure register value' in C, and the compiler may make > arbitrary decisions about whether a particular value is stored on the stack or > in the registers. > > Luckily, KMSAN does not have to know about that, because it works on the LLVM IR > level and can track the state of a value regardless of where it is stored. > In particular, it normally works for function return values - unless `noinstr` > kicks in. > > > > > But KMSAN magically associates a memory access which it and then claims > > it belongs to a SKB which was allocated in the interrupted code. > > > > What Mark's change actually does is to make the register value 'state' > > observable in an instrumented function, while before that 'state' was > > always confined in the non instrumentable code. > > Agreed. > > > But as that 'state' argument of irqentry_exit_to_kernel_mode_preempt() > > is a pure register value, which could be even a constant supplied by the > > caller of irqentry_exit(), KMSAN has _ZERO_ business to fiddle with it. > > I disagree with a general implication that KMSAN has zero business to fiddle > with values passed in registers. But I agree we are doing a poor job trying > to pull the shadow for `state` out of thin air. > > > The compiler _cannot_ assume anything about the 'state' argument as > > that's handed in as value in RSI from a completely different compilation > > unit. > > Again, this only matters because we are calling an instrumented function from > a non-instrumented one, otherwise it's perfectly fine to call between > compilation units. For context, can you explain how this is expected to work across compilation units when the caller and callee *are* instrumented, when an argument is passed in a register? Below you suggest that the caller might add "hints", but it's not clear specifically what this means. > > Something is wrong in KMSAN/compiler land or do you still believe that > > you just need to unpoison the non existing memory 'state'? > > When we call an instrumented function from a non-instrumented one, the compiler > is doomed to not understand that and to be unable to track the function > parameters properly. Exactly because `noinstr` implies no instrumentation > whatsoever, the compiler may not add any hints on the caller side that would > help the callee understand what's going on - even if KMSAN is able to see this > `noinstr` function (which is not always the case). > > So what we could do is to add annotations manualy on either the caller side or > the callee side. Without some understanding of those "hints" you mention, I don't see how we can do that on the caller side. > We can apply `__no_kmsan_checks` to irqentry_exit_to_kernel_mode_preempt(), > making all its inputs initialized. This is the easiest solution, it may > introduce false negatives, but we are on a very thin ice anyway, so perhaps > doing so is better than dealing with more false positives in the interrupt code. > > Another option for the callee would be applying `__always_inline`, so that > irqentry_exit_to_kernel_mode_preempt() also becomes non-instrumented. > Given that irqentry_exit_to_kernel_mode_after_preempt() is already > `__always_inline`, it might be the right thing to do. We can do that, but this really suggests that there's a fundemantal inability to pass arguments between code which is noinstr and code which isinstrumented with AddressSanitizer, and that's inevitably going to bite us in future. > On the caller side, we could do something creative with instrumentation_begin() > and instrumentation_end(). We've had a discussion about that exactly four years > ago: https://lore.kernel.org/all/20220426164315.625149-29-glider@google.com/T/#u > , but came to a conclusion that a handful of annotations on the noinstr/instr > boundary may do a better job than a solution that doesn't cover all cases. That doesn't look general at all, so I am not keen on that. > In particular, the case of irqentry_exit_to_kernel_mode_preempt() could have > been solved by `__memset(state, 0, sizeof(struct kmsan_context_state))` in > instrumentation_begin(). But it wouldn't solve more complex (yet rare, and > non-existing today) cases where two functions are called from an instrumented > region, and the first function somehow leaves the argument state poisoned. How exactly is kmsan_context_state used? If that's supposed to carry some global or current context, surely blatting that in entry code will affect the code that was interrupted? I see kmsan_get_context() has an in_task() check, but that can't help with nested exceptions, so this doesn't look right at all. > Do you think it's worth revisiting the instrumentation_begin() approach, or > shall we go with one of the compiler attributes instead? I think we need a better understanding of this first. It looks to me that there are bigger problems here. Mark.