Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2429504imj; Mon, 18 Feb 2019 05:58:33 -0800 (PST) X-Google-Smtp-Source: AHgI3IZbRg2E+ZJL7A1HFQqGQIp1bKizmWaPnq05V1xAwFAsgs0QUgp8v+JORgKk/rKmqqN/7uC8 X-Received: by 2002:a63:c34e:: with SMTP id e14mr17805022pgd.231.1550498313808; Mon, 18 Feb 2019 05:58:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550498313; cv=none; d=google.com; s=arc-20160816; b=rcrO1WpSh/Z8RXcKkGQvFDiwKYUzVKyypZBJlApRLUNM1xfqv0IxtXp9qIakfO5/du NKvD+BKJqzNdgF++7LL+rG87NqIMybq324W/1SJ26HRBarmlsI4qftfwElDrdhePlcnw ye0ZnfiCKZXr+7TgIh8Ga+vofEPZ/MXXXhsmtv7wf9kiQk1yQbZFkrVWu7tn9hMN9e8k it/Hv+6o/by2Y+mIQlJEPcJ/qH8zmZPqSOhqOkhpDpCwBiHRCqofu01EG02erSXelYOx GGEIa7q+ndXjHM9t4iH8xyZ0f+i2anAuzSalqvCtI4BZSChxO89hR1Gr6Rzxx37HEF8N 8kPQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=APmbIc1PQTTMdVgAC8mLQOud5lZRHVdnK+YfnVtsBnw=; b=oDvc86JYtTuZDTD1gpoLLjJBHj/d/dCmv8wShi+MFKz4Cr04wi2mgOWrI0DOt+gGG7 /NV+lV2B8UBvT8aPHGdi3/txALSua+ANC+llhlPBah2fOf4kv52P2N9ZhDJyFIml2jzS rlPQ1y8zgo0L08FiBPz/QgCNvBtclEtBQLDaCIUhkNoUESvRbjm+MPxZ3BLoj34JbXcr 3LFJpcGx4MtOzIfoN32O8K4nzX04Y0fD21UFf2H7Kc5xmTSsLuZ4TKnJIzXBONNq4/UJ +d9yuPzJaMAgHM4wRBZVhoTEbwT/2jUqFpA4w9s2LAeuYm038ICN1Xq/3DJ9oVPVw4ad u2Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="RzBtmC/c"; 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 d12si2540021plo.143.2019.02.18.05.58.18; Mon, 18 Feb 2019 05:58:33 -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; dkim=pass header.i=@kernel.org header.s=default header.b="RzBtmC/c"; 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 S2388090AbfBRN50 (ORCPT + 99 others); Mon, 18 Feb 2019 08:57:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:37806 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733040AbfBRN5W (ORCPT ); Mon, 18 Feb 2019 08:57:22 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 4F0512077B; Mon, 18 Feb 2019 13:57:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550498241; bh=7QRKOcgaVbGY4rx8eSAyG7eoLBarA0l0qO1GkxivUdg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RzBtmC/cwcVyPnXXC/H3gf3KL48uv7w5uphEfBhNkh7Vm9gGTpqhpCEGJPca+0AS/ rGwkadPuFe4mchvDSTe7csS3Lc5y5k0EqsjFcHLZJ692Vn3qTTveFmb3BH20OIAWAm 0/LWffKdUGoHQsW0zBw7lbaKnhg1ey2VkXVicRwA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ingo Molnar , Masami Hiramatsu , Andreas Ziegler , "Steven Rostedt (VMware)" Subject: [PATCH 4.14 52/62] tracing/uprobes: Fix output for multiple string arguments Date: Mon, 18 Feb 2019 14:43:58 +0100 Message-Id: <20190218133510.245339321@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218133505.801423074@linuxfoundation.org> References: <20190218133505.801423074@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace_uprobe.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -153,7 +153,14 @@ static void FETCH_FUNC_NAME(memory, stri 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';