From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64361C43381 for ; Mon, 18 Feb 2019 11:34:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3351A208E4 for ; Mon, 18 Feb 2019 11:34:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kroah.com header.i=@kroah.com header.b="Q2nEFbQh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="G0vaPLGR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730008AbfBRLeW (ORCPT ); Mon, 18 Feb 2019 06:34:22 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:39599 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729907AbfBRLeW (ORCPT ); Mon, 18 Feb 2019 06:34:22 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 365063184; Mon, 18 Feb 2019 06:34:19 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 18 Feb 2019 06:34:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kroah.com; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=hRAGiMxsqwbWtGmSaSeF7+Yw4WH 10qSnOqFylGM4VB0=; b=Q2nEFbQhPemZv1qfSXvm1omZi0GzxLZw73eL4jpMT4D v1b4mwp/HGb5NJAb63wSykln9KPo4Ut0WQi4JDSrMWopT1Xsw5Y+9kNBqZjL97DJ Dmwce0MbaKm4ShG21WAmjgHoSd6oDnC4mgF7WfxZabnTlR0pVjhBBI4h/Al19Ma6 4Vgu9q3cJ8TAyIJhgWWzlr/nHeRBFyaIWS8tTqcXD7UfqFPdTlVYB5DYmcDO8AKP aStFdvFBZ3GOEjoReTVEQ/Dzz5GoVWbOUoVyB4DYqLTfnMshgbqLNDNx/6pyqHJD LQSJERS7RufkNxzcKwcZRFD5snV8mfZFbf0eR6OgsmA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=hRAGiM xsqwbWtGmSaSeF7+Yw4WH10qSnOqFylGM4VB0=; b=G0vaPLGRMwCLVLkJAzFQ/v STbtXGEQ346Axw9NcIQIyMsk0huSSbopb67z8SUiQyqy0TP8w+TlePEp3kiA0Q4e +FFrB48kZCVL/2ETrpUDWNh/sFl/LnWRbcaYbWzH1AWWrc0L5QZfKXU/+Y+DbwoU CXm+MeSYYs93LA2VbaeAXCkMWVr3DsEuzi4uHmNnfEYevayrhJkSmDUUYWn60Y0S hYWvu2RRnEBz3NDHB/2oE0JlWHnwS8qq4YGI2NHq2QeDBBINXsInsLx08WdbMEOL lHxcdffhbxLxvDQQZWqNZL91eH74x6PwVCc4P9HM3c70k8tLGGP9ivtuG/g3sSsQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrtddtgdduudculddtuddrgedtledrtddtmd cutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjfgesthdtredttdervdenucfhrhhomhepifhrvghg ucfmjfcuoehgrhgvgheskhhrohgrhhdrtghomheqnecuffhomhgrihhnpehkvghrnhgvlh drohhrghenucfkphepkeefrdekiedrkeelrddutdejnecurfgrrhgrmhepmhgrihhlfhhr ohhmpehgrhgvgheskhhrohgrhhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from localhost (5356596b.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) by mail.messagingengine.com (Postfix) with ESMTPA id 7E81A10310; Mon, 18 Feb 2019 06:34:17 -0500 (EST) Date: Mon, 18 Feb 2019 12:34:16 +0100 From: Greg KH To: Masami Hiramatsu Cc: stable@vger.kernel.org, andreas.ziegler@fau.de, mingo@redhat.com, rostedt@goodmis.org Subject: Re: [PATCH stable-4.19 v2] tracing/uprobes: Fix output for multiple string arguments Message-ID: <20190218113416.GA27643@kroah.com> References: <20190214223923.3b068eafda0114870580e48d@kernel.org> <155015426911.16940.12496678038569055827.stgit@devbox> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <155015426911.16940.12496678038569055827.stgit@devbox> User-Agent: Mutt/1.11.3 (2019-02-01) Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On Thu, Feb 14, 2019 at 11:24:29PM +0900, Masami Hiramatsu wrote: > From: Andreas Ziegler > > commit 0722069a5374b904ec1a67f91249f90e1cfae259 upstream. > > 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. > > Link: http://lkml.kernel.org/r/20190116141629.5752-1-andreas.ziegler@fau.de > > Cc: Ingo Molnar > Cc: stable@vger.kernel.org > Fixes: 5baaa59ef09e ("tracing/probes: Implement 'memory' fetch method for uprobes") > Acked-by: Masami Hiramatsu > Signed-off-by: Andreas Ziegler > Signed-off-by: Steven Rostedt (VMware) > Signed-off-by: Masami Hiramatsu > --- > kernel/trace/trace_uprobe.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c > index e696667da29a..bf93ae152c22 100644 > --- a/kernel/trace/trace_uprobe.c > +++ b/kernel/trace/trace_uprobe.c > @@ -141,7 +141,14 @@ static void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs, > > ret = strncpy_from_user(dst, src, maxlen); > if (ret == maxlen) > - dst[--ret] = '\0'; > + dst[ret - 1] = '\0'; > + else if (ret >= 0) > + /* > + * Include the terminating null byte. In this case it > + * was copied by strncpy_from_user but not accounted > + * for in ret. > + */ > + ret++; > > if (ret < 0) { /* Failed to fetch string */ > ((u8 *)get_rloc_data(dest))[0] = '\0'; > All now queued up, thanks. greg k-h