Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1183714imu; Wed, 16 Jan 2019 14:18:55 -0800 (PST) X-Google-Smtp-Source: ALg8bN7fG2U7MatbFnoJQ3S6OtWsdptYk+UO1KqjfxE17Ufl+IwF91trBxrHHKq1/8D3B92qlaVi X-Received: by 2002:a62:5884:: with SMTP id m126mr12130616pfb.177.1547677135490; Wed, 16 Jan 2019 14:18:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547677135; cv=none; d=google.com; s=arc-20160816; b=iHkwyUPEU7YZVg7HtNvHzTi+rbtgVdWvT5Q4UuKE8t/BZgBBVFEq9U8FlaX+BWY/aO KcCpvSqDXeFbv06GjCYjesyQBBRr9MiwbLEypplm1Ep20JoQLaXO6rz5nU7wya74dero 2Yq1TScmZXK47/D2EktHQ+2m1eTCqH7Vd+A0Y/skdluKD94grxUCa4AHgwg7ry9UhB+l 8MaTT4UAcBRPdL6L7khdpp2c01emRIIJPRizOCJDPzA1Ws24TYUQTacjXGqfZbp1B/r9 uKhWWJa+TTiCRfo2WKIwux7U7KvnO3Aana3sYilRfgOGLKsxw4+WWveMmGp5tc+QvBNr 0TkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=wLWWyT65hdslHmYAHGhFkKEL/5DhuLE0/XKRA9M+8hc=; b=l3ae4APb0Ft9OHQO3cteyca/DWK1IJYbXw0rLeDCN35FDQoBIHSQA3Uzb+dNCX4qi6 aGcxlY3o5p3T3i30G0pfsWwAqBg7kS18Iigb6FcK5iZnA+qIlBm48qww1rpeMcN/UHbg sf5wblpHPmkseCVdKMXK6VKzCG8fU1tbhmWrSZeFlbtO0rJ2ukWKNHGWv5CAEjLO+p9K P1ePzqmHPjOcM820z9LELSeCvYLtHiXzRUHsQTV78MBkKvaNH9TQ7uNNlUgSs/bLKwU3 PIy9jpSChh/E3/nyIBKMy9vSYwW1qHh3eJc3f1rrTxpG22O0HIezIeXv8mfyK+i2iSqW pHjg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a9si7207193plp.323.2019.01.16.14.18.37; Wed, 16 Jan 2019 14:18:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393634AbfAPOeW (ORCPT + 99 others); Wed, 16 Jan 2019 09:34:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:40594 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387533AbfAPOeV (ORCPT ); Wed, 16 Jan 2019 09:34:21 -0500 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5C09E206C2; Wed, 16 Jan 2019 14:34:20 +0000 (UTC) Date: Wed, 16 Jan 2019 09:34:18 -0500 From: Steven Rostedt To: Masami Hiramatsu Cc: Andreas Ziegler , Ingo Molnar , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] tracing/uprobes: Fix output for multiple string arguments Message-ID: <20190116093418.2fe3e96b@gandalf.local.home> In-Reply-To: <20190116141629.5752-1-andreas.ziegler@fau.de> References: <20190116084021.34b0beee@gandalf.local.home> <20190116141629.5752-1-andreas.ziegler@fau.de> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 16 Jan 2019 15:16:29 +0100 Andreas Ziegler wrote: > When printing multiple uprobe arguments as strings the output for the > earlier arguments would also include all later string arguments. > > This is best explained in an example: > > Consider adding a uprobe to a function receiving two strings as > parameters which is at offset 0xa0 in strlib.so and we want to print > both parameters when the uprobe is hit (on x86_64): > > $ echo 'p:func /lib/strlib.so:0xa0 +0(%di):string +0(%si):string' > \ > /sys/kernel/debug/tracing/uprobe_events > > When the function is called as func("foo", "bar") and we hit the probe, > the trace file shows a line like the following: > > [...] func: (0x7f7e683706a0) arg1="foobar" arg2="bar" > > Note the extra "bar" printed as part of arg1. This behaviour stacks up > for additional string arguments. > > The strings are stored in a dynamically growing part of the uprobe > buffer by fetch_store_string() after copying them from userspace via > strncpy_from_user(). The return value of strncpy_from_user() is then > directly used as the required size for the string. However, this does > not take the terminating null byte into account as the documentation > for strncpy_from_user() cleary states that it "[...] returns the > length of the string (not including the trailing NUL)" even though the > null byte will be copied to the destination. > > Therefore, subsequent calls to fetch_store_string() will overwrite > the terminating null byte of the most recently fetched string with > the first character of the current string, leading to the > "accumulation" of strings in earlier arguments in the output. > > Fix this by incrementing the return value of strncpy_from_user() by > one if we did not hit the maximum buffer size. > > Signed-off-by: Andreas Ziegler Masami, Care to give a Reviewed-by on this patch? -- Steve > --- > v2: removed a wrong check for (ret > 0) > > kernel/trace/trace_uprobe.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c > index e335576b9411..3a1d5ab6b4ba 100644 > --- a/kernel/trace/trace_uprobe.c > +++ b/kernel/trace/trace_uprobe.c > @@ -160,6 +160,13 @@ fetch_store_string(unsigned long addr, void *dest, void *base) > if (ret >= 0) { > if (ret == maxlen) > dst[ret - 1] = '\0'; > + else > + /* > + * Include the terminating null byte. In this case it > + * was copied by strncpy_from_user but not accounted > + * for in ret. > + */ > + ret++; > *(u32 *)dest = make_data_loc(ret, (void *)dst - base); > } > > -- > 2.17.1