From nobody Fri Dec 19 21:47:59 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFC71135418 for ; Wed, 6 Mar 2024 18:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750509; cv=none; b=Y5RCXMiWKRdH4UkinUOdRX6HSU+Pf7raG/Ije492UtoMRblrxGyrI42FDKGGYkYfjhD/IJgTPs7+AlUqB4AAyNTnrdfjGqEgKiWeqefWpP+sMBjuHGWtR0iY81iVok50LyjEae2yRJ4c5sS721FupWj9mo5ffYT4QbRgHTVJ9/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750509; c=relaxed/simple; bh=X4WfEJ6vv6eukyGzEmI+iPFGtD8Sbu7/bUkHDWL7TCM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=gmjT+K+BOjBkkm8aX1gYEnX9Z07UFKtREDLPHEruFeTG6tS2VyIVnnF2gSnKZztL6f5JQOdMw6JOVz4u/bVhTw3JNkHQACCJ2Mhp1vItmRAVogWnPhj/VE/yxCRbrBv44P2xu/gwI4m8GqB29MeI5h/84IucMSH0mkPOsU0CXEI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65F66C433F1; Wed, 6 Mar 2024 18:41:49 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rhwEw-00000000Y9k-2X9y; Wed, 06 Mar 2024 13:43:42 -0500 Message-ID: <20240306184342.463314544@goodmis.org> User-Agent: quilt/0.67 Date: Wed, 06 Mar 2024 13:42:45 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Linus Torvalds , Sachin Sant Subject: [for-linus][PATCH 1/3] tracing: Remove precision vsnprintf() check from print event References: <20240306184244.754263547@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" This reverts 60be76eeabb3d ("tracing: Add size check when printing trace_marker output"). The only reason the precision check was added was because of a bug that miscalculated the write size of the string into the ring buffer and it truncated it removing the terminating nul byte. On reading the trace it crashed the kernel. But this was due to the bug in the code that happened during development and should never happen in practice. If anything, the precision can hide bugs where the string in the ring buffer isn't nul terminated and it will not be checked. Link: https://lore.kernel.org/all/C7E7AF1A-D30F-4D18-B8E5-AF1EF58004F5@linu= x.ibm.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240227125706.04279ac2@ga= ndalf.local.home Link: https://lore.kernel.org/all/20240302111244.3a1674be@gandalf.local.hom= e/ Link: https://lore.kernel.org/linux-trace-kernel/20240304174341.2a561d9f@ga= ndalf.local.home Cc: Masami Hiramatsu Cc: Linus Torvalds Fixes: 60be76eeabb3d ("tracing: Add size check when printing trace_marker o= utput") Reported-by: Sachin Sant Tested-by: Sachin Sant Reviewed-by: Mathieu Desnoyers Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_output.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index 3e7fa44dc2b2..d8b302d01083 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -1587,12 +1587,11 @@ static enum print_line_t trace_print_print(struct t= race_iterator *iter, { struct print_entry *field; struct trace_seq *s =3D &iter->seq; - int max =3D iter->ent_size - offsetof(struct print_entry, buf); =20 trace_assign_type(field, iter->ent); =20 seq_print_ip_sym(s, field->ip, flags); - trace_seq_printf(s, ": %.*s", max, field->buf); + trace_seq_printf(s, ": %s", field->buf); =20 return trace_handle_return(s); } @@ -1601,11 +1600,10 @@ static enum print_line_t trace_print_raw(struct tra= ce_iterator *iter, int flags, struct trace_event *event) { struct print_entry *field; - int max =3D iter->ent_size - offsetof(struct print_entry, buf); =20 trace_assign_type(field, iter->ent); =20 - trace_seq_printf(&iter->seq, "# %lx %.*s", field->ip, max, field->buf); + trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf); =20 return trace_handle_return(&iter->seq); } --=20 2.43.0 From nobody Fri Dec 19 21:47:59 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFACF13BAF5 for ; Wed, 6 Mar 2024 18:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750509; cv=none; b=CZ1NFILpvLuU/OJTD14t96odUZ4fO+RWjusEokW8qBs8BfIpTkI5HPYT/kiaengPVeA4VCTfLDMgfDrsspWSEV635lWd1ec3lEuh6x9hoAQJARGPF0eDJrJsdK8latAXHIEmPRHev+U07qRo/CYCpacHz+wd8ZlOs+rIl5+xN/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750509; c=relaxed/simple; bh=gvvazBn6Ji928ngeVXDVmIWNh1/O7Kz/cGCBfkdeFE8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=B8nbq5SVxFLjQne8NeC0+8Pj0gOsMXlWAcbWh3g+DjivRCfjOZPxMtj/DMONvHDZmdBaIYCjI7a+ZfWrzQm/nWHAVNvn3+UmlBLYieE3XN67x5MDkHPIsfKr2lStKoQCD5jd5Zz8sP0y1BAghP4gx9e7hPOIlw/6x01viEzSnis= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8BE4CC433A6; Wed, 6 Mar 2024 18:41:49 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rhwEw-00000000YAE-3DPw; Wed, 06 Mar 2024 13:43:42 -0500 Message-ID: <20240306184342.625779901@goodmis.org> User-Agent: quilt/0.67 Date: Wed, 06 Mar 2024 13:42:46 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Linus Torvalds , Sachin Sant Subject: [for-linus][PATCH 2/3] tracing: Limit trace_seq size to just 8K and not depend on architecture PAGE_SIZE References: <20240306184244.754263547@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" The trace_seq buffer is used to print out entire events. It's typically set to PAGE_SIZE * 2 as there's some events that can be quite large. As a side effect, writes to trace_marker is limited by both the size of the trace_seq buffer as well as the ring buffer's sub-buffer size (which is a power of PAGE_SIZE). By limiting the trace_seq size, it also limits the size of the largest string written to trace_marker. trace_seq does not need to be dependent on PAGE_SIZE like the ring buffer sub-buffers need to be. Hard code it to 8K which is PAGE_SIZE * 2 on most architectures. This will also limit the size of trace_marker on those architectures with greater than 4K PAGE_SIZE. Link: https://lore.kernel.org/all/20240302111244.3a1674be@gandalf.local.hom= e/ Link: https://lore.kernel.org/linux-trace-kernel/20240304191342.56fb1087@ga= ndalf.local.home Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Linus Torvalds Cc: Sachin Sant Signed-off-by: Steven Rostedt (Google) --- include/linux/trace_seq.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/linux/trace_seq.h b/include/linux/trace_seq.h index 9ec229dfddaa..1ef95c0287f0 100644 --- a/include/linux/trace_seq.h +++ b/include/linux/trace_seq.h @@ -9,9 +9,15 @@ /* * Trace sequences are used to allow a function to call several other func= tions * to create a string of data to use. + * + * Have the trace seq to be 8K which is typically PAGE_SIZE * 2 on + * most architectures. The TRACE_SEQ_BUFFER_SIZE (which is + * TRACE_SEQ_SIZE minus the other fields of trace_seq), is the + * max size the output of a trace event may be. */ =20 -#define TRACE_SEQ_BUFFER_SIZE (PAGE_SIZE * 2 - \ +#define TRACE_SEQ_SIZE 8192 +#define TRACE_SEQ_BUFFER_SIZE (TRACE_SEQ_SIZE - \ (sizeof(struct seq_buf) + sizeof(size_t) + sizeof(int))) =20 struct trace_seq { --=20 2.43.0 From nobody Fri Dec 19 21:47:59 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F62C13E7C5 for ; Wed, 6 Mar 2024 18:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750510; cv=none; b=P/A1ABuMKsnklXwGoEMSOSlvjodTJDcHUR1f/n228Ab+KR5vZgP8lXxtkudaz6cMoQfNbsloe7pmG6+R/5kq4Dk0fe0BeYZIDs0Z7oNny/T89AtrdjPMo7gKmkOInywaCkNYG4qQeHRgr8uNh87P0VXP/joGbBzgCKEmjj/UPYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750510; c=relaxed/simple; bh=M32KOXv/AFVR6xfmKfYjkG0waeE8jfIiCibplogrfB4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=gHHZipvNYuqWQbS+ZI6+9WoFI2by2g15n68C8TrRvKvOOABJGvVTYCz9vNivEoKYvVdc6g/231qKALbw7VDxicSYpvXp2kAbmXLkWFtBq1w+/66NRJKLjyw5GUPdq/dj6Yhw0NtNwhKs7qEvUNcpmz+yKXeJh71xndo4m74mR1M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFC45C43390; Wed, 6 Mar 2024 18:41:49 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rhwEw-00000000YAi-3uCp; Wed, 06 Mar 2024 13:43:42 -0500 Message-ID: <20240306184342.788071416@goodmis.org> User-Agent: quilt/0.67 Date: Wed, 06 Mar 2024 13:42:47 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Linus Torvalds Subject: [for-linus][PATCH 3/3] tracing: Limit trace_marker writes to just 4K References: <20240306184244.754263547@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" Limit the max print event of trace_marker to just 4K string size. This must also be less than the amount that can be held by a trace_seq along with the text that is before the output (like the task name, PID, CPU, state, etc). As trace_seq is made to handle large events (some greater than 4K). Make the max size of a trace_marker write event be 4K which is guaranteed to fit in the trace_seq buffer. Link: https://lore.kernel.org/linux-trace-kernel/20240304223433.4ba47dff@ga= ndalf.local.home Suggested-by: Linus Torvalds Reviewed-by: Mathieu Desnoyers Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 8198bfc54b58..d16b95ca58a7 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -7293,6 +7293,8 @@ tracing_free_buffer_release(struct inode *inode, stru= ct file *filp) return 0; } =20 +#define TRACE_MARKER_MAX_SIZE 4096 + static ssize_t tracing_mark_write(struct file *filp, const char __user *ubuf, size_t cnt, loff_t *fpos) @@ -7320,6 +7322,9 @@ tracing_mark_write(struct file *filp, const char __us= er *ubuf, if ((ssize_t)cnt < 0) return -EINVAL; =20 + if (cnt > TRACE_MARKER_MAX_SIZE) + cnt =3D TRACE_MARKER_MAX_SIZE; + meta_size =3D sizeof(*entry) + 2; /* add '\0' and possible '\n' */ again: size =3D cnt + meta_size; @@ -7328,11 +7333,6 @@ tracing_mark_write(struct file *filp, const char __u= ser *ubuf, if (cnt < FAULTED_SIZE) size +=3D FAULTED_SIZE - cnt; =20 - if (size > TRACE_SEQ_BUFFER_SIZE) { - cnt -=3D size - TRACE_SEQ_BUFFER_SIZE; - goto again; - } - buffer =3D tr->array_buffer.buffer; event =3D __trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, tracing_gen_ctx()); --=20 2.43.0