All of lore.kernel.org
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
To: "ceph-devel@vger.kernel.org" <ceph-devel@vger.kernel.org>,
	"enjou1224z@gmail.com" <enjou1224z@gmail.com>,
	"edragain@163.com" <edragain@163.com>
Cc: "sage@newdream.net" <sage@newdream.net>,
	"idryomov@gmail.com" <idryomov@gmail.com>,
	"dstsmallbird@foxmail.com" <dstsmallbird@foxmail.com>,
	"slava@dubeyko.com" <slava@dubeyko.com>,
	Alex Markuze <amarkuze@redhat.com>,
	"yuantan098@gmail.com" <yuantan098@gmail.com>
Subject: RE: [PATCH 1/1] libceph: use RCU to protect monmap in ceph_compare_options()
Date: Fri, 10 Jul 2026 16:33:50 +0000	[thread overview]
Message-ID: <522d0bf88c127d2c8ca4f4e5055e77e2918d4bd2.camel@ibm.com> (raw)
In-Reply-To: <235ac7b2-cb4d-474b-87f0-53a5962de59e@163.com>

On Fri, 2026-07-10 at 10:16 +0800, Yong Wang wrote:
> 
> 在 2026/7/9 6:43, Viacheslav Dubeyko 写道:
> > On Wed, 2026-07-08 at 11:03 +0800, Ren Wei wrote:
> > > From: Yong Wang <edragain@163.com>
> > > 
> > > ceph_compare_options() checks whether a new mount shares any monitor
> > > address with an existing client by walking client->monc.monmap via
> > > ceph_monmap_contains().  That comparison can run under sb_lock or
> > > rbd_client_list_lock, so it cannot take monc->mutex.
> > > 
> > > Meanwhile, monmap update handling replaces monc->monmap under
> > > monc->mutex and frees the old map immediately.  A concurrent shared-
> > > mount comparison can therefore dereference a freed monmap and walk
> > > stale mon_inst[] entries, triggering a use-after-free.
> > > 
> > > Protect the compare path with RCU and publish/free monitor maps with
> > > rcu_assign_pointer() and kfree_rcu().  Annotate monc->monmap as an
> > > RCU pointer and use rcu_dereference_protected() in mutex-protected
> > > paths to keep the accesses consistent with the new pointer contract.
> > > 
> > > This keeps the existing non-blocking comparison semantics while
> > > ensuring that replaced monmaps remain alive until readers are done.
> > 
> > The approach makes sense to me. However, I have some concern. If the replaced
> > monmap(s) could be in use with newly allocated one(s), then are we safe here?
> 
> The new monmap is fully allocated and initialized before publication, then
> installed with rcu_assign_pointer() under monc->mutex. Readers only dereference
> an RCU snapshot and treat the monmap as immutable, while the replaced monmap is
> freed with kfree_rcu(), which means the old map is not reclaimed immediately, 
> but is delayed until all readers that are still accessing it have exited the 
> read-side critical section.Readers only see either the old map or the new map.
> 
> So it is safe to use.
> 
> > Have you tried to run xfstests for the patch?
> 
> I ran the ceph xfstests in QEMU on the patched kernel, and all ceph-
> specific tests in the current tree passed: ceph/001-006.
> 
> 

The running only Ceph specific test-cases is not enough. The patch should
survive the auto group of xfstests.

Thanks,
Slava.

  reply	other threads:[~2026-07-10 16:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08  3:03 [PATCH 0/1] libceph: fix a monmap use-after-free in ceph_compare_options() Ren Wei
2026-07-08  3:03 ` [PATCH 1/1] libceph: use RCU to protect monmap " Ren Wei
2026-07-08 22:43   ` Viacheslav Dubeyko
2026-07-10  2:16     ` Yong Wang
2026-07-10 16:33       ` Viacheslav Dubeyko [this message]
2026-07-12  6:28         ` Yong Wang
2026-07-13 22:22           ` Viacheslav Dubeyko
     [not found] <cover.1783342642.git.edragain@163.com>
2026-07-07  2:44 ` Ren Wei

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=522d0bf88c127d2c8ca4f4e5055e77e2918d4bd2.camel@ibm.com \
    --to=slava.dubeyko@ibm.com \
    --cc=amarkuze@redhat.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=dstsmallbird@foxmail.com \
    --cc=edragain@163.com \
    --cc=enjou1224z@gmail.com \
    --cc=idryomov@gmail.com \
    --cc=sage@newdream.net \
    --cc=slava@dubeyko.com \
    --cc=yuantan098@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.