Linux Trace Kernel
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@kernel.org>
To: Andrii Nakryiko <andrii@kernel.org>
Cc: linux-trace-kernel@vger.kernel.org, peterz@infradead.org,
	rostedt@goodmis.org, mhiramat@kernel.org, x86@kernel.org,
	mingo@redhat.com, tglx@linutronix.de,
	linux-kernel@vger.kernel.org, bpf@vger.kernel.org, rihams@fb.com,
	linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v3] perf,x86: avoid missing caller address in stack traces captured in uprobe
Date: Wed, 3 Jul 2024 15:39:27 -0700	[thread overview]
Message-ID: <20240703223927.zby4glzbngjqxemd@treble> (raw)
In-Reply-To: <20240703040203.3368505-1-andrii@kernel.org>

On Tue, Jul 02, 2024 at 09:02:03PM -0700, Andrii Nakryiko wrote:
> @@ -2833,6 +2858,18 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry_ctx *ent
>  
>  	fp = compat_ptr(ss_base + regs->bp);
>  	pagefault_disable();
> +
> +#ifdef CONFIG_UPROBES
> +	/* see perf_callchain_user() below for why we do this */
> +	if (current->utask) {
> +		u32 ret_addr;
> +
> +		if (is_uprobe_at_func_entry(regs, current->utask->auprobe) &&
> +		    !__get_user(ret_addr, (const u32 __user *)regs->sp))

Shouldn't the regs->sp value be checked with __access_ok() before
calling __get_user()?

Also, instead of littering functions with ifdefs it would be better to
abstract this out into a separate function which has an "always return
false" version for !CONFIG_UPROBES.  Then the above could be simplified to
something like:

	...
 	pagefault_disable();

	if (is_uprobe_at_func_entry(regs, current) &&
	    __access_ok(regs->sp, 4) &&
	    !__get_user(ret_addr, (const u32 __user *)regs->sp))
	    	perf_callchain_store(entry, ret_addr);
	...

Also it's good practice to wait at least several days before posting new
versions to avoid spamming reviewers and to give them time to digest
what you've already sent.

-- 
Josh

  reply	other threads:[~2024-07-03 22:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-03  4:02 [PATCH v3] perf,x86: avoid missing caller address in stack traces captured in uprobe Andrii Nakryiko
2024-07-03 22:39 ` Josh Poimboeuf [this message]
2024-07-03 23:26   ` Andrii Nakryiko

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=20240703223927.zby4glzbngjqxemd@treble \
    --to=jpoimboe@kernel.org \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rihams@fb.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=x86@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