mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Vincent Donnefort <vdonnefort@google.com>,
	Fuad Tabba <fuad.tabba@linux.dev>
Subject: [for-linus] tracing: Fix for 7.2
Date: Wed, 15 Jul 2026 12:33:11 -0400	[thread overview]
Message-ID: <20260715123311.1ea3aeaa@gandalf.local.home> (raw)


tracing fix for 7.2:

- Move rb_desc->nr_page_va before updating dynamic array

  The rb_descr->page_va is a dynamic array counted by nr_page_va. But the
  updating of the page_va[] is done before the nr_page_va is incremented
  causing a build with CONFIG_UBSAN_BOUNDS to flag it as an overflow.

  Move the increment of the counted by value before the array element is
  updated.


  git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace/fixes

Head SHA1: 1d867ac69846d212a462d899603b4ac8664a9a78


Fuad Tabba (1):
      tracing/remotes: Fix page_va[] access before counter update in trace_remote_alloc_buffer()

----
 kernel/trace/trace_remote.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
---------------------------
commit 1d867ac69846d212a462d899603b4ac8664a9a78
Author: Fuad Tabba <fuad.tabba@linux.dev>
Date:   Mon Jul 13 08:28:23 2026 +0100

    tracing/remotes: Fix page_va[] access before counter update in trace_remote_alloc_buffer()
    
    page_va[] is annotated __counted_by(nr_page_va), so nr_page_va must
    cover an index before that element is accessed. The allocation loop
    writes page_va[id] while nr_page_va is still id and increments it only
    afterwards, so every write is one element past the declared count.
    
    The store is out of bounds with respect to the annotation: a build with
    CONFIG_UBSAN_BOUNDS on a toolchain that honours __counted_by
    (clang >= 20.1, gcc >= 15.1) flags it as an array-index overflow.
    
    Increment nr_page_va before writing the element it now covers. A failed
    allocation then leaves the slot counted but NULL; the error path frees
    it with free_page(0), which is a no-op.
    
    Link: https://patch.msgid.link/20260713072823.2668323-1-fuad.tabba@linux.dev
    Fixes: 96e43537af546 ("tracing: Introduce trace remotes")
    Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
    Reviewed-by: Vincent Donnefort <vdonnefort@google.com>
    Tested-by: Vincent Donnefort <vdonnefort@google.com>
    Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

diff --git a/kernel/trace/trace_remote.c b/kernel/trace/trace_remote.c
index 0f6ef5c36d84..ef42d9c38b37 100644
--- a/kernel/trace/trace_remote.c
+++ b/kernel/trace/trace_remote.c
@@ -1004,11 +1004,10 @@ int trace_remote_alloc_buffer(struct trace_buffer_desc *desc, size_t desc_size,
 		desc->nr_cpus++;
 
 		for (id = 0; id < nr_pages; id++) {
+			rb_desc->nr_page_va++;
 			rb_desc->page_va[id] = (unsigned long)__get_free_page(GFP_KERNEL);
 			if (!rb_desc->page_va[id])
 				goto err;
-
-			rb_desc->nr_page_va++;
 		}
 		rb_desc = __next_ring_buffer_desc(rb_desc);
 	}

                 reply	other threads:[~2026-07-15 16:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260715123311.1ea3aeaa@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=fuad.tabba@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=vdonnefort@google.com \
    /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®