RISC-V: Fix raw_copy_{to,from}_user()
PATCH 1/1 RISC-V: Fix raw_copy_{to,from}_user()
Sparse highlighted it, and appears to be a pure bug (from vs to).
./arch/riscv/include/asm/uaccess.h:403:35: warning: incorrect type in argument 1 (different address spaces) ./arch/riscv/include/asm/uaccess.h:403:39: warning: incorrect type in argument 2 (different address spaces) ./arch/riscv/include/asm/uaccess.h:409:37: warning: incorrect type in argument 1 (different address spaces) ./arch/riscv/include/asm/uaccess.h:409:41: warning: incorrect type in argument 2 (different address spaces)
--- arch/riscv/include/asm/uaccess.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/include/asm/uaccess.h +2 -2
@@ -400,13 +400,13 @@ extern unsigned long __must_check __asm_copy_from_user(void *to,static inline unsigned long raw_copy_from_user (void *to,const void __user *from,unsigned long n) { -return __asm_copy_to_user (to, from, n); +return __asm_copy_from_user (to, from, n); }static inline unsigned long raw_copy_to_user (void __user *to,const void *from,unsigned long n) { -return __asm_copy_from_user (to, from, n); +return __asm_copy_to_user (to, from, n); }extern long strncpy_from_user (char *dest,const char __user *src,long count);
Signature · 1 line
2.11.0
Quoted 22 lines · Olof Johansson
Sparse highlighted it, and appears to be a pure bug (from vs to).
./arch/riscv/include/asm/uaccess.h:403:35: warning: incorrect type in argument 1 (different address spaces)./arch/riscv/include/asm/uaccess.h:403:39: warning: incorrect type in argument 2 (different address spaces)./arch/riscv/include/asm/uaccess.h:409:37: warning: incorrect type in argument 1 (different address spaces)./arch/riscv/include/asm/uaccess.h:409:41: warning: incorrect type in argument 2 (different address spaces)Signed-off-by Olof Johansson <[email protected]>--- arch/riscv/include/asm/uaccess.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/include/asm/uaccess.h +1
-1@@ -400,13 +400,13 @@ extern unsigned long __must_check __asm_copy_from_user(void *to,static inline unsigned long raw_copy_from_user (void *to,const void __user *from,unsigned long n) { -return __asm_copy_to_user (to, from, n); +return __asm_copy_from_user (to, from, n);
arch/riscv/include/asm/uaccess.h extern unsigned long __must_check __asm_copy_from_user(void *to, · line 412
Quoted 10 lines
arch/riscv/include/asm/uaccess.h +1
-1}static inline unsigned long raw_copy_to_user (void __user *to,const void *from,unsigned long n) { -return __asm_copy_from_user (to, from, n); +return __asm_copy_to_user (to, from, n); }extern long strncpy_from_user (char *dest,const char __user *src,long count);
Oh, no idea how I missed that one. This looks like it's been in for a long time, so I'm surprised anything works at all!
I'm going to add a stable CC and PR this to Linus this week, assuming I get some time to at least give it a minimal test.
Thanks for catching this!
Quoted 33 lines · Palmer Dabbelt
Quoted 31 lines · Olof Johansson
Sparse highlighted it, and appears to be a pure bug (from vs to).
./arch/riscv/include/asm/uaccess.h:403:35: warning: incorrect type in argument 1 (different address spaces)./arch/riscv/include/asm/uaccess.h:403:39: warning: incorrect type in argument 2 (different address spaces)./arch/riscv/include/asm/uaccess.h:409:37: warning: incorrect type in argument 1 (different address spaces)./arch/riscv/include/asm/uaccess.h:409:41: warning: incorrect type in argument 2 (different address spaces)Signed-off-by Olof Johansson <[email protected]>--- arch/riscv/include/asm/uaccess.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/include/asm/uaccess.h +2
-2@@ -400,13 +400,13 @@ extern unsigned long __must_check __asm_copy_from_user(void *to,static inline unsigned long raw_copy_from_user (void *to,const void __user *from,unsigned long n) { -return __asm_copy_to_user (to, from, n); +return __asm_copy_from_user (to, from, n); }static inline unsigned long raw_copy_to_user (void __user *to,const void *from,unsigned long n) { -return __asm_copy_from_user (to, from, n); +return __asm_copy_to_user (to, from, n); }
Quoted 4 lines
arch/riscv/include/asm/uaccess.h extern unsigned long __must_check __asm_copy_from_user(void *to, · line 412
Quoted 1 line
arch/riscv/include/asm/uaccess.h +0
-0extern long strncpy_from_user (char *dest,const char __user *src,long count);Oh, no idea how I missed that one. This looks like it's been in for a long time, so I'm surprised anything works at all!
Actually, it boils down to a memcpy either way, it's just that exceptions and access control isn't handled right. So as long as you always do valid copying you'll luck out.
Quoted 4 lines
I'm going to add a stable CC and PR this to Linus this week, assuming I get some time to at least give it a minimal test.
Thanks for catching this!
Cool, sounds good.
-Olof