Re: [PATCH] [RFC] instrumented.h: mark instrument_write non-const

From: Peter Zijlstra

Date: Wed Nov 11 2026 - 05:36:26 EST


On Wed, Nov 11, 2026 at 10:59:51AM +0100, Marco Elver wrote:
> On Wed, 11 Nov 2026 at 10:22, Arnd Bergmann <arnd@xxxxxxxxxx> wrote:
> >
> > From: Arnd Bergmann <arnd@xxxxxxxx>
> >
> > I got another instance of a -Wmaybe-uninitialized in ntfs, as this is
> > the only place that enables the warning:
> >
> > In file included from include/asm-generic/rwonce.h:26,
> > from fs/ntfs3/file.c:10:
> > In function 'instrument_copy_from_user_before',
> > inlined from '_inline_copy_from_user' at include/linux/uaccess.h:184:2,
> > inlined from 'copy_from_user' at include/linux/uaccess.h:222:9,
> > inlined from 'ntfs_ioctl_fitrim' at fs/ntfs3/file.c:78:6,
> > inlined from 'ntfs_ioctl' at fs/ntfs3/file.c:246:10:
> > include/linux/kasan-checks.h:38:27: error: 'range' may be used uninitialized [-Werror=maybe-uninitialized]
> > 38 | #define kasan_check_write __kasan_check_write
> > include/linux/instrumented.h:146:9: note: in expansion of macro 'kasan_check_write'
> > 146 | kasan_check_write(to, n);
> > | ^~~~~~~~~~~~~~~~~
> > include/linux/kasan-checks.h: In function 'ntfs_ioctl':
> > include/linux/kasan-checks.h:20:6: note: by argument 1 of type 'const volatile void *' to '__kasan_check_write' declared here
> > 20 | bool __kasan_check_write(const volatile void *p, unsigned int size);
> > | ^~~~~~~~~~~~~~~~~~~
> > fs/ntfs3/file.c:66:29: note: 'range' declared here
> > 66 | struct fstrim_range range;
> > | ^~~~~
> >
> > The problem here is that copy_from_user() is called on an uninitialized
> > object, but the instrumentation passes the pointer into a function that
> > takes a const object. gcc deduces that any access to that object is
> > undefined behavior and warns about it.
> >
> > The only workaround I could come up with is to remove the 'const' keyword
> > from these annotations, which of course is not great either, as the
> > functions do not actually access the data at all.
>
> Agree, but the code where a real 'write' happens ought to never pass
> in a const-qualified variable or pointer anyway, so I think it's fine.
>
> > This also found incorrect 'const' annotations in
> > arch/s390/include/asm/fpu-insn.h, which writes to those pointers.
>
> That looks like a bug. Maybe split it into a separate patch.
>
> > Any ideas?
> >
> > Fixes: 33b75c1d884e ("instrumented.h: allow instrumenting both sides of copy_from_user()")
> > Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
>
> If there are no warnings that appear because of this elsewhere, then:
>
> Acked-by: Marco Elver <elver@xxxxxxxxxx>

Yeah, this looks sane enough for me too. Shall I take this (after s390
acks it), or do we want to have it sit in a CI first?