From patchwork Tue Jan 7 20:54:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 234286 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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 47DEFC282DD for ; Tue, 7 Jan 2020 21:22:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 124CF206F0 for ; Tue, 7 Jan 2020 21:22:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578432128; bh=082g/+E/r/Uzy/BpXGTHlxw9TEPrw/aq7wuayti0Uhk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=KLfSoE8QJM5Vs93ePrc2eRQlc9sDZaS5ZDy6BwZ55vrz4g6nyOxIEgqMFdSHLHLrk vuIyTUuE91M6puxSGhz2mow3KJ6KPtPQI/HeBbGp5tOCskyiwVe6c/LdYtqTsZaqLj M5FoLXk97qEZ0cLyGQ/eG/SElkUOXVraYepsb6FU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727311AbgAGVCn (ORCPT ); Tue, 7 Jan 2020 16:02:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:42992 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728772AbgAGVCm (ORCPT ); Tue, 7 Jan 2020 16:02:42 -0500 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 B0DB72077B; Tue, 7 Jan 2020 21:02:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578430962; bh=082g/+E/r/Uzy/BpXGTHlxw9TEPrw/aq7wuayti0Uhk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N1M6+GcOKkGOqOCD+LdffhY3ixJkI9X1BabwU8EJdFlvOPLVMgbcHKTttGg3yOisB HYJp9jdfvDWhDwrDsuoYMs65qAzV/dh8DQsTf4o1ismAYQ7fRxpwS/oI3UZ8tS8tU0 V5RAlY7XPqeQvYrGQw+fvGmOEXhm4g0FhBacDrrU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wen Yang , "Steven Rostedt (VMware)" Subject: [PATCH 5.4 131/191] ftrace: Avoid potential division by zero in function profiler Date: Tue, 7 Jan 2020 21:54:11 +0100 Message-Id: <20200107205339.982782846@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200107205332.984228665@linuxfoundation.org> References: <20200107205332.984228665@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Wen Yang commit e31f7939c1c27faa5d0e3f14519eaf7c89e8a69d upstream. The ftrace_profile->counter is unsigned long and do_div truncates it to 32 bits, which means it can test non-zero and be truncated to zero for division. Fix this issue by using div64_ul() instead. Link: http://lkml.kernel.org/r/20200103030248.14516-1-wenyang@linux.alibaba.com Cc: stable@vger.kernel.org Fixes: e330b3bcd8319 ("tracing: Show sample std dev in function profiling") Fixes: 34886c8bc590f ("tracing: add average time in function to function profiler") Signed-off-by: Wen Yang Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/ftrace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -524,8 +524,7 @@ static int function_stat_show(struct seq } #ifdef CONFIG_FUNCTION_GRAPH_TRACER - avg = rec->time; - do_div(avg, rec->counter); + avg = div64_ul(rec->time, rec->counter); if (tracing_thresh && (avg < tracing_thresh)) goto out; #endif @@ -551,7 +550,8 @@ static int function_stat_show(struct seq * Divide only 1000 for ns^2 -> us^2 conversion. * trace_print_graph_duration will divide 1000 again. */ - do_div(stddev, rec->counter * (rec->counter - 1) * 1000); + stddev = div64_ul(stddev, + rec->counter * (rec->counter - 1) * 1000); } trace_seq_init(&s);