All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] m68knommu: add missing __user annotations
@ 2020-09-08 13:26 Greg Ungerer
  2020-09-08 13:30 ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Ungerer @ 2020-09-08 13:26 UTC (permalink / raw)
  To: linux-m68k; +Cc: hch, geert, Greg Ungerer, kernel test robot

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
  >> 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
  >> drivers/char/mem.c:737:21: sparse:     got char [noderef] __user *

Add in __user where appropriate.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Greg Ungerer <gerg@linux-m68k.org>
---
 arch/m68k/include/asm/uaccess_no.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/m68k/include/asm/uaccess_no.h b/arch/m68k/include/asm/uaccess_no.h
index dcfb69361408..764b01a3bd07 100644
--- a/arch/m68k/include/asm/uaccess_no.h
+++ b/arch/m68k/include/asm/uaccess_no.h
@@ -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;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] m68knommu: add missing __user annotations
  2020-09-08 13:26 [PATCH] m68knommu: add missing __user annotations Greg Ungerer
@ 2020-09-08 13:30 ` Christoph Hellwig
  2020-09-08 23:26   ` Greg Ungerer
  0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2020-09-08 13:30 UTC (permalink / raw)
  To: Greg Ungerer; +Cc: linux-m68k, hch, geert, kernel test robot

On Tue, Sep 08, 2020 at 11:26:47PM +1000, Greg Ungerer wrote:
> 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] m68knommu: add missing __user annotations
  2020-09-08 13:30 ` Christoph Hellwig
@ 2020-09-08 23:26   ` Greg Ungerer
  0 siblings, 0 replies; 3+ messages in thread
From: Greg Ungerer @ 2020-09-08 23:26 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-m68k, geert, kernel test robot


On 8/9/20 11:30 pm, Christoph Hellwig wrote:
> On Tue, Sep 08, 2020 at 11:26:47PM +1000, Greg Ungerer wrote:
>> 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-08 23:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-08 13:26 [PATCH] m68knommu: add missing __user annotations Greg Ungerer
2020-09-08 13:30 ` Christoph Hellwig
2020-09-08 23:26   ` Greg Ungerer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.