All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yifan Feng" <evanfengff@gmail.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] rethook: link the node before replacing the return address
Date: Fri, 27 Nov 2026 18:53:03 +0000	[thread overview]
Message-ID: <sashiko-outbox-238117@kernel.org> (raw)
In-Reply-To: <20261127184037.71903-1-evanfengff@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] rethook: missing compiler barriers in rethook_hook() and
  arch_rethook_prepare()
--

commit 8555f1c8da702428f75ba61ef07accb91b4115a4
Author: Yifan Feng <evanfengff@gmail.com>

rethook: link the node before replacing the return address

This commit links the rethook_node into current->rethooks with sentinel
values before calling arch_rethook_prepare(), so that an interrupt or NMI
stack unwinder never observes the trampoline return address without a
corresponding node on the list.

> diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c
> index 87a27f3aa4a61..c0d89720e1a8b 100644
> --- a/kernel/trace/rethook.c
> +++ b/kernel/trace/rethook.c
> @@ -196,8 +196,16 @@ NOKPROBE_SYMBOL(rethook_try_get);
>   */
>  void rethook_hook(struct rethook_node *node, struct pt_regs *regs, bool mcount)
>  {
> -	arch_rethook_prepare(node, regs, mcount);
> +	/*
> +	 * Link the node before the return address is replaced, so that a
> +	 * stack unwinder never finds the trampoline address without its node.
> +	 * Until arch_rethook_prepare() fills the node in, make it one that
> +	 * rethook_find_ret_addr() skips.
> +	 */
> +	node->ret_addr = (unsigned long)arch_rethook_trampoline;
> +	node->frame = 0;
>  	__llist_add(&node->llist, &current->rethooks);
> +	arch_rethook_prepare(node, regs, mcount);
>  }
>  NOKPROBE_SYMBOL(rethook_hook);

[Severity: Medium]
Do these stores and the updates in arch_rethook_prepare() need compiler
barriers to protect same-CPU interrupt and NMI unwinders?

__llist_add() expands to plain stores:

include/linux/llist.h:__llist_add_batch() {
	new_last->next = head->first;
	head->first = new_first;
}

Because node comes from an objpool and rethook_recycle() does not clear
its fields, reordering current->rethooks.first ahead of the stores to
node->ret_addr, node->frame, or node->llist.next exposes stale values to
rethook_find_ret_addr().  With LTO, arch_rethook_prepare() can also be
inlined into rethook_hook(), allowing the compiler to eliminate the
sentinel stores to node->ret_addr and node->frame as dead stores before
they are overwritten.

In addition, because node is now already visible on current->rethooks
when arch_rethook_prepare() runs, arch_rethook_prepare() itself needs a
barrier() before replacing the return address with
arch_rethook_trampoline so that the real node->ret_addr and node->frame
are committed first:

arch/x86/kernel/rethook.c:arch_rethook_prepare() {
	...
	rh->ret_addr = stack[0];
	rh->frame = regs->sp;

	/* Replace the return addr with trampoline addr */
	stack[0] = (unsigned long) arch_rethook_trampoline;
}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127184037.71903-1-evanfengff@gmail.com?part=1

      reply	other threads:[~2026-11-27 18:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 18:40 [PATCH] rethook: link the node before replacing the return address Yifan Feng
2026-11-27 18:53 ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-238117@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=evanfengff@gmail.com \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.