RCU Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH][next] refperf: avoid null pointer dereference when buf fails to allocate
@ 2020-07-16 14:38 Colin King
  2020-07-20 16:26 ` Paul E. McKenney
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2020-07-16 14:38 UTC (permalink / raw)
  To: Paul E . McKenney, Josh Triplett, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, Joel Fernandes, rcu
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently in the unlikely event that buf fails to be allocated it
is dereferenced a few times.  Use the errexit flag to determine if
buf should be written to to avoid the null pointer dereferences.

Addresses-Coverity: ("Dereference after null check")
Fixes: f518f154ecef ("refperf: Dynamically allocate experiment-summary output buffer")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 kernel/rcu/refscale.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c
index d9291f883b54..952595c678b3 100644
--- a/kernel/rcu/refscale.c
+++ b/kernel/rcu/refscale.c
@@ -546,9 +546,11 @@ static int main_func(void *arg)
 	// Print the average of all experiments
 	SCALEOUT("END OF TEST. Calculating average duration per loop (nanoseconds)...\n");
 
-	buf[0] = 0;
-	strcat(buf, "\n");
-	strcat(buf, "Runs\tTime(ns)\n");
+	if (!errexit) {
+		buf[0] = 0;
+		strcat(buf, "\n");
+		strcat(buf, "Runs\tTime(ns)\n");
+	}
 
 	for (exp = 0; exp < nruns; exp++) {
 		u64 avg;
-- 
2.27.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH][next] refperf: avoid null pointer dereference when buf fails to allocate
  2020-07-16 14:38 [PATCH][next] refperf: avoid null pointer dereference when buf fails to allocate Colin King
@ 2020-07-20 16:26 ` Paul E. McKenney
  0 siblings, 0 replies; 2+ messages in thread
From: Paul E. McKenney @ 2020-07-20 16:26 UTC (permalink / raw)
  To: Colin King
  Cc: Josh Triplett, Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan,
	Joel Fernandes, rcu, kernel-janitors, linux-kernel

On Thu, Jul 16, 2020 at 03:38:56PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently in the unlikely event that buf fails to be allocated it
> is dereferenced a few times.  Use the errexit flag to determine if
> buf should be written to to avoid the null pointer dereferences.
> 
> Addresses-Coverity: ("Dereference after null check")
> Fixes: f518f154ecef ("refperf: Dynamically allocate experiment-summary output buffer")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Good catch, applied, thank you!

							Thanx, Paul

> ---
>  kernel/rcu/refscale.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c
> index d9291f883b54..952595c678b3 100644
> --- a/kernel/rcu/refscale.c
> +++ b/kernel/rcu/refscale.c
> @@ -546,9 +546,11 @@ static int main_func(void *arg)
>  	// Print the average of all experiments
>  	SCALEOUT("END OF TEST. Calculating average duration per loop (nanoseconds)...\n");
>  
> -	buf[0] = 0;
> -	strcat(buf, "\n");
> -	strcat(buf, "Runs\tTime(ns)\n");
> +	if (!errexit) {
> +		buf[0] = 0;
> +		strcat(buf, "\n");
> +		strcat(buf, "Runs\tTime(ns)\n");
> +	}
>  
>  	for (exp = 0; exp < nruns; exp++) {
>  		u64 avg;
> -- 
> 2.27.0
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-16 14:38 [PATCH][next] refperf: avoid null pointer dereference when buf fails to allocate Colin King
2020-07-20 16:26 ` Paul E. McKenney

RCU Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/rcu/0 rcu/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 rcu rcu/ https://lore.kernel.org/rcu \
		rcu@vger.kernel.org
	public-inbox-index rcu

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.rcu


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git