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: <8bc08bc1-df91-45c5-829a-a0beb0f74652@kernel.dk>
Date: Mon, 16 Sep 2024 05:03:33 -0600
From: Jens Axboe <axboe@...nel.dk>
To: Felix Moessbauer <felix.moessbauer@...mens.com>
Cc: io-uring <io-uring@...r.kernel.org>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 1/1] io_uring/sqpoll: do not put cpumasks on stack

On 9/16/24 4:55 AM, Felix Moessbauer wrote:
> Putting the cpumask on the stack is deprecated for a long time (since
> 2d3854a37e8), as these can be big. Given that, we port-over the stack
> allocated mask to the cpumask allocation api.

I'd change that last sentence to:

Given that, change the on-stack allocation of allowed_mask to be
dynamically allocated.

> diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c
> index 7adfcf6818ff..44b9f58e11b6 100644
> --- a/io_uring/sqpoll.c
> +++ b/io_uring/sqpoll.c
> @@ -461,15 +461,22 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
>  			return 0;
>  
>  		if (p->flags & IORING_SETUP_SQ_AFF) {
> -			struct cpumask allowed_mask;
> +			cpumask_var_t allowed_mask;
>  			int cpu = p->sq_thread_cpu;
>  
>  			ret = -EINVAL;
>  			if (cpu >= nr_cpu_ids || !cpu_online(cpu))
>  				goto err_sqpoll;
> -			cpuset_cpus_allowed(current, &allowed_mask);
> -			if (!cpumask_test_cpu(cpu, &allowed_mask))
> +			if (!alloc_cpumask_var(&allowed_mask, GFP_KERNEL)) {
> +				ret = -ENOMEM;
>  				goto err_sqpoll;
> +			}
> +			cpuset_cpus_allowed(current, allowed_mask);
> +			if (!cpumask_test_cpu(cpu, allowed_mask)) {
> +				free_cpumask_var(allowed_mask);
> +				goto err_sqpoll;
> +			}
> +			free_cpumask_var(allowed_mask);
>  			sqd->sq_cpu = cpu;

The kernel generally does:

ret = -ESOMEERROR;
if (fails_check)
	goto err_label;

and you're now mixing the two here. To keep it consistent, it'd be
better to do :

ret = -ENOMEM before the alloc, and then re-set it to -EINVAL before the
cpumask check.

-- 
Jens Axboe

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ