All of lore.kernel.org
 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 v6] tracing/probes: Zero out faulted dereferenced fields
Date: Mon, 23 Nov 2026 21:48:08 +0000	[thread overview]
Message-ID: <sashiko-outbox-230090@kernel.org> (raw)
In-Reply-To: <20261123163027.4d101385@gandalf.local.home>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] tracing/probes: undeclared __dest in do_fetch_store_string*()
- [High] tracing/probes: FETCH_OP_ST_SYMSTR size mismatch when val is 0
- [Medium] tracing/probes: NULL pointer read in do_probe_mem_read() at
  stage 3
--

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

tracing/probes: Zero out faulted dereferenced fields

This commit zeroes the destination buffer when probe memory reads fail and
continues past NULL or faulted dereferences in process_fetch_insn_bottom()
so that failed probe fields are zeroed in the ring buffer.

> diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h
> index 8db12f758fdae..de43966e40e7d 100644
> --- a/kernel/trace/trace_probe_tmpl.h
> +++ b/kernel/trace/trace_probe_tmpl.h
> @@ -121,13 +121,59 @@ 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;
> +}
> +
> +static nokprobe_inline int
> +do_fetch_store_string(unsigned long addr, void *dest, void *base)
> +{
> +	/* NULL addr gets zero size string */
> +	if (!addr) {
> +		*(u32 *)dest = make_data_loc(0, __dest - base);
> +		return 0;
> +	}
> +	return fetch_store_string(addr, dest, base);
> +}
> +
> +static nokprobe_inline int
> +do_fetch_store_string_user(unsigned long addr, void *dest, void *base)
> +{
> +	/* NULL addr gets zero size string */
> +	if (!addr) {
> +		*(u32 *)dest = make_data_loc(0, __dest - base);
> +		return 0;
> +	}
> +	return fetch_store_string_user(addr, dest, base);
> +}

[Severity: High]
Does this fail to build because __dest is undeclared in both
do_fetch_store_string() and do_fetch_store_string_user()?

[ ... ]

> @@ -161,19 +212,25 @@ process_fetch_insn_bottom(struct fetch_insn *code, unsigned long val,
>  
>  	s3 = code;
>  stage3:
> +	/*
> +	 * Once val is zero, it is pointing to NULL. Any new dereference is
> +	 * also treated as a NULL pointer.
> +	 */
> +	offset = val ? code->offset : 0;
> +
>  	/* 3rd stage: store value to buffer */
>  	if (unlikely(!dest)) {
>  		switch (code->op) {
>  		case FETCH_OP_ST_STRING:
> -			ret = fetch_store_strlen(val + code->offset);
> +			ret = val ? fetch_store_strlen(val + offset) : 0;
>  			code++;
>  			goto array;
>  		case FETCH_OP_ST_USTRING:
> -			ret = fetch_store_strlen_user(val + code->offset);
> +			ret = val ? fetch_store_strlen_user(val + offset) : 0;
>  			code++;
>  			goto array;
>  		case FETCH_OP_ST_SYMSTR:
> -			ret = fetch_store_symstrlen(val + code->offset);
> +			ret = val ? fetch_store_symstrlen(val + offset) : 0;
>  			code++;
>  			goto array;
>  		default:
> @@ -181,27 +238,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]
When val is 0 in stage 3, offset is forced to 0, so FETCH_OP_ST_MEM and
FETCH_OP_ST_UMEM pass src == NULL to do_probe_mem_read() and
do_probe_mem_read_user().  Should those helpers (or these call sites)
check for a NULL address and memset(dest, 0, size) directly instead of
reading from virtual address 0x0?

On s390, virtual address 0x0 is mapped to struct lowcore, so
copy_from_kernel_nofault() succeeds and copies lowcore bytes into the
ring buffer instead of zeroing the field.  On architectures with
CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE, probe_mem_read() redirects
src == NULL (< TASK_SIZE) to probe_mem_read_user(), reading user address
0x0 if mapped or taking a page fault on every NULL dereference.

>  	case FETCH_OP_ST_STRING:
>  		loc = *(u32 *)dest;
> -		ret = fetch_store_string(val + code->offset, dest, base);
> +		ret = do_fetch_store_string(val + offset, dest, base);
>  		break;
>  	case FETCH_OP_ST_USTRING:
>  		loc = *(u32 *)dest;
> -		ret = fetch_store_string_user(val + code->offset, dest, base);
> +		ret = do_fetch_store_string_user(val + offset, dest, base);
>  		break;
>  	case FETCH_OP_ST_SYMSTR:
>  		loc = *(u32 *)dest;
> -		ret = fetch_store_symstring(val + code->offset, dest, base);
> +		ret = fetch_store_symstring(val + offset, dest, base);
>  		break;

[Severity: High]
Can FETCH_OP_ST_SYMSTR write past the end of the ring buffer entry when
val is 0?

During the sizing pass (!dest), FETCH_OP_ST_SYMSTR now returns 0 when val
is 0, reserving 0 bytes for this argument.  During the store pass,
store_trace_args() sets *dl = make_data_loc(maxlen, dyndata - base) with
the total remaining maxlen across all dynamic arguments, and
FETCH_OP_ST_SYMSTR still calls fetch_store_symstring(0, dest, base):

kernel/trace/trace_probe_tmpl.h:fetch_store_symstring() {
	int maxlen = get_loc_len(*(u32 *)dest);
	void *__dest;

	if (unlikely(!maxlen))
		return -ENOMEM;

	__dest = get_loc_data(dest, base);

	return sprint_symbol(__dest, addr);
}

If a later dynamic argument in the same probe reserved 1 to 3 bytes,
maxlen is non-zero and sprint_symbol(__dest, 0) writes 4 bytes ("0x0\0")
into __dest and returns 3, overflowing the reserved ring buffer space and
underflowing maxlen in store_trace_args() for the next dynamic argument.

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

  reply	other threads:[~2026-11-23 21:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 21:30 [PATCH v6] tracing/probes: Zero out faulted dereferenced fields Steven Rostedt
2026-11-23 21:48 ` sashiko-bot [this message]
2026-11-24  2:27   ` Steven Rostedt

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-230090@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 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.