Linux Trace Kernel
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Steven Rostedt" <rostedt@goodmis.org>,
	"Linux Trace Kernel" <linux-trace-kernel@vger.kernel.org>
Subject: Re: [PATCH v7] tracing/probes: Zero out faulted dereferenced fields
Date: Tue, 24 Nov 2026 02:51:12 +0000	[thread overview]
Message-ID: <sashiko-outbox-230424@kernel.org> (raw)
In-Reply-To: <20261123213246.00440bfc@gandalf.local.home>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] tracing/probes: do_probe_mem_read() dereferences NULL in
  stage 3
--

commit fd104aec084b16bdb5ef3c044c9c69e47141c17c
Author: Steven Rostedt <rostedt@goodmis.org>

tracing/probes: Zero out faulted dereferenced fields

This commit zeroes the destination buffer when probe memory reads or
dereferences fail or encounter NULL pointers during probe argument
fetching.

> diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h
> index 8acc0f0ebd7a6..9672474b067b3 100644
> --- a/kernel/trace/trace_probe_tmpl.h
> +++ b/kernel/trace/trace_probe_tmpl.h
[ ... ]
> @@ -133,13 +135,63 @@ process_common_fetch_insn(struct fetch_insn *code, unsigned long *val)
>  	return 0;
>  }
>  
> +/* On failure, zero out the destination */
> +static nokprobe_inline int
> +do_probe_mem_read_user(void *dest, void *src, size_t size)
> +{
> +	int ret;
> +
> +	ret = probe_mem_read_user(dest, src, size);
> +	if (ret < 0)
> +		memset(dest, 0, size);
> +	return ret;
> +}
> +
> +/* On failure, zero out the destination */
> +static nokprobe_inline int
> +do_probe_mem_read(void *dest, void *src, size_t size)
> +{
> +	int ret;
> +
> +	ret = probe_mem_read(dest, src, size);
> +	if (ret < 0)
> +		memset(dest, 0, size);
> +	return ret;
> +}
[ ... ]
> @@ -193,27 +256,30 @@ process_fetch_insn_bottom(struct fetch_insn *code, unsigned long val,
>  		}
>  	}
>  
> +	/* When val is NULL, so should the val + offset */
> +	offset = val ? code->offset : 0;
> +
>  	switch (code->op) {
>  	case FETCH_OP_ST_RAW:
>  		fetch_store_raw(val, code, dest);
>  		break;
>  	case FETCH_OP_ST_MEM:
> -		probe_mem_read(dest, (void *)val + code->offset, code->size);
> +		do_probe_mem_read(dest, (void *)val + offset, code->size);
>  		break;
>  	case FETCH_OP_ST_UMEM:
> -		probe_mem_read_user(dest, (void *)val + code->offset, code->size);
> +		do_probe_mem_read_user(dest, (void *)val + offset, code->size);
>  		break;

[Severity: Medium]
Should do_probe_mem_read() and do_probe_mem_read_user() check for a NULL
src before calling probe_mem_read() and probe_mem_read_user()?

When val is 0 in stage 3 (for example, when prev->mm is NULL in
prev->mm->pgd, where finalize_fetch_insn() turns the final dereference
into FETCH_OP_ST_MEM), offset is set to 0 and (void *)val + offset passes
NULL as src to do_probe_mem_read() or do_probe_mem_read_user().

Because neither helper checks for !src, every NULL pointer hit attempts a
real memory read at virtual address 0x0, raising a hardware page fault on
every event when page 0 is unmapped.  If address 0x0 is readable, the
read succeeds instead of zeroing dest: on s390 it copies kernel lowcore
bytes from 0x0, and on CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
architectures probe_mem_read() sees (unsigned long)src < TASK_SIZE and
reads user-space address 0x0 if mapped:

kernel/trace/trace_probe_kernel.h:probe_mem_read() {
#ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
	if ((unsigned long)src < TASK_SIZE)
		return probe_mem_read_user(dest, src, size);
#endif
	return copy_from_kernel_nofault(dest, src, size);
}

Also, in process_fetch_insn_bottom(), offset = val ? code->offset : 0 is
computed twice in stage 3, and in stage 2 offset is only used inside
if (val) blocks where code->offset can be used directly.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123213246.00440bfc@gandalf.local.home?part=1

      reply	other threads:[~2026-11-24  2:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  2:32 [PATCH v7] tracing/probes: Zero out faulted dereferenced fields Steven Rostedt
2026-11-24  2:51 ` 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-230424@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox