Patch "riscv/stacktrace: Fix stack output without ra on the stack top" has been added to the 5.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    riscv/stacktrace: Fix stack output without ra on the stack top

to the 5.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     riscv-stacktrace-fix-stack-output-without-ra-on-the-.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit e92954d051587a06c852db0cb6f3173e9f9f651e
Author: Chen Huang <chenhuang5@xxxxxxxxxx>
Date:   Mon Jan 11 20:40:14 2021 +0800

    riscv/stacktrace: Fix stack output without ra on the stack top
    
    [ Upstream commit f766f77a74f5784d8d4d3c36b1900731f97d08d0 ]
    
    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: Chen Huang <chenhuang5@xxxxxxxxxx>
    Signed-off-by: Kefeng Wang <wangkefeng.wang@xxxxxxxxxx>
    Signed-off-by: Palmer Dabbelt <palmerdabbelt@xxxxxxxxxx>
    Stable-dep-of: 5c3022e4a616 ("riscv: stacktrace: Fixup ftrace_graph_ret_addr retp argument")
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c
index 19e46f4160cc..1a512a24879e 100644
--- a/arch/riscv/kernel/stacktrace.c
+++ b/arch/riscv/kernel/stacktrace.c
@@ -55,9 +55,15 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
 		/* Unwind stack frame */
 		frame = (struct stackframe *)fp - 1;
 		sp = fp;
-		fp = frame->fp;
-		pc = ftrace_graph_ret_addr(current, NULL, frame->ra,
-					   (unsigned long *)(fp - 8));
+		if (regs && (regs->epc == pc) && (frame->fp & 0x7)) {
+			fp = frame->ra;
+			pc = regs->ra;
+		} else {
+			fp = frame->fp;
+			pc = ftrace_graph_ret_addr(current, NULL, frame->ra,
+						   (unsigned long *)(fp - 8));
+		}
+
 	}
 }
 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux