Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2771273imb; Mon, 4 Mar 2019 13:52:01 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ7s5f3drKabosx+mY+8sos5zuKbua9t/FjZHVIe7oqGbk699VdkXEorUX0+yzrMrluK3+b X-Received: by 2002:a62:2f81:: with SMTP id v123mr21674134pfv.156.1551736321604; Mon, 04 Mar 2019 13:52:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551736321; cv=none; d=google.com; s=arc-20160816; b=DfFQuak4Okp9gtbkE4rG2Ftb5LweLzAFB+eqdJ3/i1kDn44Wexgn7Nvsc2vWncRzgn PbutkD+dRxYb85mIoE9YMrg79fSHCMCrfr+rLFqiIh+EWTCPjQ+GQKJs5TYoYqDpsA6f uaI8Qwuzjn7qn+vLBGkPA1dqikuhPp24PRc8bntE6vrBdWS4jsrmYLa5NWKWzKP5J8I3 U/0XIH3BzRkIdYQ3wqni90toQZqeQLRKK2uGIJOaG4qwcOaVCxJqBI13pS+7Pq21uJgU rQYvjH+YXmrSs38Z4WLZXRFKteX4G2kStDxsuhbXkpLVsImYH37uCl6aGTvi4aUrsdjw j0sA== 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=IqxRjrH3ev+NyOPqgGWr0yvSXKWAu12HhX7fOa85RwE=; b=LztRL8+TkgJTUKZWJqCHdgru8ijZNMr6dc47oD7ijeWiMGPByWn+/7NkKvY6MkPi4r u+PNss1lpJXeX9IvqPirflLg42YA/Jx5Y/FQALh1vvsQ7BbMJtv/IhVRJHVtrSnEJunN fizUdNj9FhVMILQjQ7NU+pEqCxMrU9H9aVuNBAUO2uDPZMkmrzyC7UdstStaPv8crtGH opk9SRmA1o9AomOds1vUNo31bnwpFATEvTOxHXUSYX3DcLLE+Yz1dP1NwFaKzZBSy+qz sAN/1laFn8k92JrOdIzgokxdh6BMo79OCWZK4znwrtmZndTlKoKRdS1QncQyZDPGYdK8 prpQ== 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 e67si6647408plb.107.2019.03.04.13.51.45; Mon, 04 Mar 2019 13:52:01 -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 S1726355AbfCDVuD (ORCPT + 99 others); Mon, 4 Mar 2019 16:50:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:51626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726069AbfCDVuD (ORCPT ); Mon, 4 Mar 2019 16:50:03 -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 3B889206B6; Mon, 4 Mar 2019 21:50:02 +0000 (UTC) Date: Mon, 4 Mar 2019 16:50:00 -0500 From: Steven Rostedt To: Tom Zanussi Cc: linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org, Tom Zanussi , Namhyung Kim Subject: Re: [PATCH 2/2] tracing: Use strncpy instead of memcpy for string keys in hist triggers Message-ID: <20190304165000.0ce0fbdd@gandalf.local.home> In-Reply-To: <50c35ae1267d64eee975b8125e151e600071d4dc.1549309756.git.tom.zanussi@linux.intel.com> References: <50c35ae1267d64eee975b8125e151e600071d4dc.1549309756.git.tom.zanussi@linux.intel.com> 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 Mon, 4 Feb 2019 15:07:24 -0600 Tom Zanussi wrote: > 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); > } > Shouldn't we use strncpy() in save_comm() too. Feels safer. -- Steve