[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241221061555.1071516-1-dheeraj.linuxdev@gmail.com>
Date: Sat, 21 Dec 2024 11:45:54 +0530
From: Dheeraj Reddy Jonnalagadda <dheeraj.linuxdev@...il.com>
To: edumazet@...gle.com,
jasowang@...hat.com
Cc: akpm@...ux-foundation.org,
surenb@...gle.com,
jack@...e.cz,
linux-kernel@...r.kernel.org
Subject: [PATCH RFC] possible atomicity issue in ptr_ring_resize_multiple_bh_noprof
Hi Maintainers,
While reviewing the ptr_ring_resize_multiple_bh_noprof function, I noticed
a potential atomicity issue. The function appears to be callable from multiple
threads, based on the locking patterns and _bh suffix.
The current code frees queues[i] after releasing locks:
for (i = 0; i < nrings; ++i) {
spin_lock_bh(&(rings[i])->consumer_lock);
spin_lock(&(rings[i])->producer_lock);
queues[i] = __ptr_ring_swap_queue(rings[i], queues[i],
size, gfp, destroy);
spin_unlock(&(rings[i])->producer_lock);
spin_unlock_bh(&(rings[i])->consumer_lock);
}
/* Free after releasing locks */
for (i = 0; i < nrings; ++i)
kvfree(queues[i]);
It seems that there could be a race condition where another thread modifies
queues[i] between the unlock and the kvfree. Would it be safer to do the
kvfree while still holding the locks and removing the kvfree loop later
as shown below?
for (i = 0; i < nrings; ++i) {
spin_lock_bh(&(rings[i])->consumer_lock);
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);
}
kfree(queues);
return 0;
I've attached a potential fix, but would appreciate confirmation on whether
this is actually an issue that needs addressing.
-Dheeraj
Powered by blists - more mailing lists