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] [day] [month] [year] [list]
Message-ID: <41a572f2-b9d3-4985-a61e-bff0b3b0e4d3@paulmck-laptop>
Date: Wed, 10 Sep 2025 06:33:12 -0700
From: "Paul E. McKenney" <paulmck@...nel.org>
To: Kaushlendra Kumar <kaushlendra.kumar@...el.com>
Cc: dave@...olabs.net, josh@...htriplett.org, frederic@...nel.org,
	neeraj.upadhyay@...nel.org, rostedt@...dmis.org,
	linux-kernel@...r.kernel.org, rcu@...r.kernel.org
Subject: Re: [PATCH v2] rcu/rcutorture: Improve error handling in
 rcu_torture_fwd_prog_init()

On Wed, Sep 10, 2025 at 02:58:20PM +0530, Kaushlendra Kumar wrote:
> Restructure error handling in rcu_torture_fwd_prog_init() to provide
> cleaner allocation failure paths. The current code checks both
> allocations in a single condition, making error handling less
> efficient and clear.
> 
> The improved approach:
> - Check rfp allocation immediately and return early on failure
> - Separately handle fwd_prog_tasks allocation failure with proper
>   cleanup
> - Remove redundant kfree(fwd_prog_tasks) since it would be NULL on
>   failure

First, thank you for your interest in Linux-kernel RCU!

However, you lost me on this one.  Please see below.

> Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@...el.com>
> ---
> Changes in v2:
> - Fixed word wrapping in commit message to follow kernel guidelines
> ---
>  kernel/rcu/rcutorture.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
> index 807fbf6123a7..6af0d207adba 100644
> --- a/kernel/rcu/rcutorture.c
> +++ b/kernel/rcu/rcutorture.c
> @@ -2995,11 +2995,11 @@ static int __init rcu_torture_fwd_prog_init(void)
>  	if (fwd_progress_div <= 0)
>  		fwd_progress_div = 4;
>  	rfp = kcalloc(fwd_progress, sizeof(*rfp), GFP_KERNEL);
> +	if (!rfp)
> +		return -ENOMEM;

Don't we still need to set fwd_progress to zero?

>  	fwd_prog_tasks = kcalloc(fwd_progress, sizeof(*fwd_prog_tasks), GFP_KERNEL);

Although this change does avoid the doomed kcalloc() attempt, why are
we optimizing an infrequent failure case?

> -	if (!rfp || !fwd_prog_tasks) {
> +	if (!fwd_prog_tasks) {
>  		kfree(rfp);
> -		kfree(fwd_prog_tasks);

Invoking kfree() on a NULL pointer is a well-defined no-op.

> -		fwd_prog_tasks = NULL;
>  		fwd_progress = 0;
>  		return -ENOMEM;
>  	}

I don't see where this is helping the common-case success path, nor am
I seeing need need to optimize this initialization-time-only code path.
Adding the zeroing of fwd_progress will result in a net increase in the
number of lines of code.

So what am I missing here?

							Thanx, Paul

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ