lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250203100603.5c00df0f@gandalf.local.home>
Date: Mon, 3 Feb 2025 10:06:03 -0500
From: Steven Rostedt <rostedt@...dmis.org>
To: Nikolay Kuratov <kniv@...dex-team.ru>
Cc: linux-kernel@...r.kernel.org, linux-trace-kernel@...r.kernel.org, Wen
 Yang <wenyang@...ux.alibaba.com>, Mark Rutland <mark.rutland@....com>,
 Mathieu Desnoyers <mathieu.desnoyers@...icios.com>, stable@...r.kernel.org
Subject: Re: [PATCH] ftrace: Avoid potential division by zero in
 function_stat_show()

On Fri, 31 Jan 2025 18:53:46 +0300
Nikolay Kuratov <kniv@...dex-team.ru> wrote:

> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -570,12 +570,12 @@ static int function_stat_show(struct seq_file *m, void *v)
>  		stddev = rec->counter * rec->time_squared -
>  			 rec->time * rec->time;
>  
> +		stddev = div64_ul(stddev, rec->counter * (rec->counter - 1));
>  		/*
>  		 * Divide only 1000 for ns^2 -> us^2 conversion.
>  		 * trace_print_graph_duration will divide 1000 again.
>  		 */
> -		stddev = div64_ul(stddev,
> -				  rec->counter * (rec->counter - 1) * 1000);
> +		stddev = div64_ul(stddev, 1000);
>  	}
>  

Why make it more complex than it needs to be? We can simply have:

	if (rec->counter <= 1) {
		stddev = 0;
	} else {
		unsigned long counter = rec->counter * (rec->counter - 1) * 1000;

		stddev = rec->counter * rec->time_squared -
			 rec->time * rec->time;

		/* Check for overflow */
		stddev = counter > rec->counter ? div64_ul(stddev, counter) : 0;
	}

And be done with it.

I'll make the change and give you a "Reported-by".

Thanks,

-- Steve


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ