Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1317083lqg; Sun, 3 Mar 2024 05:02:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWkGSuC8xMRpXwTXAgqIqSYSlDoVjwnch9nYjhXuoAPQins2phz6Gxv84gSr2p1l2whM++fOziUnCU3eF6R8tDUEDJVwKKLyrkwptLWpw== X-Google-Smtp-Source: AGHT+IFIy+rP9k8I9wsWo7tUxy7RDAh7f1uCoeMzyur3bbqMACjXUaGxpEgVKmMKZYc8LZWSMhQc X-Received: by 2002:a05:6a00:1950:b0:6e5:5de9:146c with SMTP id s16-20020a056a00195000b006e55de9146cmr7430363pfk.14.1709470945237; Sun, 03 Mar 2024 05:02:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709470945; cv=pass; d=google.com; s=arc-20160816; b=HAf96KyUY+It6F98wLEJlUNCoY5E0NFjQneuSBTqKabTB29oG1uH+drL4Nfm8wgmgp ZwhGjDRQi8dCo+Yrc0k6533v6uNbvlftSMbRwsFaqWCx5zK9AEhzeAtOd+5M97McLCkY NAmRV0YRHhy3BUuZ7tXev79hklLQni4jhhZa/d4vTaVGzBEmsLR2EvN9ylzVOW0LpMEA Ky0oeC69FQ17uV/NxLcoWWDVVoZ72kYytBnXycxMoPapzN8Ww8ft23NkymZhywTdfljM QBFuhkFtpHFEH3Ef2Sx+ScJuS2Z6cOH4/1NH7qhgvMkbfaljrLlUhHnj3KNeUWcGqJQ/ rAUA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=hzx/uhs7HNjp+E7u5TS5uMmLzJxu7lBJqHl/HXXz70E=; fh=Z4tsOB/IV38gOyR2qPehPYRd6/PjJOdZwylA30ksxfw=; b=GSPjg6H1AbwL14IRGHczQphbuciFo2iwq5cYRq6eYrTDd/lskGajK/RWpJmjQlPmux E5TAO5fW5PaAvXd72hU0jN1Ptvcfc6EAzTtyypQiXjEl9/xhhsKor4kEsDipAxTomuo8 RZbQ2FutaiFUwfuRZttHUkHG9bqRt9tFv6RuCJV8X0b2vwHuEJDhk1YOaid3h+B/MNNv GesOE8TRnQfA68h4CiczmugtneuNXIUEKSwXfbwMjQ4Glzd3LO4YbnLfiP4jfUKsai9w a/QtzP1pVfGRD8Jc8UARgwWsKrRNrp7/7w+2SFn0V/tO1PyF0N3nWcQeqEOvfdrA32fy VNLw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-89740-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89740-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id h7-20020a056a00000700b006e13cdd21b5si6711050pfk.207.2024.03.03.05.02.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 05:02:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89740-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-89740-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89740-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A81AFB21CCE for ; Sun, 3 Mar 2024 13:02:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0616AC2C6; Sun, 3 Mar 2024 13:02:16 +0000 (UTC) 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 847A3BE6B for ; Sun, 3 Mar 2024 13:02:15 +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=1709470935; cv=none; b=FRZZ+Iw77u5OHUjmz8590Kpw9QRS65haPDbxThSV3hekyHXBcfhSYG+HloZ/TnCcN5sHNW1rkQ3J0ewFytECtTwRGmplRMqEHYcIti5ynlkTLzRrJkx6P7KTZQ2dfsUQdElNfYLawWvkwP3eN7i0pKijqbIVMAtM/MMzo51nMwo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709470935; c=relaxed/simple; bh=fW7vH0k8JdCdLJCce0aUSYLj9NPTW/2Vau0mQPPcjUM=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OSIEnT0ESWTc1fnFDE9r+lGOuTO5r+R1DQtNvJjVRkSsGO8M/nxwoNS6/+r+lWkwiGrLViFJqIV2I5/dSoFjX5p2KSoLoLzAUEC0WA+IELs1ngeglO2L6ODkKe7VrIVVq7yj40jVAUiI3wO/8VJgnTi6NP1Z7WchTtzW/J6mlBQ= 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 1BB11C433F1; Sun, 3 Mar 2024 13:02:13 +0000 (UTC) Date: Sun, 3 Mar 2024 08:02:12 -0500 From: Steven Rostedt To: Linus Torvalds Cc: LKML , Masami Hiramatsu , Mathieu Desnoyers , Sachin Sant Subject: Re: [GIT PULL] tracing: Prevent trace_marker being bigger than unsigned short Message-ID: <20240303080212.489b3232@rorschach.local.home> In-Reply-To: <20240303075937.36fc6043@rorschach.local.home> References: <20240302111244.3a1674be@gandalf.local.home> <20240302145958.05aabdd2@rorschach.local.home> <20240302154713.71e29402@rorschach.local.home> <20240303075937.36fc6043@rorschach.local.home> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 3 Mar 2024 07:59:37 -0500 Steven Rostedt wrote: > > > > I believe I was trying to solve this wrong. The vsprintf() is called on > reading of the ring buffer, and I was trying to fix it on the write > side. I believe that the fix should be on the read side where the > vsprintf() is called. I prefer this patch, as I found other ways to add large strings into the ring buffer that can trigger this issue again. This fixes it at the location of the bug. -- Steve > > Sachin, can you try this patch. > > diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c > index 3e7fa44dc2b2..5c7962d612de 100644 > --- a/kernel/trace/trace_output.c > +++ b/kernel/trace/trace_output.c > @@ -1588,11 +1588,20 @@ static enum print_line_t trace_print_print(struct trace_iterator *iter, > struct print_entry *field; > struct trace_seq *s = &iter->seq; > int max = iter->ent_size - offsetof(struct print_entry, buf); > + const char *p; > > trace_assign_type(field, iter->ent); > > seq_print_ip_sym(s, field->ip, flags); > - trace_seq_printf(s, ": %.*s", max, field->buf); > + trace_seq_puts(s, ": "); > + /* Write 1K chunks at a time */ > + p = field->buf; > + do { > + int pre = max > 1024 ? 1024 : max; > + trace_seq_printf(s, "%.*s", pre, p); > + max -= pre; > + p += pre; > + } while (max > 0); > > return trace_handle_return(s); > } > @@ -1602,10 +1611,19 @@ static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags, > { > struct print_entry *field; > int max = iter->ent_size - offsetof(struct print_entry, buf); > + const char *p; > > trace_assign_type(field, iter->ent); > > - trace_seq_printf(&iter->seq, "# %lx %.*s", field->ip, max, field->buf); > + trace_seq_printf(&iter->seq, "# %lx", field->ip); > + /* Write 1K chunks at a time */ > + p = field->buf; > + do { > + int pre = max > 1024 ? 1024 : max; > + trace_seq_printf(&iter->seq, "%.*s", pre, p); > + max -= pre; > + p += pre; > + } while (max > 0); > > return trace_handle_return(&iter->seq); > }