lkml.org 
[lkml]   [2022]   [Nov]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
SubjectRe: [tip:x86/mm 5/16] sound/core/hwdep.c:243:24: sparse: sparse: incorrect type in assignment (different address spaces)
From
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.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)
\
 
 \ /
  Last update: 2022-11-14 23:56    [W:0.064 / U:0.332 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site