1. 09 May, 2019 1 commit
    • Michael Ellerman's avatar
      powerpc/64s: Use early_mmu_has_feature() in set_kuap() · 8150a153
      Michael Ellerman authored
      When implementing the KUAP support on Radix we fixed one case where
      mmu_has_feature() was being called too early in boot via
      __put_user_size().
      
      However since then some new code in linux-next has created a new path
      via which we can end up calling mmu_has_feature() too early.
      
      On P9 this leads to crashes early in boot if we have both PPC_KUAP and
      CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG enabled. Our early boot code
      calls printk() which calls probe_kernel_read(), that does a
      __copy_from_user_inatomic() which calls into set_kuap() and that uses
      mmu_has_feature().
      
      At that point in boot we haven't patched MMU features yet so the debug
      code in mmu_has_feature() complains, and calls printk(). At that point
      we recurse, eg:
      
        ...
        dump_stack+0xdc
        probe_kernel_read+0x1a4
        check_pointer+0x58
        ...
        printk+0x40
        dump_stack_print_info+0xbc
        dump_stack+0x8
        probe_kernel_read+0x1a4
        probe_kernel_read+0x19c
        check_pointer+0x58
        ...
        printk+0x40
        cpufeatures_process_feature+0xc8
        scan_cpufeatures_subnodes+0x380
        of_scan_flat_dt_subnodes+0xb4
        dt_cpu_ftrs_scan_callback+0x158
        of_scan_flat_dt+0xf0
        dt_cpu_ftrs_scan+0x3c
        early_init_devtree+0x360
        early_setup+0x9c
      
      And so on for infinity, symptom is a dead system.
      
      Even more fun is what happens when using the hash MMU (ie. p8 or p9
      with Radix disabled), and when we don't have
      CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG enabled. With the debug disabled
      we don't check if static keys have been initialised, we just rely on
      the jump label. But the jump label defaults to true so we just whack
      the AMR even though Radix is not enabled.
      
      Clearing the AMR is fine, but after we've done the user copy we write
      (0b11 << 62) into AMR. When using hash that makes all pages with key
      zero no longer readable or writable. All kernel pages implicitly have
      key zero, and so all of a sudden the kernel can't read or write any of
      its memory. Again dead system.
      
      In the medium term we have several options for fixing this.
      probe_kernel_read() doesn't need to touch AMR at all, it's not doing a
      user access after all, but it uses __copy_from_user_inatomic() just
      because it's easy, we could fix that.
      
      It would also be safe to default to not writing to the AMR during
      early boot, until we've detected features. But it's not clear that
      flipping all the MMU features to static_key_false won't introduce
      other bugs.
      
      But for now just switch to early_mmu_has_feature() in set_kuap(), that
      avoids all the problems with jump labels. It adds the overhead of a
      global lookup and test, but that's probably trivial compared to the
      writes to the AMR anyway.
      
      Fixes: 890274c2 ("powerpc/64s: Implement KUAP for Radix MMU")
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Reviewed-by: default avatarRussell Currey <ruscur@russell.cc>
      8150a153
  2. 07 May, 2019 1 commit
    • Rick Lindsley's avatar
      powerpc/book3s/64: check for NULL pointer in pgd_alloc() · f3935626
      Rick Lindsley authored
      When the memset code was added to pgd_alloc(), it failed to consider
      that kmem_cache_alloc() can return NULL. It's uncommon, but not
      impossible under heavy memory contention. Example oops:
      
        Unable to handle kernel paging request for data at address 0x00000000
        Faulting instruction address: 0xc0000000000a4000
        Oops: Kernel access of bad area, sig: 11 [#1]
        LE SMP NR_CPUS=2048 NUMA pSeries
        CPU: 70 PID: 48471 Comm: entrypoint.sh Kdump: loaded Not tainted 4.14.0-115.6.1.el7a.ppc64le #1
        task: c000000334a00000 task.stack: c000000331c00000
        NIP:  c0000000000a4000 LR: c00000000012f43c CTR: 0000000000000020
        REGS: c000000331c039c0 TRAP: 0300   Not tainted  (4.14.0-115.6.1.el7a.ppc64le)
        MSR:  800000010280b033 <SF,VEC,VSX,EE,FP,ME,IR,DR,RI,LE,TM[E]>  CR: 44022840  XER: 20040000
        CFAR: c000000000008874 DAR: 0000000000000000 DSISR: 42000000 SOFTE: 1
        ...
        NIP [c0000000000a4000] memset+0x68/0x104
        LR [c00000000012f43c] mm_init+0x27c/0x2f0
        Call Trace:
          mm_init+0x260/0x2f0 (unreliable)
          copy_mm+0x11c/0x638
          copy_process.isra.28.part.29+0x6fc/0x1080
          _do_fork+0xdc/0x4c0
          ppc_clone+0x8/0xc
        Instruction dump:
        409e000c b0860000 38c60002 409d000c 90860000 38c60004 78a0d183 78a506a0
        7c0903a6 41820034 60000000 60420000 <f8860000> f8860008 f8860010 f8860018
      
      Fixes: fc5c2f4a ("powerpc/mm/hash64: Zero PGD pages on allocation")
      Cc: stable@vger.kernel.org # v4.16+
      Signed-off-by: default avatarRick Lindsley <ricklind@vnet.linux.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      f3935626
  3. 06 May, 2019 6 commits
  4. 02 May, 2019 32 commits