linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chuck Lever III <chuck.lever@oracle.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Linux NFS Mailing List <linux-nfs@vger.kernel.org>,
	David Wysochanski <dwysocha@redhat.com>,
	Bruce Fields <bfields@fieldses.org>
Subject: Re: [PATCH v2 01/25] NFSD: Fix TP_printk() format specifier in trace_nfsd_dirent()
Date: Thu, 13 May 2021 20:01:00 +0000	[thread overview]
Message-ID: <5BC8482E-1902-432A-B162-774A96E4C2B7@oracle.com> (raw)
In-Reply-To: <20210513151721.02a7fdd1@gandalf.local.home>


> On May 13, 2021, at 3:17 PM, Steven Rostedt <rostedt@goodmis.org> wrote:
> 
> On Thu, 13 May 2021 19:08:13 +0000
> Chuck Lever III <chuck.lever@oracle.com> wrote:
> 
>> The tracepoints that currently use '%.*s' no longer work when
>> using "trace-cmd start/stop/show". They were working before
>> 9a6944fee68e, so I consider this a regression. I plan to
>> submit patches to address this for 5.13-rc. I guess they will
>> have to go without the use of the new _len macros for now,
>> and you can push the macros in v5.14.
> 
> That's a separate bug. I'm currently running this patch through my tests,
> and will push to Linus when it completes. Feel free to test this one too.

Confirmed that applying the below patch addresses the regression.

Tested-by: Chuck Lever <chuck.lever@oracle.com>

Thanks for your quick response!


> -- Steve
> 
> From eb01f5353bdaa59600b29d864819056a0e3de24d Mon Sep 17 00:00:00 2001
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> Date: Thu, 13 May 2021 12:23:24 -0400
> Subject: [PATCH] tracing: Handle %.*s in trace_check_vprintf()
> 
> If a trace event uses the %*.s notation, the trace_check_vprintf() will
> fail and will warn about a bad processing of strings, because it does not
> take into account the length field when processing the star (*) part.
> Have it handle this case as well.
> 
> Link: https://lore.kernel.org/linux-nfs/238C0E2D-C2A4-4578-ADD2-C565B3B99842@oracle.com/
> 
> Reported-by: Chuck Lever III <chuck.lever@oracle.com>
> Fixes: 9a6944fee68e2 ("tracing: Add a verifier to check string pointers for trace events")
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
> kernel/trace/trace.c | 31 +++++++++++++++++++++++++++----
> 1 file changed, 27 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 560e4c8d3825..a21ef9cd2aae 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -3704,6 +3704,9 @@ void trace_check_vprintf(struct trace_iterator *iter, const char *fmt,
> 		goto print;
> 
> 	while (*p) {
> +		bool star = false;
> +		int len = 0;
> +
> 		j = 0;
> 
> 		/* We only care about %s and variants */
> @@ -3725,13 +3728,17 @@ void trace_check_vprintf(struct trace_iterator *iter, const char *fmt,
> 				/* Need to test cases like %08.*s */
> 				for (j = 1; p[i+j]; j++) {
> 					if (isdigit(p[i+j]) ||
> -					    p[i+j] == '*' ||
> 					    p[i+j] == '.')
> 						continue;
> +					if (p[i+j] == '*') {
> +						star = true;
> +						continue;
> +					}
> 					break;
> 				}
> 				if (p[i+j] == 's')
> 					break;
> +				star = false;
> 			}
> 			j = 0;
> 		}
> @@ -3744,6 +3751,9 @@ void trace_check_vprintf(struct trace_iterator *iter, const char *fmt,
> 		iter->fmt[i] = '\0';
> 		trace_seq_vprintf(&iter->seq, iter->fmt, ap);
> 
> +		if (star)
> +			len = va_arg(ap, int);
> +
> 		/* The ap now points to the string data of the %s */
> 		str = va_arg(ap, const char *);
> 
> @@ -3762,8 +3772,18 @@ void trace_check_vprintf(struct trace_iterator *iter, const char *fmt,
> 			int ret;
> 
> 			/* Try to safely read the string */
> -			ret = strncpy_from_kernel_nofault(iter->fmt, str,
> -							  iter->fmt_size);
> +			if (star) {
> +				if (len + 1 > iter->fmt_size)
> +					len = iter->fmt_size - 1;
> +				if (len < 0)
> +					len = 0;
> +				ret = copy_from_kernel_nofault(iter->fmt, str, len);
> +				iter->fmt[len] = 0;
> +				star = false;
> +			} else {
> +				ret = strncpy_from_kernel_nofault(iter->fmt, str,
> +								  iter->fmt_size);
> +			}
> 			if (ret < 0)
> 				trace_seq_printf(&iter->seq, "(0x%px)", str);
> 			else
> @@ -3775,7 +3795,10 @@ void trace_check_vprintf(struct trace_iterator *iter, const char *fmt,
> 			strncpy(iter->fmt, p + i, j + 1);
> 			iter->fmt[j+1] = '\0';
> 		}
> -		trace_seq_printf(&iter->seq, iter->fmt, str);
> +		if (star)
> +			trace_seq_printf(&iter->seq, iter->fmt, len, str);
> +		else
> +			trace_seq_printf(&iter->seq, iter->fmt, str);
> 
> 		p += i + j + 1;
> 	}
> -- 
> 2.29.2
> 

--
Chuck Lever




  reply	other threads:[~2021-05-13 20:01 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-12 15:34 [PATCH v2 00/25] NFSD callback and lease management observability Chuck Lever
2021-05-12 15:35 ` [PATCH v2 01/25] NFSD: Fix TP_printk() format specifier in trace_nfsd_dirent() Chuck Lever
2021-05-12 16:26   ` Steven Rostedt
2021-05-12 16:52     ` Chuck Lever III
2021-05-13 14:50       ` Steven Rostedt
2021-05-13 14:53         ` Chuck Lever III
2021-05-13 15:02           ` Steven Rostedt
2021-05-13 15:10         ` Chuck Lever III
2021-05-13 18:43           ` Chuck Lever III
2021-05-13 19:00             ` Steven Rostedt
2021-05-13 19:08               ` Chuck Lever III
2021-05-13 19:17                 ` Steven Rostedt
2021-05-13 20:01                   ` Chuck Lever III [this message]
2021-07-12 15:18         ` Chuck Lever III
2021-07-12 17:09           ` Steven Rostedt
2021-05-12 16:53     ` Steven Rostedt
2021-05-12 15:35 ` [PATCH v2 02/25] NFSD: Fix TP_printk() format specifier in nfsd_clid_class Chuck Lever
2021-05-12 15:35 ` [PATCH v2 03/25] NFSD: Add nfsd_clid_cred_mismatch tracepoint Chuck Lever
2021-05-12 15:35 ` [PATCH v2 04/25] NFSD: Add nfsd_clid_verf_mismatch tracepoint Chuck Lever
2021-05-12 15:35 ` [PATCH v2 05/25] NFSD: Remove trace_nfsd_clid_inuse_err Chuck Lever
2021-05-12 15:35 ` [PATCH v2 06/25] NFSD: Add nfsd_clid_confirmed tracepoint Chuck Lever
2021-05-12 15:35 ` [PATCH v2 07/25] NFSD: Add nfsd_clid_reclaim_complete tracepoint Chuck Lever
2021-05-12 15:35 ` [PATCH v2 08/25] NFSD: Add nfsd_clid_destroyed tracepoint Chuck Lever
2021-05-12 15:35 ` [PATCH v2 09/25] NFSD: Add a couple more nfsd_clid_expired call sites Chuck Lever
2021-05-13 16:42   ` David Wysochanski
2021-05-13 17:05     ` Chuck Lever III
2021-05-12 15:36 ` [PATCH v2 10/25] NFSD: Add an RPC authflavor tracepoint display helper Chuck Lever
2021-05-12 15:36 ` [PATCH v2 11/25] NFSD: Add tracepoints for SETCLIENTID edge cases Chuck Lever
2021-05-12 15:36 ` [PATCH v2 12/25] NFSD: Add tracepoints for EXCHANGEID " Chuck Lever
2021-05-12 15:36 ` [PATCH v2 13/25] NFSD: Constify @fh argument of knfsd_fh_hash() Chuck Lever
2021-05-12 15:36 ` [PATCH v2 14/25] NFSD: Capture every CB state transition Chuck Lever
2021-05-12 15:36 ` [PATCH v2 15/25] NFSD: Drop TRACE_DEFINE_ENUM for NFSD4_CB_<state> macros Chuck Lever
2021-05-12 15:36 ` [PATCH v2 16/25] NFSD: Add cb_lost tracepoint Chuck Lever
2021-05-12 15:36 ` [PATCH v2 17/25] NFSD: Adjust cb_shutdown tracepoint Chuck Lever
2021-05-12 15:36 ` [PATCH v2 18/25] NFSD: Remove spurious cb_setup_err tracepoint Chuck Lever
2021-05-12 15:37 ` [PATCH v2 19/25] NFSD: Enhance the nfsd_cb_setup tracepoint Chuck Lever
2021-05-12 15:37 ` [PATCH v2 20/25] NFSD: Add an nfsd_cb_lm_notify tracepoint Chuck Lever
2021-05-12 15:37 ` [PATCH v2 21/25] NFSD: Add an nfsd_cb_offload tracepoint Chuck Lever
2021-05-12 15:37 ` [PATCH v2 22/25] NFSD: Replace the nfsd_deleg_break tracepoint Chuck Lever
2021-05-12 15:37 ` [PATCH v2 23/25] NFSD: Add an nfsd_cb_probe tracepoint Chuck Lever
2021-05-12 15:37 ` [PATCH v2 24/25] NFSD: Remove the nfsd_cb_work and nfsd_cb_done tracepoints Chuck Lever
2021-05-12 15:37 ` [PATCH v2 25/25] NFSD: Update nfsd_cb_args tracepoint Chuck Lever

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=5BC8482E-1902-432A-B162-774A96E4C2B7@oracle.com \
    --to=chuck.lever@oracle.com \
    --cc=bfields@fieldses.org \
    --cc=dwysocha@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /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;
as well as URLs for NNTP newsgroup(s).