mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Aohan Mei" <ljp1205831794@gmail.com>, <bpf@vger.kernel.org>
Cc: <ast@kernel.org>, <daniel@iogearbox.net>, <andrii@kernel.org>,
	<eddyz87@gmail.com>, <memxor@gmail.com>,
	<linux-kernel@vger.kernel.org>,
	"Aohan Mei" <henrymei@tencent.com>,
	"TencentOS Corvus AI" <corvus@tencent.com>,
	<stable@vger.kernel.org>
Subject: Re: [PATCH bpf] bpf: Hash lock addresses in rqspinlock violation reports
Date: Fri, 11 Sep 2026 08:28:07 -0700	[thread overview]
Message-ID: <DLCLDD3KN3WJ.2PUS28BYG2QVK@gmail.com> (raw)
In-Reply-To: <20260901114755.1165703-1-ljp1205831794@gmail.com>

On Tue Sep 1, 2026 at 4:47 AM PDT, Aohan Mei wrote:
> From: Aohan Mei <henrymei@tencent.com>
>
> bpf_prog_report_rqspinlock_violation() prints the attempted lock and
> every held lock with %px, which expands to the raw pointer value.
> The report lands in the program's BPF_STDERR stream, and that stream
> is readable through BPF_PROG_STREAM_READ_BY_FD with no privilege
> check on the read side: prog_stream_read() only validates the fd
> with bpf_prog_get().
>
> Any user with read access to the program fd (a shared fd, a BPF
> token delegation, or an unprivileged child) can therefore read back
> the raw kernel addresses of the rqspinlock objects, which are
> dynamic allocations whose placement depends on KASLR and the slab
> layout.  The verifier-facing log path gates pointer printing on
> allow_ptr_leaks; the stream path has no equivalent gate.
>
> Print the ptr_to_hashval() hash of each address instead, so the
> report still allows correlating the attempted lock with the held
> locks within a boot, without exposing the raw addresses.  Fall back
> to printing 0 if hashing fails.
>
> Fixes: ecec5b5743bf ("bpf: Report rqspinlock deadlocks/timeout to BPF stderr")
> Reported-by: TencentOS Corvus AI <corvus@tencent.com>
> Cc: stable@vger.kernel.org
> Assisted-by: CodeBuddy:Kimi-K3
> Signed-off-by: Aohan Mei <henrymei@tencent.com>
> ---
>  kernel/bpf/rqspinlock.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/bpf/rqspinlock.c b/kernel/bpf/rqspinlock.c
> index 111ec80ea958..5721dc1a9577 100644
> --- a/kernel/bpf/rqspinlock.c
> +++ b/kernel/bpf/rqspinlock.c
> @@ -16,6 +16,7 @@
>  #include <linux/smp.h>
>  #include <linux/bug.h>
>  #include <linux/bpf.h>
> +#include <linux/string.h>
>  #include <linux/err.h>
>  #include <linux/cpumask.h>
>  #include <linux/percpu.h>
> @@ -673,6 +674,7 @@ __bpf_kfunc_start_defs();
>  static void bpf_prog_report_rqspinlock_violation(const char *str, void *lock, bool irqsave)
>  {
>  	struct rqspinlock_held *rqh = this_cpu_ptr(&rqspinlock_held_locks);
> +	unsigned long hashval;
>  	struct bpf_stream_stage ss;
>  	struct bpf_prog *prog;
>  
> @@ -681,10 +683,15 @@ static void bpf_prog_report_rqspinlock_violation(const char *str, void *lock, bo
>  		return;
>  	bpf_stream_stage(ss, prog, BPF_STDERR, ({
>  		bpf_stream_printk(ss, "ERROR: %s for bpf_res_spin_lock%s\n", str, irqsave ? "_irqsave" : "");
> -		bpf_stream_printk(ss, "Attempted lock   = 0x%px\n", lock);
> +		if (ptr_to_hashval(lock, &hashval))
> +			hashval = 0;
> +		bpf_stream_printk(ss, "Attempted lock   = 0x%08lx\n", hashval);

No. This is not necessary.

pw-bot: cr

  reply	other threads:[~2026-09-11 15:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01 11:47 Aohan Mei
2026-09-11 15:28 ` Alexei Starovoitov [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-09-01  4:21 Aohan Mei

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=DLCLDD3KN3WJ.2PUS28BYG2QVK@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=corvus@tencent.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=henrymei@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ljp1205831794@gmail.com \
    --cc=memxor@gmail.com \
    --cc=stable@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®