Commit ae6b0195 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Ingo Molnar

x86/uaccess: Add missing __force to casts in __access_ok() and valid_user_address()

Sparse complains about losing the __user address space due to the cast to
long:

  uaccess_64.h:88:24: sparse: warning: cast removes address space '__user' of expression

Annotate it with __force to tell sparse that this is intentional.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20240304005104.677606054@linutronix.de
parent 71eb4893
...@@ -54,7 +54,7 @@ static inline unsigned long __untagged_addr_remote(struct mm_struct *mm, ...@@ -54,7 +54,7 @@ static inline unsigned long __untagged_addr_remote(struct mm_struct *mm,
* half and a user half. When cast to a signed type, user pointers * half and a user half. When cast to a signed type, user pointers
* are positive and kernel pointers are negative. * are positive and kernel pointers are negative.
*/ */
#define valid_user_address(x) ((long)(x) >= 0) #define valid_user_address(x) ((__force long)(x) >= 0)
/* /*
* User pointers can have tag bits on x86-64. This scheme tolerates * User pointers can have tag bits on x86-64. This scheme tolerates
...@@ -87,8 +87,9 @@ static inline bool __access_ok(const void __user *ptr, unsigned long size) ...@@ -87,8 +87,9 @@ static inline bool __access_ok(const void __user *ptr, unsigned long size)
if (__builtin_constant_p(size <= PAGE_SIZE) && size <= PAGE_SIZE) { if (__builtin_constant_p(size <= PAGE_SIZE) && size <= PAGE_SIZE) {
return valid_user_address(ptr); return valid_user_address(ptr);
} else { } else {
unsigned long sum = size + (unsigned long)ptr; unsigned long sum = size + (__force unsigned long)ptr;
return valid_user_address(sum) && sum >= (unsigned long)ptr;
return valid_user_address(sum) && sum >= (__force unsigned long)ptr;
} }
} }
#define __access_ok __access_ok #define __access_ok __access_ok
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment