mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Ricardo Ribalda <ribalda@chromium.org>
Cc: x86@kernel.org, Thomas Gleixner <tglx@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] x86/uaccess: Drop the address space qualifier from put_user()
Date: Wed, 23 Sep 2026 16:22:34 +0100	[thread overview]
Message-ID: <20260923162234.394061af@pumpkin> (raw)
In-Reply-To: <CANiDSCt9nOM8OWY21Q=ei5dmOK2O+DB1aYdd9NrbLt3e+pJPUg@mail.gmail.com>

On Wed, 23 Sep 2026 13:08:20 +0200
Ricardo Ribalda <ribalda@chromium.org> wrote:

> Friendly ping?
> 
> On Mon, 14 Sept 2026 at 15:53, Ricardo Ribalda <ribalda@chromium.org> wrote:
> >
> > __typeof__() preserves every qualifier, the address space included.
> >
> > When we do __typeof(*__user *int), we are declaring a __user integer,
> > which is pretty much meaningless. A value in a register or in the stack
> > does not live in the user address space.

Doesn't that mean it is a smatch bug - so should be fixed there.

Somewhere in the middle of this there ought to checks that the value
is the correct type (eg pointer v integer) and that, for put_user(),
the destination pointer isn't const.
Using:
	auto __x = 0 ? *ptr : x;
can be more succinct than other versions - might not help here.

David

> >
> > This annotation did not trigger any error until a recent version of
> > smatch[1] started caring. And as a result of that now we have tens of
> > warnings like:
> >
> >   drivers/media/usb/uvc/uvc_v4l2.c:1112:13: warning: incorrect type in argument 2 (different address spaces)
> >   drivers/media/usb/uvc/uvc_v4l2.c:1112:13:    expected void const *from
> >   drivers/media/usb/uvc/uvc_v4l2.c:1112:13:    got unsigned int __user *
> >
> > Instead of __typeof__() use TYPEOF_UNQUAL(). It maps to
> > __typeof_unqual__() in recent compilers, so the address space annotation
> > is gone.
> >
> > [1] https://github.com/error27/smatch/commit/e53027a4e816a772403baafa83c09e4a94c1cb8f
> >
> > Suggested-by: Dan Carpenter <dan.carpenter@linaro.org>
> > Link: https://lore.kernel.org/r/20260825-unqual-v1-2-7024fb81b4f9@chromium.org
> > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> > ---
> >  arch/x86/include/asm/uaccess.h | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
> > index 3a0dd3c2b233..4e576c0b9131 100644
> > --- a/arch/x86/include/asm/uaccess.h
> > +++ b/arch/x86/include/asm/uaccess.h
> > @@ -172,7 +172,7 @@ extern void __put_user_nocheck_8(void);
> >         int __ret_pu;                                                   \
> >         void __user *__ptr_pu;                                          \
> >         register __typeof__(*(ptr)) __val_pu asm("%"_ASM_AX);           \
> > -       __typeof__(*(ptr)) __x = (x); /* eval x once */                 \
> > +       TYPEOF_UNQUAL(*(ptr)) __x = (x); /* eval x once */              \
> >         __typeof__(ptr) __ptr = (ptr); /* eval ptr once */              \
> >         __chk_user_ptr(__ptr);                                          \
> >         __ptr_pu = __ptr;                                               \
> > @@ -231,7 +231,7 @@ extern void __put_user_nocheck_8(void);
> >
> >  #define __put_user_size(x, ptr, size, label)                           \
> >  do {                                                                   \
> > -       __typeof__(*(ptr)) __x = (x); /* eval x once */                 \
> > +       TYPEOF_UNQUAL(*(ptr)) __x = (x); /* eval x once */              \
> >         __typeof__(ptr) __ptr = (ptr); /* eval ptr once */              \
> >         __chk_user_ptr(__ptr);                                          \
> >         switch (size) {                                                 \
> >
> > --
> > 2.55.0.1007.g17ff1f9808-goog
> >  
> 
> 


      reply	other threads:[~2026-09-23 15:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14 13:53 [PATCH v2 0/2] Fix warnings with recent smatch Ricardo Ribalda
2026-09-14 13:53 ` [PATCH v2 1/2] rcu: Drop the address space qualifier from the dereference macros Ricardo Ribalda
2026-09-14 13:53 ` [PATCH v2 2/2] x86/uaccess: Drop the address space qualifier from put_user() Ricardo Ribalda
2026-09-14 14:58   ` Paul E. McKenney
2026-09-14 15:13     ` Paul E. McKenney
2026-09-23 11:08   ` Ricardo Ribalda
2026-09-23 15:22     ` David Laight [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260923162234.394061af@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=ribalda@chromium.org \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®