All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: kernel test robot <lkp@intel.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: oe-kbuild-all@lists.linux.dev, linux-kernel@vger.kernel.org,
	x86@kernel.org, Dave Hansen <dave.hansen@linux.intel.com>
Subject: Re: [tip:x86/mm 5/16] sound/core/hwdep.c:243:24: sparse: sparse: incorrect type in assignment (different address spaces)
Date: Mon, 14 Nov 2022 14:55:46 -0800	[thread overview]
Message-ID: <fdae3de9-db03-b04d-1992-bc8efd053053@intel.com> (raw)
In-Reply-To: <202211150551.T7mpZomP-lkp@intel.com>

[-- Attachment #1: Type: text/plain, Size: 1384 bytes --]

On 11/14/22 13:41, kernel test robot wrote:
>    sound/core/hwdep.c:243:24: sparse:     expected int [noderef] __user *__ptr_clean
>    sound/core/hwdep.c:243:24: sparse:     got int *
>    sound/core/hwdep.c:273:29: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected int [noderef] __user *__ptr_clean @@     got int * @@
>    sound/core/hwdep.c:273:29: sparse:     expected int [noderef] __user *__ptr_clean
>    sound/core/hwdep.c:273:29: sparse:     got int *
>    sound/core/hwdep.c:292:29: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected int [noderef] __user *__ptr_clean @@     got int * @@
>    sound/core/hwdep.c:292:29: sparse:     expected int [noderef] __user *__ptr_clean
>    sound/core/hwdep.c:292:29: sparse:     got int *

I think the sparse ends up throwing away all of its annotations once it
dereferences a pointer.  So, '*(int __user *)' boils down to a plain
'int'.  Confusingly, a '*(int __user *) *' boils down to an 'int *'.

That's what happened here.  A __user-annotated point got dereferenced
down to an 'int' and then turned into a pointer again.

I think the trick in this case is to avoid dereferencing the pointer too
early by just moving the dereference outside of the casting, like the
attached patch.  But, it also feels kinda wrong.  I'd love a second
opinion on this one.

[-- Attachment #2: lam-sparse.patch --]
[-- Type: text/x-patch, Size: 528 bytes --]

diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index 0db6f5451854..b8947b623c72 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -39,7 +39,7 @@ static inline bool pagefault_disabled(void);
 #define untagged_ptr(mm, ptr)	({					\
 	u64 __ptrval = (__force u64)(ptr);				\
 	__ptrval = untagged_addr(mm, __ptrval);				\
-	(__force __typeof__(*(ptr)) *)__ptrval;				\
+	*(__force __typeof__((ptr)) *)__ptrval;				\
 })
 #else
 #define untagged_addr(mm, addr)	(addr)

  reply	other threads:[~2022-11-14 22:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-14 21:41 [tip:x86/mm 5/16] sound/core/hwdep.c:243:24: sparse: sparse: incorrect type in assignment (different address spaces) kernel test robot
2022-11-14 22:55 ` Dave Hansen [this message]
2022-11-15  3:40   ` Kirill A. Shutemov
2022-11-15 15:58     ` Kirill A. Shutemov
2022-11-16  0:43       ` [PATCH 0/2] x86/mm: Fix sparse warning due to LAM patchset Kirill A. Shutemov
2022-11-16  0:43         ` [PATCH 1/2] scsi: Fix get_user() in call sg_scsi_ioctl() Kirill A. Shutemov
2022-11-16  0:48           ` Dave Hansen
2022-11-16  0:55             ` kirill
2022-11-16 22:40           ` David Laight
2022-11-17  0:03             ` kirill
2022-11-16  0:43         ` [PATCH 2/2] x86/mm: Fix sparse warnings in untagged_ptr() Kirill A. Shutemov
2022-11-24 19:36           ` Andy Shevchenko

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=fdae3de9-db03-b04d-1992-bc8efd053053@intel.com \
    --to=dave.hansen@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=oe-kbuild-all@lists.linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.