1. 23 Feb, 2021 23 commits
  2. 19 Feb, 2021 11 commits
  3. 14 Jan, 2021 6 commits
    • Chen Huang's avatar
      riscv/stacktrace: Fix stack output without ra on the stack top · f766f77a
      Chen Huang authored
      When a function doesn't have a callee, then it will not
      push ra into the stack, such as lkdtm_BUG() function,
      
      addi	sp,sp,-16
      sd	s0,8(sp)
      addi	s0,sp,16
      ebreak
      
      The struct stackframe use {fp,ra} to get information from
      stack, if walk_stackframe() with pr_regs, we will obtain
      wrong value and bad stacktrace,
      
      [<ffffffe00066c56c>] lkdtm_BUG+0x6/0x8
      ---[ end trace 18da3fbdf08e25d5 ]---
      
      Correct the next fp and pc, after that, full stacktrace
      shown as expects,
      
      [<ffffffe00066c56c>] lkdtm_BUG+0x6/0x8
      [<ffffffe0008b24a4>] lkdtm_do_action+0x14/0x1c
      [<ffffffe00066c372>] direct_entry+0xc0/0x10a
      [<ffffffe000439f86>] full_proxy_write+0x42/0x6a
      [<ffffffe000309626>] vfs_write+0x7e/0x214
      [<ffffffe00030992a>] ksys_write+0x98/0xc0
      [<ffffffe000309960>] sys_write+0xe/0x16
      [<ffffffe0002014bc>] ret_from_syscall+0x0/0x2
      ---[ end trace 61917f3d9a9fadcd ]---
      Signed-off-by: default avatarChen Huang <chenhuang5@huawei.com>
      Signed-off-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
      Signed-off-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
      f766f77a
    • Kefeng Wang's avatar
      riscv: Improve __show_regs · da401e89
      Kefeng Wang authored
      Show the function symbols of epc and ra to improve the
      readability of crash reports, and align the printing
      formats about the raw epc value.
      Signed-off-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
      Signed-off-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
      da401e89
    • Kefeng Wang's avatar
      riscv: Add dump stack in show_regs · 091b9450
      Kefeng Wang authored
      Like commit 1149aad1 ("arm64: Add dump_backtrace() in show_regs"),
      dump the stack in riscv show_regs as common code expects.
      Reviewed-by: default avatarAtish Patra <atish.patra@wdc.com>
      Signed-off-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
      Signed-off-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
      091b9450
    • Guo Ren's avatar
      riscv: Enable per-task stack canaries · fea2fed2
      Guo Ren authored
      This enables the use of per-task stack canary values if GCC has
      support for emitting the stack canary reference relative to the
      value of tp, which holds the task struct pointer in the riscv
      kernel.
      
      After compare arm64 and x86 implementations, seems arm64's is more
      flexible and readable. The key point is how gcc get the offset of
      stack_canary from gs/el0_sp.
      
      x86: Use a fix offset from gs, not flexible.
      
      struct fixed_percpu_data {
      	/*
      	 * GCC hardcodes the stack canary as %gs:40.  Since the
      	 * irq_stack is the object at %gs:0, we reserve the bottom
      	 * 48 bytes of the irq stack for the canary.
      	 */
      	char            gs_base[40]; // :(
      	unsigned long   stack_canary;
      };
      
      arm64: Use -mstack-protector-guard-offset & guard-reg
      	gcc options:
      	-mstack-protector-guard=sysreg
      	-mstack-protector-guard-reg=sp_el0
      	-mstack-protector-guard-offset=xxx
      
      riscv: Use -mstack-protector-guard-offset & guard-reg
      	gcc options:
      	-mstack-protector-guard=tls
      	-mstack-protector-guard-reg=tp
      	-mstack-protector-guard-offset=xxx
      
       GCC's implementation has been merged:
       commit c931e8d5a96463427040b0d11f9c4352ac22b2b0
       Author: Cooper Qu <cooper.qu@linux.alibaba.com>
       Date:   Mon Jul 13 16:15:08 2020 +0800
      
           RISC-V: Add support for TLS stack protector canary access
      
      In the end, these codes are inserted by gcc before return:
      
      *  0xffffffe00020b396 <+120>:   ld      a5,1008(tp) # 0x3f0
      *  0xffffffe00020b39a <+124>:   xor     a5,a5,a4
      *  0xffffffe00020b39c <+126>:   mv      a0,s5
      *  0xffffffe00020b39e <+128>:   bnez    a5,0xffffffe00020b61c <_do_fork+766>
         0xffffffe00020b3a2 <+132>:   ld      ra,136(sp)
         0xffffffe00020b3a4 <+134>:   ld      s0,128(sp)
         0xffffffe00020b3a6 <+136>:   ld      s1,120(sp)
         0xffffffe00020b3a8 <+138>:   ld      s2,112(sp)
         0xffffffe00020b3aa <+140>:   ld      s3,104(sp)
         0xffffffe00020b3ac <+142>:   ld      s4,96(sp)
         0xffffffe00020b3ae <+144>:   ld      s5,88(sp)
         0xffffffe00020b3b0 <+146>:   ld      s6,80(sp)
         0xffffffe00020b3b2 <+148>:   ld      s7,72(sp)
         0xffffffe00020b3b4 <+150>:   addi    sp,sp,144
         0xffffffe00020b3b6 <+152>:   ret
         ...
      *  0xffffffe00020b61c <+766>:   auipc   ra,0x7f8
      *  0xffffffe00020b620 <+770>:   jalr    -1764(ra) # 0xffffffe000a02f38 <__stack_chk_fail>
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      Signed-off-by: default avatarCooper Qu <cooper.qu@linux.alibaba.com>
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
      fea2fed2
    • Guo Ren's avatar
      riscv: Add support for function error injection · ee55ff80
      Guo Ren authored
      Inspired by the commit 42d038c4 ("arm64: Add support for function
      error injection"), this patch supports function error injection for
      riscv.
      
      This patch mainly support two functions: one is regs_set_return_value()
      which is used to overwrite the return value; the another function is
      override_function_with_return() which is to override the probed
      function returning and jump to its caller.
      
      Test log:
       cd /sys/kernel/debug/fail_function
       echo sys_clone > inject
       echo 100 > probability
       echo 1 > interval
       ls /
      [  313.176875] FAULT_INJECTION: forcing a failure.
      [  313.176875] name fail_function, interval 1, probability 100, space 0, times 1
      [  313.184357] CPU: 0 PID: 87 Comm: sh Not tainted 5.8.0-rc5-00007-g6a758cc #117
      [  313.187616] Call Trace:
      [  313.189100] [<ffffffe0002036b6>] walk_stackframe+0x0/0xc2
      [  313.191626] [<ffffffe00020395c>] show_stack+0x40/0x4c
      [  313.193927] [<ffffffe000556c60>] dump_stack+0x7c/0x96
      [  313.194795] [<ffffffe0005522e8>] should_fail+0x140/0x142
      [  313.195923] [<ffffffe000299ffc>] fei_kprobe_handler+0x2c/0x5a
      [  313.197687] [<ffffffe0009e2ec4>] kprobe_breakpoint_handler+0xb4/0x18a
      [  313.200054] [<ffffffe00020357e>] do_trap_break+0x36/0xca
      [  313.202147] [<ffffffe000201bca>] ret_from_exception+0x0/0xc
      [  313.204556] [<ffffffe000201bbc>] ret_from_syscall+0x0/0x2
      -sh: can't fork: Invalid argument
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      Reviewed-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Cc: Palmer Dabbelt <palmerdabbelt@google.com>
      Cc: Paul Walmsley <paul.walmsley@sifive.com>
      Signed-off-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
      ee55ff80
    • Guo Ren's avatar
      riscv: Add uprobes supported · 74784081
      Guo Ren authored
      This patch adds support for uprobes on riscv architecture.
      
      Just like kprobe, it support single-step and simulate instructions.
      Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
      Reviewed-by: default avatarPekka Enberg <penberg@kernel.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Palmer Dabbelt <palmerdabbelt@google.com>
      Signed-off-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
      74784081