uaccess: fix type mismatch warnings from access_ok()
authorArnd Bergmann <arnd@arndb.de>
Mon, 14 Feb 2022 19:22:10 +0000 (20:22 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Apr 2022 12:24:01 +0000 (14:24 +0200)
[ Upstream commit 23fc539e81295b14b50c6ccc5baeb4f3d59d822d ]

On some architectures, access_ok() does not do any argument type
checking, so replacing the definition with a generic one causes
a few warnings for harmless issues that were never caught before.

Fix the ones that I found either through my own test builds or
that were reported by the 0-day bot.

Reported-by: kernel test robot <lkp@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Dinh Nguyen <dinguyen@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/arc/kernel/process.c
arch/arm/kernel/swp_emulate.c
arch/arm/kernel/traps.c
arch/csky/kernel/perf_callchain.c
arch/csky/kernel/signal.c
arch/nios2/kernel/signal.c
arch/powerpc/lib/sstep.c
arch/riscv/kernel/perf_callchain.c
arch/sparc/kernel/signal_32.c
lib/test_lockup.c

index 8e90052f6f0569722e961a49ecb843bde37fab86..5f7f5aab361f17f9db0ae01baf594f6ceeb12868 100644 (file)
@@ -43,7 +43,7 @@ SYSCALL_DEFINE0(arc_gettls)
        return task_thread_info(current)->thr_ptr;
 }
 
-SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new)
+SYSCALL_DEFINE3(arc_usr_cmpxchg, int __user *, uaddr, int, expected, int, new)
 {
        struct pt_regs *regs = current_pt_regs();
        u32 uval;
index 6166ba38bf99479d62fa9f2e24c5a0f180ba4851..b74bfcf94fb1a5ea85fea22756628afae9676630 100644 (file)
@@ -195,7 +195,7 @@ static int swp_handler(struct pt_regs *regs, unsigned int instr)
                 destreg, EXTRACT_REG_NUM(instr, RT2_OFFSET), data);
 
        /* Check access in reasonable access range for both SWP and SWPB */
-       if (!access_ok((address & ~3), 4)) {
+       if (!access_ok((void __user *)(address & ~3), 4)) {
                pr_debug("SWP{B} emulation: access to %p not allowed!\n",
                         (void *)address);
                res = -EFAULT;
index 655c4fe0b4d08a25a0e92cbe21f25153a08d9858..54abd8720ddef09700a983035bcde300a44905bd 100644 (file)
@@ -575,7 +575,7 @@ do_cache_op(unsigned long start, unsigned long end, int flags)
        if (end < start || flags)
                return -EINVAL;
 
-       if (!access_ok(start, end - start))
+       if (!access_ok((void __user *)start, end - start))
                return -EFAULT;
 
        return __do_cache_op(start, end);
index 35318a635a5fae7b6de24723f6f43338bab85b67..75e1f9df5f60449c6ec65c3e97ed3bd5ca2b07e2 100644 (file)
@@ -49,7 +49,7 @@ static unsigned long user_backtrace(struct perf_callchain_entry_ctx *entry,
 {
        struct stackframe buftail;
        unsigned long lr = 0;
-       unsigned long *user_frame_tail = (unsigned long *)fp;
+       unsigned long __user *user_frame_tail = (unsigned long __user *)fp;
 
        /* Check accessibility of one struct frame_tail beyond */
        if (!access_ok(user_frame_tail, sizeof(buftail)))
index c7b763d2f526e661f16b5ad98c5c56bd4c7c257e..8867ddf3e6c7712731745f215b21d7f6e1851e53 100644 (file)
@@ -136,7 +136,7 @@ static inline void __user *get_sigframe(struct ksignal *ksig,
 static int
 setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs)
 {
-       struct rt_sigframe *frame;
+       struct rt_sigframe __user *frame;
        int err = 0;
 
        frame = get_sigframe(ksig, regs, sizeof(*frame));
index 2009ae2d3c3bbe55eecbdfaaaacb956855068be4..386e46443b605676c92a55fb47245b919be751db 100644 (file)
@@ -36,10 +36,10 @@ struct rt_sigframe {
 
 static inline int rt_restore_ucontext(struct pt_regs *regs,
                                        struct switch_stack *sw,
-                                       struct ucontext *uc, int *pr2)
+                                       struct ucontext __user *uc, int *pr2)
 {
        int temp;
-       unsigned long *gregs = uc->uc_mcontext.gregs;
+       unsigned long __user *gregs = uc->uc_mcontext.gregs;
        int err;
 
        /* Always make any pending restarted system calls return -EINTR */
@@ -102,10 +102,11 @@ asmlinkage int do_rt_sigreturn(struct switch_stack *sw)
 {
        struct pt_regs *regs = (struct pt_regs *)(sw + 1);
        /* Verify, can we follow the stack back */
-       struct rt_sigframe *frame = (struct rt_sigframe *) regs->sp;
+       struct rt_sigframe __user *frame;
        sigset_t set;
        int rval;
 
+       frame = (struct rt_sigframe __user *) regs->sp;
        if (!access_ok(frame, sizeof(*frame)))
                goto badframe;
 
@@ -124,10 +125,10 @@ badframe:
        return 0;
 }
 
-static inline int rt_setup_ucontext(struct ucontext *uc, struct pt_regs *regs)
+static inline int rt_setup_ucontext(struct ucontext __user *uc, struct pt_regs *regs)
 {
        struct switch_stack *sw = (struct switch_stack *)regs - 1;
-       unsigned long *gregs = uc->uc_mcontext.gregs;
+       unsigned long __user *gregs = uc->uc_mcontext.gregs;
        int err = 0;
 
        err |= __put_user(MCONTEXT_VERSION, &uc->uc_mcontext.version);
@@ -162,8 +163,9 @@ static inline int rt_setup_ucontext(struct ucontext *uc, struct pt_regs *regs)
        return err;
 }
 
-static inline void *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
-                                size_t frame_size)
+static inline void __user *get_sigframe(struct ksignal *ksig,
+                                       struct pt_regs *regs,
+                                       size_t frame_size)
 {
        unsigned long usp;
 
@@ -174,13 +176,13 @@ static inline void *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
        usp = sigsp(usp, ksig);
 
        /* Verify, is it 32 or 64 bit aligned */
-       return (void *)((usp - frame_size) & -8UL);
+       return (void __user *)((usp - frame_size) & -8UL);
 }
 
 static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
                          struct pt_regs *regs)
 {
-       struct rt_sigframe *frame;
+       struct rt_sigframe __user *frame;
        int err = 0;
 
        frame = get_sigframe(ksig, regs, sizeof(*frame));
index d8cc49f39fe47558ef01ea49bbe85122d7a2db78..1a16ad18f9f23e2a5813e50184642b3f3af3bea4 100644 (file)
@@ -112,9 +112,9 @@ static nokprobe_inline long address_ok(struct pt_regs *regs,
 {
        if (!user_mode(regs))
                return 1;
-       if (__access_ok(ea, nb))
+       if (access_ok((void __user *)ea, nb))
                return 1;
-       if (__access_ok(ea, 1))
+       if (access_ok((void __user *)ea, 1))
                /* Access overlaps the end of the user region */
                regs->dar = TASK_SIZE_MAX - 1;
        else
index d82c291c1e4ca1f4bf086c76fdb1af8c8c168f1b..357f985041cb914d383d93c0410fb8b764f78f1b 100644 (file)
@@ -15,8 +15,8 @@ static unsigned long user_backtrace(struct perf_callchain_entry_ctx *entry,
 {
        struct stackframe buftail;
        unsigned long ra = 0;
-       unsigned long *user_frame_tail =
-                       (unsigned long *)(fp - sizeof(struct stackframe));
+       unsigned long __user *user_frame_tail =
+               (unsigned long __user *)(fp - sizeof(struct stackframe));
 
        /* Check accessibility of one struct frame_tail beyond */
        if (!access_ok(user_frame_tail, sizeof(buftail)))
index ffab16369beac82f9fd6cfe243571888f9609a81..74f80443b195fa400964f9491982934dd5c6e6a1 100644 (file)
@@ -65,7 +65,7 @@ struct rt_signal_frame {
  */
 static inline bool invalid_frame_pointer(void __user *fp, int fplen)
 {
-       if ((((unsigned long) fp) & 15) || !__access_ok((unsigned long)fp, fplen))
+       if ((((unsigned long) fp) & 15) || !access_ok(fp, fplen))
                return true;
 
        return false;
index 906b598740a7b87b45368c6453f7f8a319d25ea3..6a0f329a794a4787fc740f22c0acac5971821918 100644 (file)
@@ -417,8 +417,8 @@ static bool test_kernel_ptr(unsigned long addr, int size)
                return false;
 
        /* should be at least readable kernel address */
-       if (access_ok(ptr, 1) ||
-           access_ok(ptr + size - 1, 1) ||
+       if (access_ok((void __user *)ptr, 1) ||
+           access_ok((void __user *)ptr + size - 1, 1) ||
            get_kernel_nofault(buf, ptr) ||
            get_kernel_nofault(buf, ptr + size - 1)) {
                pr_err("invalid kernel ptr: %#lx\n", addr);