Received: by 2002:a25:d783:0:0:0:0:0 with SMTP id o125csp651291ybg; Thu, 19 Mar 2020 06:25:54 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv71DuKr3gYfuTRGD433VXge0EJSAKOXaF2IWGNTCyzqrcWPtYaSuxRsdAMaCf2NGHH3S6g X-Received: by 2002:a9d:4c05:: with SMTP id l5mr2355324otf.371.1584624353873; Thu, 19 Mar 2020 06:25:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584624353; cv=none; d=google.com; s=arc-20160816; b=hYaEbeAFCo8P1/cetvDWzyt5gtrEDea6CSaY9isSH7utBUNpParOdaK0PgXyfCQfv8 fl6HNS+6OwGiWIwQBu0OYoWjsXfXYuioMjAhpTwcYcNFvFtDxpVm4s6zUCsk2jQHbxkW jEkY4xg2y1JNx4zeJgiG4ei1X6Qg6fg2YnH8fT4hekyFCNzq44o//MLzITyKF49BYIbI ZRb5KLJxf3KQAp7Tr3MXQKrFPZ7o6XRBcPNoD8MOV5zGqJH3VlHwV93QOpUzTDYyq0eZ bPCRc0FgYsrKja/J6WfPrEqf57lDnXrXh4a6mcSHYhxsoeibOsTwg2WWXu2mAGxXHLmr ugmA== 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=PLandAYgG15+jASSeugg+KnduH+MXoli0vJ8U7g+CNU=; b=wnxDAAwOh6HBfZ8sbKAXc5bGdFr6FbteNO+eFJBm/H87DG4guwknDlIkREigE0b/4k GKWNk3JvOBs/YBI9+S0EBE56avfYoV2OSuqkY8cKheFvwRNnMwNIHW4izavJ8hY1TQCx hcKF7qTipkDpzveFY1j9To0jbc2WONnfmxiEP9DSqiRpSjMM+EX+y5UrsoDeGVc3zLs/ axjrc2EbSME4plvrkKK+xC8NatGeJcBTeYIScI6Wrer96Y4wJQwiQiEMRuXhOJdUXoPN 7kc0y49f2y/lt1vFwCXVOn3CS8ZOjxIjPVBBDqg1DzuK0O1DmY8L1QkhV5rkkMbg270R OG2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="2hUp7Z/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 c22si1400301oto.280.2020.03.19.06.25.41; Thu, 19 Mar 2020 06:25:53 -0700 (PDT) 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="2hUp7Z/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 S1730057AbgCSNZ0 (ORCPT + 99 others); Thu, 19 Mar 2020 09:25:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:52978 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727684AbgCSNZZ (ORCPT ); Thu, 19 Mar 2020 09:25:25 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 21AC52080C; Thu, 19 Mar 2020 13:25:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584624324; bh=Gkbskkt5Gyu5DT0af7NouvEBc3hpmFpLfbbZiBpS7EM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2hUp7Z/c+CCQIfTqV35RAlgXTxyMjMzBNtD7QfaZUCYUfZWtkl1A4o67d73oXH//J D819vAoT458s8aPKvKIob6u6HfHhToBYBCBF6uO3APw30SzKAqxySZT8kCH9FhQDNe qf486G9nODbdmFuQOlkaTle8PM1JJV0M5PPzGkpI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Steven Rostedt (VMware)" , Tom Zanussi , Sasha Levin Subject: [PATCH 5.5 23/65] tracing: Fix number printing bug in print_synth_event() Date: Thu, 19 Mar 2020 14:04:05 +0100 Message-Id: <20200319123933.689001532@linuxfoundation.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200319123926.466988514@linuxfoundation.org> References: <20200319123926.466988514@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Tom Zanussi [ Upstream commit 784bd0847eda032ed2f3522f87250655a18c0190 ] Fix a varargs-related bug in print_synth_event() which resulted in strange output and oopses on 32-bit x86 systems. The problem is that trace_seq_printf() expects the varargs to match the format string, but print_synth_event() was always passing u64 values regardless. This results in unspecified behavior when unpacking with va_arg() in trace_seq_printf(). Add a function that takes the size into account when calling trace_seq_printf(). Before: modprobe-1731 [003] .... 919.039758: gen_synth_test: next_pid_field=777(null)next_comm_field=hula hoops ts_ns=1000000 ts_ms=1000 cpu=3(null)my_string_field=thneed my_int_field=598(null) After: insmod-1136 [001] .... 36.634590: gen_synth_test: next_pid_field=777 next_comm_field=hula hoops ts_ns=1000000 ts_ms=1000 cpu=1 my_string_field=thneed my_int_field=598 Link: http://lkml.kernel.org/r/a9b59eb515dbbd7d4abe53b347dccf7a8e285657.1581720155.git.zanussi@kernel.org Reported-by: Steven Rostedt (VMware) Signed-off-by: Tom Zanussi Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Sasha Levin --- kernel/trace/trace_events_hist.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index e10585ef00e15..862fb6d16edb8 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -811,6 +811,29 @@ static const char *synth_field_fmt(char *type) return fmt; } +static void print_synth_event_num_val(struct trace_seq *s, + char *print_fmt, char *name, + int size, u64 val, char *space) +{ + switch (size) { + case 1: + trace_seq_printf(s, print_fmt, name, (u8)val, space); + break; + + case 2: + trace_seq_printf(s, print_fmt, name, (u16)val, space); + break; + + case 4: + trace_seq_printf(s, print_fmt, name, (u32)val, space); + break; + + default: + trace_seq_printf(s, print_fmt, name, val, space); + break; + } +} + static enum print_line_t print_synth_event(struct trace_iterator *iter, int flags, struct trace_event *event) @@ -849,10 +872,13 @@ static enum print_line_t print_synth_event(struct trace_iterator *iter, } else { struct trace_print_flags __flags[] = { __def_gfpflag_names, {-1, NULL} }; + char *space = (i == se->n_fields - 1 ? "" : " "); - trace_seq_printf(s, print_fmt, se->fields[i]->name, - entry->fields[n_u64], - i == se->n_fields - 1 ? "" : " "); + print_synth_event_num_val(s, print_fmt, + se->fields[i]->name, + se->fields[i]->size, + entry->fields[n_u64], + space); if (strcmp(se->fields[i]->type, "gfp_t") == 0) { trace_seq_puts(s, " ("); -- 2.20.1