Skip to content

Commit 334a023

Browse files
committed
Clean up x86 unsafe_get/put_user() type handling
Al noticed that unsafe_put_user() had type problems, and fixed them in commit a7cc722 ("fix unsafe_put_user()"), which made me look more at those functions. It turns out that unsafe_get_user() had a type issue too: it limited the largest size of the type it could handle to "unsigned long". Which is fine with the current users, but doesn't match our existing normal get_user() semantics, which can also handle "u64" even when that does not fit in a long. While at it, also clean up the type cast in unsafe_put_user(). We actually want to just make it an assignment to the expected type of the pointer, because we actually do want warnings from types that don't convert silently. And it makes the code more readable by not having that one very long and complex line. [ This patch might become stable material if we ever end up back-porting any new users of the unsafe uaccess code, but as things stand now this doesn't matter for any current existing uses. ] Cc: Al Viro <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent f3926e4 commit 334a023

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

arch/x86/include/asm/uaccess.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,14 +703,15 @@ extern struct movsl_mask {
703703
#define unsafe_put_user(x, ptr, err_label) \
704704
do { \
705705
int __pu_err; \
706-
__put_user_size((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)), __pu_err, -EFAULT); \
706+
__typeof__(*(ptr)) __pu_val = (x); \
707+
__put_user_size(__pu_val, (ptr), sizeof(*(ptr)), __pu_err, -EFAULT); \
707708
if (unlikely(__pu_err)) goto err_label; \
708709
} while (0)
709710

710711
#define unsafe_get_user(x, ptr, err_label) \
711712
do { \
712713
int __gu_err; \
713-
unsigned long __gu_val; \
714+
__inttype(*(ptr)) __gu_val; \
714715
__get_user_size(__gu_val, (ptr), sizeof(*(ptr)), __gu_err, -EFAULT); \
715716
(x) = (__force __typeof__(*(ptr)))__gu_val; \
716717
if (unlikely(__gu_err)) goto err_label; \

0 commit comments

Comments
 (0)