Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4296027ima; Mon, 4 Feb 2019 13:51:39 -0800 (PST) X-Google-Smtp-Source: AHgI3IYtDw9/BzCQfEfif0cgmmKjAO+MjfDEndiomb5R4bKn2U77D/3H2tMn2Zr5DKKVYslhdhOa X-Received: by 2002:a62:4e83:: with SMTP id c125mr1502513pfb.101.1549317099643; Mon, 04 Feb 2019 13:51:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549317099; cv=none; d=google.com; s=arc-20160816; b=07nwF87Vba1gfDqTzdIL9EmR7ATn3mxFXxQXlek+nYVyd9yq4vsrumJL0eJzUEaV++ D+fIyxV7SZH5pkuwaK+tO5C3qPIpByIDpcb1hhNkjE2eBxxodLHS/PSmJy+RvLu+Yp3r iEWaKePHSmjA0+A7lRvtG0XU0Nn4uClIPnW9locLklaEibm2datikVkghqu5jP/Bj/ia Sknr5fKUfBVf+Cu+sS9ow7W/Q9Nw3uEEowiiwm6XGnkYECHYrQp7pxwMxzVRBw9KRYVX JqQDhNVAkVqfFVv4t8fzOqCg90v4zE7/jczUk6dlZgZ2Jb74Tb2N4rbf5p1xBE0DDQQi yiKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=CBu4XHeWsbdJZL8zFp/9TG6ttSZzm9i4xPgzYdbzPg4=; b=mL9hzKij0SlV0v1HIuHMWDi2lqv8qRoftVraowrtOQmfwo0/ujDaFWm/bRxfunFuqN M/+u63AY8YBObR3lbdY/BH4SSX4uVGrIeqk8rDi/vbFO1Rp9nWo4Cuk4OtBsLAUCFQiK NrzIxBoTjkTzlMqmfr94ysbqSDrTNW6fFKBpNk05Jfl2svJrpBx1MA4jQKnbDm+AwWh9 MMpYbMakTyq0bKZ5z77fXxzwqv86SfHOAIM/RFP4i8muF11ZCh5RJgSmgCp+ACUwk/Ys llMxdSzlYyvYoVJUtSXOc0vBnKdDdk9qpPaonihC3EgBJJfm1n4SyZLaKkUS4SrYXSMz mpAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zm31fbbC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cb1si1319643plb.37.2019.02.04.13.51.23; Mon, 04 Feb 2019 13:51:39 -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=zm31fbbC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729772AbfBDVHi (ORCPT + 99 others); Mon, 4 Feb 2019 16:07:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:32966 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729534AbfBDVHf (ORCPT ); Mon, 4 Feb 2019 16:07:35 -0500 Received: from localhost.localdomain (c-98-220-238-81.hsd1.il.comcast.net [98.220.238.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8D3012083B; Mon, 4 Feb 2019 21:07:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549314455; bh=YG3gLhHCItxKRLkiqzjLjfv0P4jXp8JpzDQCk0nccYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=zm31fbbCvAkvAxQ+GHo51tYfOhEaOlnyRDkP2AvxwRkMbLVUA5I36vl/J6h8RTddD 1w/RmMlq5EPJ0pq+9kCRRYXNL79FRE5H1hKeJZv1rRbk9Qd7hbG8My+KhtCk9NnWPL RGb7nDxjPJ5v+D6ICuPMAZo1t8VRdsfT3wMXkgmc= From: Tom Zanussi To: rostedt@goodmis.org Cc: linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org, Tom Zanussi , Namhyung Kim Subject: [PATCH 2/2] tracing: Use strncpy instead of memcpy for string keys in hist triggers Date: Mon, 4 Feb 2019 15:07:24 -0600 Message-Id: <50c35ae1267d64eee975b8125e151e600071d4dc.1549309756.git.tom.zanussi@linux.intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tom Zanussi Because there may be random garbage beyond a string's null terminator, it's not correct to copy the the complete character array for use as a hist trigger key. This results in multiple histogram entries for the 'same' string key. So, in the case of a string key, use strncpy instead of memcpy to avoid copying in the extra bytes. Before, using the gdbus entries in the following hist trigger as an example: # echo 'hist:key=comm' > /sys/kernel/debug/tracing/events/sched/sched_waking/trigger # cat /sys/kernel/debug/tracing/events/sched/sched_waking/hist ... { comm: ImgDecoder #4 } hitcount: 203 { comm: gmain } hitcount: 213 { comm: gmain } hitcount: 216 { comm: StreamTrans #73 } hitcount: 221 { comm: mozStorage #3 } hitcount: 230 { comm: gdbus } hitcount: 233 { comm: StyleThread#5 } hitcount: 253 { comm: gdbus } hitcount: 256 { comm: gdbus } hitcount: 260 { comm: StyleThread#4 } hitcount: 271 ... # cat /sys/kernel/debug/tracing/events/sched/sched_waking/hist | egrep gdbus | wc -l 51 After: # cat /sys/kernel/debug/tracing/events/sched/sched_waking/hist | egrep gdbus | wc -l 1 Signed-off-by: Tom Zanussi Cc: Namhyung Kim --- kernel/trace/trace_events_hist.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index c4a667503bf0..1b349689b897 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -4695,9 +4695,10 @@ static inline void add_to_key(char *compound_key, void *key, /* ensure NULL-termination */ if (size > key_field->size - 1) size = key_field->size - 1; - } - memcpy(compound_key + key_field->offset, key, size); + strncpy(compound_key + key_field->offset, (char *)key, size); + } else + memcpy(compound_key + key_field->offset, key, size); } static void -- 2.14.1