mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Ren Wei <n05ec@lzu.edu.cn>
Cc: linux-kernel@vger.kernel.org, ljs@kernel.org,
	Liam.Howlett@oracle.com, brauner@kernel.org, kees@kernel.org,
	aha310510@gmail.com, sergeh@kernel.org, segoon@openwall.com,
	yuantan098@gmail.com, yifanwucs@gmail.com,
	tomapufckgml@gmail.com, bird@lzu.edu.cn, zylzyl2333@gmail.com,
	Oleg Nesterov <oleg@redhat.com>, Serge Hallyn <serge@hallyn.com>,
	Vasiliy Kulikov <segoon@openwall.com>,
	Davidlohr Bueso <dave@stgolabs.net>
Subject: Re: [PATCH 1/1] ipc/shm: serialize orphan cleanup with shm_nattch updates
Date: Thu, 30 Apr 2026 08:37:43 -0700	[thread overview]
Message-ID: <20260430083743.b8c2ae998664c346ab3c8091@linux-foundation.org> (raw)
In-Reply-To: <9d97cc1031de2d0bace0edf3a668818aa2f4eca6.1777410234.git.zylzyl2333@gmail.com>

On Thu, 30 Apr 2026 13:21:34 +0800 Ren Wei <n05ec@lzu.edu.cn> wrote:

> From: Yilin Zhu <zylzyl2333@gmail.com>
> 
> shm_destroy_orphaned() walks the shm idr under shm_ids(ns).rwsem, but
> that does not serialize all fields tested by shm_may_destroy().  In
> particular, shm_nattch is updated while holding shm_perm.lock, and attach
> paths can do that without holding the rwsem.
> 
> Do not decide that an orphaned segment is unused before taking the object
> lock.  Move the shm_may_destroy() check under shm_perm.lock, matching the
> other destroy paths, and unlock the segment when it no longer qualifies
> for removal.

Thanks.

> Fixes: 4c677e2eefdb ("shm: optimize locking and ipc_namespace getting")

Let's cc more people who were involved in 4c677e2eefdb.

And Davidlohr, who might have opinions.

> Cc: stable@kernel.org
> Reported-by: Yuan Tan <yuantan098@gmail.com>
> Reported-by: Yifan Wu <yifanwucs@gmail.com>
> Reported-by: Juefei Pu <tomapufckgml@gmail.com>
> Reported-by: Xin Liu <bird@lzu.edu.cn>
> Signed-off-by: Yilin Zhu <zylzyl2333@gmail.com>
> Signed-off-by: Ren Wei <n05ec@lzu.edu.cn>
> ---
>  ipc/shm.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/ipc/shm.c b/ipc/shm.c
> index a95dae447707..b3e8a58e177d 100644
> --- a/ipc/shm.c
> +++ b/ipc/shm.c
> @@ -418,15 +418,17 @@ static int shm_try_destroy_orphaned(int id, void *p, void *data)
>  	 * We want to destroy segments without users and with already
>  	 * exit'ed originating process.
>  	 *
> -	 * As shp->* are changed under rwsem, it's safe to skip shp locking.
> +	 * shm_nattch can be changed under shm_perm.lock without holding the
> +	 * rwsem, so take the object lock before checking shm_may_destroy().
>  	 */
>  	if (!list_empty(&shp->shm_clist))
>  		return 0;
>  
> -	if (shm_may_destroy(shp)) {
> -		shm_lock_by_ptr(shp);
> +	shm_lock_by_ptr(shp);
> +	if (shm_may_destroy(shp))
>  		shm_destroy(ns, shp);
> -	}
> +	else
> +		shm_unlock(shp);
>  	return 0;
>  }


  reply	other threads:[~2026-04-30 15:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1777410234.git.zylzyl2333@gmail.com>
2026-04-30  5:21 ` Ren Wei
2026-04-30 15:37   ` Andrew Morton [this message]
2026-05-02 18:51     ` Davidlohr Bueso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260430083743.b8c2ae998664c346ab3c8091@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=aha310510@gmail.com \
    --cc=bird@lzu.edu.cn \
    --cc=brauner@kernel.org \
    --cc=dave@stgolabs.net \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=n05ec@lzu.edu.cn \
    --cc=oleg@redhat.com \
    --cc=segoon@openwall.com \
    --cc=serge@hallyn.com \
    --cc=sergeh@kernel.org \
    --cc=tomapufckgml@gmail.com \
    --cc=yifanwucs@gmail.com \
    --cc=yuantan098@gmail.com \
    --cc=zylzyl2333@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®