Re: [tip:core/objtool 26/27] arch/x86/kernel/signal.c:357:16: sparse: got unsigned long long [usertype] *__pu_ptr

From: Peter Zijlstra
Date: Wed Apr 24 2019 - 12:00:58 EST


On Wed, Apr 24, 2019 at 08:38:53PM +0800, kbuild test robot wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git core/objtool
> head: 29da93fea3ea39ab9b12270cc6be1b70ef201c9e
> commit: 6ae865615fc43d014da2fd1f1bba7e81ee622d1b [26/27] x86/uaccess: Dont leak the AC flag into __put_user() argument evaluation
> reproduce:
> # apt-get install sparse
> git checkout 6ae865615fc43d014da2fd1f1bba7e81ee622d1b
> make ARCH=x86_64 allmodconfig
> make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
>
> If you fix the issue, kindly add following tag
> Reported-by: kbuild test robot <lkp@xxxxxxxxx>
>
> sparse warnings: (new ones prefixed by >>)
>
> arch/x86/kernel/signal.c:357:16: sparse: sparse: cast removes address space '<asn:1>' of expression
> arch/x86/kernel/signal.c:357:16: sparse: sparse: cast removes address space '<asn:1>' of expression
> arch/x86/kernel/signal.c:357:16: sparse: sparse: cast removes address space '<asn:1>' of expression
> arch/x86/kernel/signal.c:357:16: sparse: sparse: cast removes address space '<asn:1>' of expression
> arch/x86/kernel/signal.c:357:16: sparse: sparse: cast removes address space '<asn:1>' of expression
> arch/x86/kernel/signal.c:357:16: sparse: sparse: cast removes address space '<asn:1>' of expression
> arch/x86/kernel/signal.c:357:16: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void const volatile [noderef] <asn:1> * @@ got st volatile [noderef] <asn:1> * @@
> arch/x86/kernel/signal.c:357:16: sparse: expected void const volatile [noderef] <asn:1> *
> >> arch/x86/kernel/signal.c:357:16: sparse: got unsigned long long [usertype] *__pu_ptr
> arch/x86/kernel/signal.c:417:17: sparse: sparse: cast removes address space '<asn:1>' of expression
> arch/x86/kernel/signal.c:417:17: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void const volatile [noderef] <asn:1> * @@ got st volatile [noderef] <asn:1> * @@
> arch/x86/kernel/signal.c:417:17: sparse: expected void const volatile [noderef] <asn:1> *
> arch/x86/kernel/signal.c:417:17: sparse: got unsigned long long [usertype] *

I'm not getting that; I have sparse version: 0.6.0 (Debian: 0.6.0-3)

But I suspect something like the below ought to cure that. But this is
not new from this patch, it's just that the sparse output changed
because some variable changed name.

---
diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index 364813cea647..1fd714b42a79 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -352,7 +352,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
* reasons and because gdb uses it as a signature to notice
* signal handler stack frames.
*/
- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
+ err |= __put_user(*((u64 __user *)&retcode), (u64 __user *)frame->retcode);

if (err)
return -EFAULT;