Re: kcsan -Wmaybe-uninitialized warning in ntfs3
From: Marco Elver
Date: Tue Apr 21 2026 - 07:38:39 EST
On Tue, 21 Apr 2026 at 12:21, Arnd Bergmann <arnd@xxxxxxxx> wrote:
>
> On Tue, Apr 21, 2026, at 11:33, Marco Elver wrote:
> > On Tue, 21 Apr 2026 at 09:54, Arnd Bergmann <arnd@xxxxxxxx> wrote:
> >> What happens here is that copy_from_user() is used in a very
> >> normal way to copy a user space structure into a previously
> >> uninitialized on-stack buffer. With KCSAN enabled, this passes
> >> the pointer to that buffer into __kcsan_check_access(), which
> >> takes a 'const volatile void *' pointer. Gcc correctly notices
> >> that there is no way to access the data behind this pointer
> >> when it hasn't been initialized yet, as both read and write
> >> would cause undefined behavior.
> >>
> >> I'm not sure what a good solution would be to avoid this,
> >> but I assume this should be fixed in the kcsan instrumentation.
> >> I tried changing that code to pass non-const pointers for
> >> any instrument_write variant, which does avoid the warning,
> >> but also adds a bit of complexity, see below.
> >>
> >> Any other ideas?
> >
> > Indeed, the below is rather complex, and seems unnecessary to me just
> > to suppress this warning which not even the whole kernel enables.
> >
> > How can I reproduce this? GCC version? .config? I can't seem to with
> > an x86 defconfig + CONFIG_NTFS3_FS + KCSAN config + GCC on linux-next
> > (20260420).
>
> I ran into this during randconfig testing, I have attached a
> reproducer .config here, but have not tried to narrow down the
> configuration options that are required for triggering it.
The attached .config is a KASAN config, still can't reproduce.