Skip to contentSkip to conversation

m68knommu: add missing __user annotations

PATCH In review Greg Ungerer 2 participants 3 messages Sep 8, 2020

Subsystems (2)
lore
Share & tools
lore

Greg Ungerer

author maintainer
#0 lore raw

PATCH 1/1 m68knommu: add missing __user annotations

Some of the m68knommu user access functions are not using the __user annotation where required. Specifically __clear_user(), strnlen_user() and strncpy_from_user() need their user space source address annoted with __user.

Picked up by the kernel test robot, when running sparse:

sparse warnings: (new ones prefixed by >>)

drivers/char/mem.c:163:37: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void *to @@ got char [noderef] __user *buf @@
drivers/char/mem.c:163:37: sparse: expected void *to
drivers/char/mem.c:163:37: sparse: got char [noderef] __user *buf

Quoted 1 line
Quoted 1 line

drivers/char/mem.c:737:21: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void *to @@ got char [noderef] __user * @@

drivers/char/mem.c:737:21: sparse: expected void *to

Quoted 1 line
Quoted 1 line

drivers/char/mem.c:737:21: sparse: got char [noderef] __user *

Add in __user where appropriate.

---
 arch/m68k/include/asm/uaccess_no.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/m68k/include/asm/uaccess_no.h +3 -3
index dcfb69361408..764b01a3bd07 100644
@@ -125,7 +125,7 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n)
  */
 
 static inline long
-strncpy_from_user(char *dst, const char *src, long count)
+strncpy_from_user(char *dst, const char __user *src, long count)
 {
 	char *tmp;
 	strncpy(dst, src, count);
@@ -139,7 +139,7 @@ strncpy_from_user(char *dst, const char *src, long count)
  *
  * Return 0 on exception, a value greater than N if too long
  */
-static inline long strnlen_user(const char *src, long n)
+static inline long strnlen_user(const char __user *src, long n)
 {
 	return(strlen(src) + 1); /* DAVIDM make safer */
 }
@@ -149,7 +149,7 @@ static inline long strnlen_user(const char *src, long n)
  */
 
 static inline unsigned long
-__clear_user(void *to, unsigned long n)
+__clear_user(void __user *to, unsigned long n)
 {
 	memset(to, 0, n);
 	return 0;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 4 lines · Greg Ungerer

Some of the m68knommu user access functions are not using the __user annotation where required. Specifically __clear_user(), strnlen_user() and strncpy_from_user() need their user space source address annoted with __user.

You'll also need __force annotations to that sparse doesn't complain inside the function. Btw, it might be worth to just use the helpers from asm-generic/uaccess.h as they should work for m68knommu.

author maintainer
#2 lore raw
Quoted 9 lines · Christoph Hellwig
Quoted 4 lines · Greg Ungerer

Some of the m68knommu user access functions are not using the __user annotation where required. Specifically __clear_user(), strnlen_user() and strncpy_from_user() need their user space source address annoted with __user.

You'll also need __force annotations to that sparse doesn't complain inside the function. Btw, it might be worth to just use the helpers from asm-generic/uaccess.h as they should work for m68knommu.

I would much prefer to use the helpers in asm-generic/uaccess.h. But that is going to involve a little more change, the put_user() and get_user() macros can't be over-ridden with the logic as defined in asm-generic/uaccess.h today.

It might just be the case that we can use the whole lot and not lose optimized get_user()/set_user() anyway. I will check the resulting code and see if it is just as good.

Regards
Greg