[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CANn89iKv+4pJRinUwTfYM4TbQ26nqkT8S11-tPNCmhPPJgv_UQ@mail.gmail.com>
Date: Sat, 21 Dec 2024 10:04:21 +0100
From: Eric Dumazet <edumazet@...gle.com>
To: Dheeraj Reddy Jonnalagadda <dheeraj.linuxdev@...il.com>
Cc: jasowang@...hat.com, akpm@...ux-foundation.org, surenb@...gle.com,
jack@...e.cz, linux-kernel@...r.kernel.org
Subject: Re: [PATCH include] ptr_ring: fix potential race in ptr_ring_resize_multiple_bh_noprof
On Sat, Dec 21, 2024 at 7:16 AM Dheeraj Reddy Jonnalagadda
<dheeraj.linuxdev@...il.com> wrote:
>
> The ptr_ring_resize_multiple_bh_noprof function may have a race condition
> where queues[i] is freed after releasing the locks. Since this function
> can be called from multiple threads, another thread could potentially modify
> queues[i] between the unlock and kvfree operations.
>
> Move the kvfree inside the critical section to ensure atomicity of the
> queue swap and cleanup operations.
>
> Fixes: 59e6ae53248a("ptr_ring: support resizing multiple queues")
> Closes: https://scan7.scan.coverity.com/#/project-view/52337/11354?selectedIssue=1602644
> Signed-off-by: Dheeraj Reddy Jonnalagadda <dheeraj.linuxdev@...il.com>
> ---
> include/linux/ptr_ring.h | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/include/linux/ptr_ring.h b/include/linux/ptr_ring.h
> index 551329220e4f..cb06c74fc791 100644
> --- a/include/linux/ptr_ring.h
> +++ b/include/linux/ptr_ring.h
> @@ -641,13 +641,11 @@ static inline int ptr_ring_resize_multiple_bh_noprof(struct ptr_ring **rings,
> spin_lock(&(rings[i])->producer_lock);
> queues[i] = __ptr_ring_swap_queue(rings[i], queues[i],
> size, gfp, destroy);
> + kvfree(queues[i]);
> spin_unlock(&(rings[i])->producer_lock);
> spin_unlock_bh(&(rings[i])->consumer_lock);
> }
>
> - for (i = 0; i < nrings; ++i)
> - kvfree(queues[i]);
> -
> kfree(queues);
I do not think this patch makes sense.
queues[] is private to this thread, there is no possible race.
Powered by blists - more mailing lists