linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] powerpc/sparse: constify addresses in get_user macros
@ 2017-01-30  6:41 Daniel Axtens
  2017-01-30  6:41 ` [PATCH 1/3] powerpc/sparse: constify the address pointer in __get_user_check Daniel Axtens
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Daniel Axtens @ 2017-01-30  6:41 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Daniel Axtens

Looking through the sparse warnings, I noticed that we were getting
warnings about dropping const qualifiers in get_user calls. This took
a while to figure out: it turns out that if you pass a const pointer
in, sparse will complain when we drop the const qualifier deep inside
the __get_user_ macros. This simple series fixes that, squashing over
60 warnings.

Daniel Axtens (3):
  powerpc/sparse: constify the address pointer in __get_user_check
  powerpc/sparse: constify the address pointer in __get_user_nocheck
  powerpc/sparse: constify the address pointer in __get_user_nosleep

 arch/powerpc/include/asm/uaccess.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

-- 
2.9.3

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

* [PATCH 1/3] powerpc/sparse: constify the address pointer in __get_user_check
  2017-01-30  6:41 [PATCH 0/3] powerpc/sparse: constify addresses in get_user macros Daniel Axtens
@ 2017-01-30  6:41 ` Daniel Axtens
  2017-02-02 11:45   ` [1/3] " Michael Ellerman
  2017-01-30  6:41 ` [PATCH 2/3] powerpc/sparse: constify the address pointer in __get_user_nocheck Daniel Axtens
  2017-01-30  6:41 ` [PATCH 3/3] powerpc/sparse: constify the address pointer in __get_user_nosleep Daniel Axtens
  2 siblings, 1 reply; 5+ messages in thread
From: Daniel Axtens @ 2017-01-30  6:41 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Daniel Axtens

In __get_user_check, we create an intermediate pointer for the
user address we're about to fetch. We currently don't tag this
pointer as const. Make it const, as we are simply dereferencing
it, and it's scope is limited to the __get_user_check macro.

Signed-off-by: Daniel Axtens <dja@axtens.net>

---

This fixes warnings outside arch/powerpc where people are passing
constified pointers into get_user(), such as:

linux/fs/exec.c:423:21: warning: incorrect type in initializer (different modifiers)
     expected unsigned int [noderef] <asn:1>*__gu_addr
     got unsigned int const [noderef] [usertype] <asn:1>*

linux/kernel/trace/trace.c:1219:15: warning: incorrect type in initializer (different modifiers)
     expected char [noderef] <asn:1>*__gu_addr
     got char const [noderef] <asn:1>*

A total of 14 warnings in my pseries build are squashed.
---
 arch/powerpc/include/asm/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
index a15d84d59356..71d81cbe3781 100644
--- a/arch/powerpc/include/asm/uaccess.h
+++ b/arch/powerpc/include/asm/uaccess.h
@@ -274,7 +274,7 @@ do {								\
 ({									\
 	long __gu_err = -EFAULT;					\
 	unsigned long  __gu_val = 0;					\
-	__typeof__(*(ptr)) __user *__gu_addr = (ptr);		\
+	const __typeof__(*(ptr)) __user *__gu_addr = (ptr);		\
 	might_fault();							\
 	if (access_ok(VERIFY_READ, __gu_addr, (size)))			\
 		__get_user_size(__gu_val, __gu_addr, (size), __gu_err);	\
-- 
2.9.3

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

* [PATCH 2/3] powerpc/sparse: constify the address pointer in __get_user_nocheck
  2017-01-30  6:41 [PATCH 0/3] powerpc/sparse: constify addresses in get_user macros Daniel Axtens
  2017-01-30  6:41 ` [PATCH 1/3] powerpc/sparse: constify the address pointer in __get_user_check Daniel Axtens
@ 2017-01-30  6:41 ` Daniel Axtens
  2017-01-30  6:41 ` [PATCH 3/3] powerpc/sparse: constify the address pointer in __get_user_nosleep Daniel Axtens
  2 siblings, 0 replies; 5+ messages in thread
From: Daniel Axtens @ 2017-01-30  6:41 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Daniel Axtens

In __get_user_nocheck, we create an intermediate pointer for the
user address we're about to fetch. We currently don't tag this
pointer as const. Make it const, as we are simply dereferencing
it, and it's scope is limited to the __get_user_nocheck macro.

Signed-off-by: Daniel Axtens <dja@axtens.net>

---

This squashes 52 sparse warnings in my pseries build. They're
similar to the ones squashed in the previous patch.
---
 arch/powerpc/include/asm/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
index 71d81cbe3781..44ded4193001 100644
--- a/arch/powerpc/include/asm/uaccess.h
+++ b/arch/powerpc/include/asm/uaccess.h
@@ -261,7 +261,7 @@ do {								\
 ({								\
 	long __gu_err;						\
 	unsigned long __gu_val;					\
-	__typeof__(*(ptr)) __user *__gu_addr = (ptr);	\
+	const __typeof__(*(ptr)) __user *__gu_addr = (ptr);	\
 	__chk_user_ptr(ptr);					\
 	if (!is_kernel_addr((unsigned long)__gu_addr))		\
 		might_fault();					\
-- 
2.9.3

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

* [PATCH 3/3] powerpc/sparse: constify the address pointer in __get_user_nosleep
  2017-01-30  6:41 [PATCH 0/3] powerpc/sparse: constify addresses in get_user macros Daniel Axtens
  2017-01-30  6:41 ` [PATCH 1/3] powerpc/sparse: constify the address pointer in __get_user_check Daniel Axtens
  2017-01-30  6:41 ` [PATCH 2/3] powerpc/sparse: constify the address pointer in __get_user_nocheck Daniel Axtens
@ 2017-01-30  6:41 ` Daniel Axtens
  2 siblings, 0 replies; 5+ messages in thread
From: Daniel Axtens @ 2017-01-30  6:41 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Daniel Axtens

In __get_user_nosleep, we create an intermediate pointer for the
user address we're about to fetch. We currently don't tag this
pointer as const. Make it const, as we are simply dereferencing
it, and it's scope is limited to the __get_user_nosleep macro.

Signed-off-by: Daniel Axtens <dja@axtens.net>

---

This is sparse neutral:

-arch/powerpc/kernel/hw_breakpoint.c:XX:14: warning: incorrect type in initializer (different address spaces)
-     expected unsigned int [noderef] <asn:1>*__gu_addr
-     got unsigned int *<noident>

+arch/powerpc/kernel/hw_breakpoint.c:XX:14: warning: incorrect type in initializer (different address spaces)
+     expected unsigned int const [noderef] <asn:1>*__gu_addr
+     got unsigned int *<noident>

It looks like a pointer not tagged with __user is being passed in.
That will need to be fixed in a follow-up patch.

However this is still worth doing, as it makes the __get_user_*
macros consistent.
---
 arch/powerpc/include/asm/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
index 44ded4193001..0e6add3187bc 100644
--- a/arch/powerpc/include/asm/uaccess.h
+++ b/arch/powerpc/include/asm/uaccess.h
@@ -286,7 +286,7 @@ do {								\
 ({								\
 	long __gu_err;						\
 	unsigned long __gu_val;					\
-	__typeof__(*(ptr)) __user *__gu_addr = (ptr);	\
+	const __typeof__(*(ptr)) __user *__gu_addr = (ptr);	\
 	__chk_user_ptr(ptr);					\
 	__get_user_size(__gu_val, __gu_addr, (size), __gu_err);	\
 	(x) = (__force __typeof__(*(ptr)))__gu_val;			\
-- 
2.9.3

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

* Re: [1/3] powerpc/sparse: constify the address pointer in __get_user_check
  2017-01-30  6:41 ` [PATCH 1/3] powerpc/sparse: constify the address pointer in __get_user_check Daniel Axtens
@ 2017-02-02 11:45   ` Michael Ellerman
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2017-02-02 11:45 UTC (permalink / raw)
  To: Daniel Axtens, linuxppc-dev; +Cc: Daniel Axtens

On Mon, 2017-01-30 at 06:41:53 UTC, Daniel Axtens wrote:
> In __get_user_check, we create an intermediate pointer for the
> user address we're about to fetch. We currently don't tag this
> pointer as const. Make it const, as we are simply dereferencing
> it, and it's scope is limited to the __get_user_check macro.
> 
> Signed-off-by: Daniel Axtens <dja@axtens.net>

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/f84ed59a612d866cde0bd17ad2a52a

cheers

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

end of thread, other threads:[~2017-02-02 11:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-30  6:41 [PATCH 0/3] powerpc/sparse: constify addresses in get_user macros Daniel Axtens
2017-01-30  6:41 ` [PATCH 1/3] powerpc/sparse: constify the address pointer in __get_user_check Daniel Axtens
2017-02-02 11:45   ` [1/3] " Michael Ellerman
2017-01-30  6:41 ` [PATCH 2/3] powerpc/sparse: constify the address pointer in __get_user_nocheck Daniel Axtens
2017-01-30  6:41 ` [PATCH 3/3] powerpc/sparse: constify the address pointer in __get_user_nosleep Daniel Axtens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).