Skip to content

[PW_SID:1123455] riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr()#2243

Closed
linux-riscv-bot wants to merge 3 commits into
workflow__riscv__fixesfrom
pw1123455
Closed

[PW_SID:1123455] riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr()#2243
linux-riscv-bot wants to merge 3 commits into
workflow__riscv__fixesfrom
pw1123455

Conversation

@linux-riscv-bot

Copy link
Copy Markdown

PR for series 1123455 applied to workflow__riscv__fixes

Name: riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr()
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1123455
Version: 1

liutgnu and others added 3 commits July 6, 2026 18:24
A NULL pointer dereference issue is noticed in riscv's machine_kexec_prepare(),
where image->segment[i].buf might be NULL and copied unchecked.

The NULL buf comes from ima_add_kexec_buffer(), where kbuf is added by
kexec_add_buffer(), but kbuf.buffer is NULL, then it is copied without
a check in machine_kexec_prepare():

  kexec_file_load
    -> kimage_file_alloc_init()
       -> kimage_file_prepare_segments()
          -> ima_add_kexec_buffer()
             -> kexec_add_buffer()
    -> machine_kexec_prepare()
       -> memcpy()

Address this by adding a check before the data copy attempt.

Fixes: b7fb4d7 ("RISC-V: use memcpy for kexec_file mode")
Cc: stable@vger.kernel.org
Closes: https://lore.kernel.org/kexec/CAO7dBbVftLUhd2qrh7hmijTB3PEPfZAhykCGqEfrPoOcSrrj-w@mail.gmail.com/
Acked-by: Baoquan He <bhe@redhat.com>
Acked-by: Pratyush Yadav <pratyush@kernel.org>
Reviewed-by: Nutty Liu <nutty.liu@hotmail.com>
Signed-off-by: Tao Liu <ltao@redhat.com>
Link: https://patch.msgid.link/20260705232706.30265-2-ltao@redhat.com
Signed-off-by: Paul Walmsley <pjw@kernel.org>
When dump_backtrace() is called with a NULL task argument, and the
call stack contains functions that are being traced,
walk_stackframe() eventually calls ftrace_graph_ret_addr() with the
NULL task pointer, which results in a NULL pointer dereference when
accessing task->curr_ret_stack.

Fix this by assigning the task pointer to the current task in
walk_stackframe() when it is NULL, keeping the behavior consistent
with other architectures.

Fixes: ecbf894 ("riscv: Fix ftrace_graph_ret_addr() to use the correct task pointer")
Reviewed-by: Shengming Hu <hu.shengming@zte.com.cn>
Reviewed-by: Rui Gao <gao.rui@zte.com.cn>
Reviewed-by: Luo Haiyang <luo.haiyang@zte.com.cn>
Reviewed-by: Run Zhang <zhang.run@zte.com.cn>
Signed-off-by: Anmeng Zhang <zhang.anmeng@zte.com.cn>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr()"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 143.02 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr()"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1420.28 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr()"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1723.70 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr()"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 26.08 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr()"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 27.77 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr()"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 1.84 seconds
Result: WARNING
Output:

CHECK: Comparison to NULL could be written "!task"
#36: FILE: arch/riscv/kernel/stacktrace.c:55:
+	if (task == NULL)

total: 0 errors, 0 warnings, 1 checks, 15 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

Commit 06d7d8ab74d7 ("riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr()") has style problems, please review.

NOTE: Ignored message types: ALLOC_SIZEOF_STRUCT CAMELCASE COMMIT_LOG_LONG_LINE GIT_COMMIT_ID MACRO_ARG_REUSE NO_AUTHOR_SIGN_OFF

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.
total: 0 errors, 0 warnings, 1 checks, 15 lines checked
CHECK: Comparison to NULL could be written "!task"


@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr()"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 88.11 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr()"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr()"
kdoc
Desc: Detects for kdoc errors
Duration: 0.86 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr()"
module-param
Desc: Detect module_param changes
Duration: 0.25 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr()"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.28 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr()"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.31 seconds
Result: PASS

@linux-riscv-bot
linux-riscv-bot force-pushed the workflow__riscv__fixes branch 7 times, most recently from f54dc6c to f61148d Compare July 15, 2026 03:51
@linux-riscv-bot
linux-riscv-bot force-pushed the workflow__riscv__fixes branch 2 times, most recently from 56b6f30 to 8ca72ef Compare July 15, 2026 17:25
@linux-riscv-bot
linux-riscv-bot deleted the pw1123455 branch July 16, 2026 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants