Merge tag 'mips_fixes_4.16_4' of git://git.kernel.org/pub/scm/linux/kernel/git/jhogan...
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 8 Mar 2018 18:03:12 +0000 (10:03 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 8 Mar 2018 18:03:12 +0000 (10:03 -0800)
Pull MIPS fixes from James Hogan:
 "A miscellaneous pile of MIPS fixes for 4.16:

   - move put_compat_sigset() to evade hardened usercopy warnings (4.16)

   - select ARCH_HAVE_PC_{SERIO,PARPORT} for Loongson64 platforms (4.16)

   - fix kzalloc() failure handling in ath25 (3.19) and Octeon (4.0)

   - fix disabling of IPIs during BMIPS suspend (3.19)"

* tag 'mips_fixes_4.16_4' of git://git.kernel.org/pub/scm/linux/kernel/git/jhogan/mips:
  MIPS: BMIPS: Do not mask IPIs during suspend
  MIPS: Loongson64: Select ARCH_MIGHT_HAVE_PC_SERIO
  MIPS: Loongson64: Select ARCH_MIGHT_HAVE_PC_PARPORT
  signals: Move put_compat_sigset to compat.h to silence hardened usercopy
  MIPS: OCTEON: irq: Check for null return on kzalloc allocation
  MIPS: ath25: Check for kzalloc allocation failure

1  2 
include/linux/compat.h

diff --combined include/linux/compat.h
@@@ -17,6 -17,7 +17,7 @@@
  #include <linux/if.h>
  #include <linux/fs.h>
  #include <linux/aio_abi.h>    /* for aio_context_t */
+ #include <linux/uaccess.h>
  #include <linux/unistd.h>
  
  #include <asm/compat.h>
@@@ -229,13 -230,13 +230,13 @@@ typedef struct compat_siginfo 
                                short int _addr_lsb;    /* Valid LSB of the reported address. */
                                /* used when si_code=SEGV_BNDERR */
                                struct {
 -                                      short _dummy_bnd;
 +                                      compat_uptr_t _dummy_bnd;
                                        compat_uptr_t _lower;
                                        compat_uptr_t _upper;
                                } _addr_bnd;
                                /* used when si_code=SEGV_PKUERR */
                                struct {
 -                                      short _dummy_pkey;
 +                                      compat_uptr_t _dummy_pkey;
                                        u32 _pkey;
                                } _addr_pkey;
                        };
@@@ -550,8 -551,29 +551,29 @@@ asmlinkage long compat_sys_settimeofday
  asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp);
  
  extern int get_compat_sigset(sigset_t *set, const compat_sigset_t __user *compat);
- extern int put_compat_sigset(compat_sigset_t __user *compat,
-                            const sigset_t *set, unsigned int size);
+ /*
+  * Defined inline such that size can be compile time constant, which avoids
+  * CONFIG_HARDENED_USERCOPY complaining about copies from task_struct
+  */
+ static inline int
+ put_compat_sigset(compat_sigset_t __user *compat, const sigset_t *set,
+                 unsigned int size)
+ {
+       /* size <= sizeof(compat_sigset_t) <= sizeof(sigset_t) */
+ #ifdef __BIG_ENDIAN
+       compat_sigset_t v;
+       switch (_NSIG_WORDS) {
+       case 4: v.sig[7] = (set->sig[3] >> 32); v.sig[6] = set->sig[3];
+       case 3: v.sig[5] = (set->sig[2] >> 32); v.sig[4] = set->sig[2];
+       case 2: v.sig[3] = (set->sig[1] >> 32); v.sig[2] = set->sig[1];
+       case 1: v.sig[1] = (set->sig[0] >> 32); v.sig[0] = set->sig[0];
+       }
+       return copy_to_user(compat, &v, size) ? -EFAULT : 0;
+ #else
+       return copy_to_user(compat, set, size) ? -EFAULT : 0;
+ #endif
+ }
  
  asmlinkage long compat_sys_migrate_pages(compat_pid_t pid,
                compat_ulong_t maxnode, const compat_ulong_t __user *old_nodes,