[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z6-SQtS-SuxiBzoK@casper.infradead.org>
Date: Fri, 14 Feb 2025 18:58:10 +0000
From: Matthew Wilcox <willy@...radead.org>
To: Jeongjun Park <aha310510@...il.com>
Cc: akpm@...ux-foundation.org, Liam.Howlett@...cle.com, brauner@...nel.org,
lorenzo.stoakes@...cle.com, davidlohr.bueso@...com,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] ipc: fix to protect IPCS lookups using RCU instead of
semaphore
On Sat, Feb 15, 2025 at 03:01:57AM +0900, Jeongjun Park wrote:
> In shm_destroy_orphaned(), we are not performing updates to the IPCS and are
> only calling idr_for_each(), which can be protected by the RCU read-critical
> section.
>
> And if idr_for_each() is not protected by the RCU read-critical section,
> then when radix_tree_node_free() is called to free the struct radix_tree_node
> through call_rcu(), the node will be freed immediately, and when reading the
> next node in radix_tree_for_each_slot(), the memory that has already been
> freed may be read.
>
> Therefore, I think it is appropriate to use RCU instead of semaphore to
> protect it.
>
> Fixes: d9a605e40b13 ("ipc: rename ids->rw_mutex")
This does not fix that commit. That's just the last commit that touches
this line. Indeed, it doesn't fix anything.
You need to justify why making this change is desirable. Does it speed
anything up?
> Signed-off-by: Jeongjun Park <aha310510@...il.com>
> ---
> ipc/shm.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/ipc/shm.c b/ipc/shm.c
> index 99564c870084..8fd87c4e5dc8 100644
> --- a/ipc/shm.c
> +++ b/ipc/shm.c
> @@ -430,10 +430,10 @@ static int shm_try_destroy_orphaned(int id, void *p, void *data)
>
> void shm_destroy_orphaned(struct ipc_namespace *ns)
> {
> - down_write(&shm_ids(ns).rwsem);
> + rcu_read_lock();
> if (shm_ids(ns).in_use)
> idr_for_each(&shm_ids(ns).ipcs_idr, &shm_try_destroy_orphaned, ns);
> - up_write(&shm_ids(ns).rwsem);
> + rcu_read_unlock();
> }
>
> /* Locking assumes this will only be called with task == current */
> --
Powered by blists - more mailing lists