mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4] ceph: Use unsigned types for snapshot split counts
@ 2026-11-26  3:27 Kaho Jiang
  2026-11-27  0:34 ` Xiubo Li
  2026-11-30 15:44 ` Alex Markuze
  0 siblings, 2 replies; 3+ messages in thread
From: Kaho Jiang @ 2026-11-26  3:27 UTC (permalink / raw)
  To: Ilya Dryomov, Alex Markuze, Xiubo Li, Viacheslav Dubeyko
  Cc: ceph-devel, linux-kernel, stable, co+408fcc361565713f, Kaho Jiang

ceph_handle_snap() stores the unsigned 32-bit split counts from the
message header in signed integers. Values with the high bit set become
negative and, on 64-bit systems, cause the subsequent pointer arithmetic
to move backwards before the message buffer.

BUG: KASAN: slab-out-of-bounds in ceph_update_snap_trace (fs/ceph/snap.c:815)
Read of size 8 at addr ffff888024f45478 by task kworker/1:3/2220
CPU: 1 UID: 0 PID: 2220 Comm: kworker/1:3 Not tainted 7.4.0-rc2-g7475ea8b5861 #1 PREEMPT(full)
Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Workqueue: ceph-msgr ceph_con_workfn
Call Trace:
 <TASK>
 dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120)
 print_report (mm/kasan/report.c:378 mm/kasan/report.c:482)
 ceph_update_snap_trace (fs/ceph/snap.c:815)
 ceph_handle_snap (fs/ceph/snap.c:1057)
 __pfx_ceph_update_snap_trace (./include/linux/list.h:172)
 down_write (kernel/locking/rwsem.c:1350 kernel/locking/rwsem.c:1356 kernel/locking/rwsem.c:1632)
 __pfx_down_write (kernel/locking/rwsem.c:602)
 ceph_handle_snap (fs/ceph/snap.c:1158)
 mds_dispatch (fs/ceph/mds_client.c:7298)
 find_held_lock (kernel/locking/lockdep.c:5401)
 ceph_con_process_message (net/ceph/messenger.c:1413)
 ceph_con_process_message (net/ceph/messenger.c:1424)
 ceph_con_in_msg_alloc (net/ceph/messenger.c:2094)
 ceph_con_v1_try_read (net/ceph/messenger_v1.c:1434)
 ceph_con_workfn (net/ceph/messenger.c:1576)
 process_one_work (kernel/workqueue.c:3495)
 worker_thread (kernel/workqueue.c:3578 kernel/workqueue.c:3659)
 kthread (kernel/kthread.c:436)
 ret_from_fork (arch/x86/kernel/process.c:158)
 ret_from_fork_asm (arch/x86/entry/entry_64.S:245)
 </TASK>
Kernel Offset: disabled

Use u32 for both counts and validate both split arrays against the
remaining message buffer before advancing the decode pointer. Use
size_mul() to detect multiplication overflow on 32-bit systems, and
ceph_decode_skip_n() for checked skips in the non-split branch.

Fixes: 963b61eb041e ("ceph: snapshot management")
Cc: stable@vger.kernel.org
Reported-by: co+408fcc361565713f@bugs.sh
Assisted-by: LLM
Signed-off-by: Kaho Jiang <kj2864@nyu.edu>
---
 fs/ceph/mds_client.c | 34 +++++++++++++++++++++++++++++++++-
 fs/ceph/mds_client.h |  3 +++
 fs/ceph/snap.c       | 33 +++++++++++----------------------
 3 files changed, 47 insertions(+), 23 deletions(-)

diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 15df9d22008d..4b416fa2ad1a 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -69,6 +69,7 @@ static void __wake_requests(struct ceph_mds_client *mdsc,
 static void ceph_cap_release_work(struct work_struct *work);
 static void ceph_cap_reclaim_work(struct work_struct *work);
 static void ceph_mdsc_reset_workfn(struct work_struct *work);
+static void ceph_mdsc_snap_fence_workfn(struct work_struct *work);
 
 static const struct ceph_connection_operations mds_con_ops;
 
@@ -4435,7 +4436,7 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
 
 	/* Defer closing the sessions after s_mutex lock being released */
 	if (close_sessions)
-		ceph_mdsc_close_sessions(mdsc);
+		ceph_mdsc_schedule_snap_fence(mdsc);
 	ceph_blog_exit(&__ji);
 	return;
 }
@@ -6568,6 +6569,8 @@ int ceph_mdsc_init(struct ceph_fs_client *fsc)
 	init_waitqueue_head(&mdsc->reset_state.blocked_wq);
 	atomic_set(&mdsc->reset_state.blocked_requests, 0);
 	INIT_WORK(&mdsc->reset_work, ceph_mdsc_reset_workfn);
+	INIT_WORK(&mdsc->snap_fence_work, ceph_mdsc_snap_fence_workfn);
+	atomic_set(&mdsc->snap_fence_pending, 0);
 
 	ceph_caps_init(mdsc);
 	ceph_adjust_caps_max_min(mdsc, fsc->mount_options);
@@ -6962,6 +6965,34 @@ static bool done_closing_sessions(struct ceph_mds_client *mdsc, int skipped)
 	return atomic_read(&mdsc->num_sessions) <= skipped;
 }
 
+static void ceph_mdsc_snap_fence_workfn(struct work_struct *work)
+{
+	struct ceph_mds_client *mdsc =
+		container_of(work, struct ceph_mds_client, snap_fence_work);
+	struct ceph_client *cl = mdsc->fsc->client;
+	int ret;
+
+	ret = ceph_monc_blocklist_add(&cl->monc, &cl->msgr.inst.addr);
+	if (ret)
+		pr_err_client(cl, "failed to blocklist %s: %d\n",
+			      ceph_pr_addr(&cl->msgr.inst.addr), ret);
+
+	ceph_mdsc_close_sessions(mdsc);
+	ceph_dec_osd_stopping_blocker(mdsc);
+}
+
+void ceph_mdsc_schedule_snap_fence(struct ceph_mds_client *mdsc)
+{
+	if (atomic_cmpxchg(&mdsc->snap_fence_pending, 0, 1))
+		return;
+
+	if (!ceph_inc_osd_stopping_blocker(mdsc))
+		return;
+
+	if (!queue_work(system_dfl_wq, &mdsc->snap_fence_work))
+		ceph_dec_osd_stopping_blocker(mdsc);
+}
+
 /*
  * called after sb is ro or when metadata corrupted.
  */
@@ -7120,6 +7151,7 @@ void ceph_mdsc_destroy(struct ceph_fs_client *fsc)
 	wake_up_all(&mdsc->reset_state.blocked_wq);
 
 	cancel_work_sync(&mdsc->reset_work);
+	cancel_work_sync(&mdsc->snap_fence_work);
 	ceph_mdsc_stop(mdsc);
 
 	ceph_metric_destroy(&mdsc->metric);
diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h
index ff9ba09f3b59..65d0fd878741 100644
--- a/fs/ceph/mds_client.h
+++ b/fs/ceph/mds_client.h
@@ -590,6 +590,8 @@ struct ceph_mds_client {
 	struct ceph_client_metric metric;
 	struct work_struct	reset_work;
 	struct ceph_client_reset_state reset_state;
+	struct work_struct	snap_fence_work;
+	atomic_t		snap_fence_pending;
 	struct ceph_subvolume_metrics_tracker subvol_metrics;
 
 	/* Subvolume metrics send tracking */
@@ -633,6 +635,7 @@ int ceph_mdsc_wait_for_reset(struct ceph_mds_client *mdsc);
 
 extern int ceph_mdsc_init(struct ceph_fs_client *fsc);
 extern void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc);
+extern void ceph_mdsc_schedule_snap_fence(struct ceph_mds_client *mdsc);
 extern void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc);
 extern void ceph_mdsc_destroy(struct ceph_fs_client *fsc);
 
diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
index e03d89db61fe..968486b0c2d4 100644
--- a/fs/ceph/snap.c
+++ b/fs/ceph/snap.c
@@ -796,11 +796,9 @@ int ceph_update_snap_trace(struct ceph_mds_client *mdsc,
 	struct ceph_snap_realm *realm;
 	struct ceph_snap_realm *first_realm = NULL;
 	struct ceph_snap_realm *realm_to_rebuild = NULL;
-	struct ceph_client *client = mdsc->fsc->client;
 	size_t snaps_len;
 	int rebuild_snapcs;
 	int err = -ENOMEM;
-	int ret;
 	LIST_HEAD(dirty_realms);
 
 	lockdep_assert_held_write(&mdsc->snap_rwsem);
@@ -924,22 +922,8 @@ int ceph_update_snap_trace(struct ceph_mds_client *mdsc,
 	 * When receiving a corrupted snap trace we don't know what
 	 * exactly has happened in MDS side. And we shouldn't continue
 	 * writing to OSD, which may corrupt the snapshot contents.
-	 *
-	 * Just try to blocklist this kclient and then this kclient
-	 * must be remounted to continue after the corrupted metadata
-	 * fixed in the MDS side.
 	 */
 	WRITE_ONCE(mdsc->fsc->mount_state, CEPH_MOUNT_FENCE_IO);
-	ret = ceph_monc_blocklist_add(&client->monc, &client->msgr.inst.addr);
-	if (ret)
-		pr_err_client(cl, "failed to blocklist %s: %d\n",
-			      ceph_pr_addr(&client->msgr.inst.addr), ret);
-
-	pr_warn_ratelimited_client(cl, "%s %s%sdo remount to continue%s",
-			    __func__,
-			    ret ? "" : ceph_pr_addr(&client->msgr.inst.addr),
-			    ret ? "" : " was blocklisted, ",
-			    err == -EIO ? " after corrupted snaptrace is fixed" : "");
 
 	return err;
 }
@@ -1039,7 +1023,7 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
 	void *p = msg->front.iov_base;
 	void *e = p + msg->front.iov_len;
 	struct ceph_mds_snap_head *h;
-	int num_split_inos, num_split_realms;
+	u32 num_split_inos, num_split_realms;
 	__le64 *split_inos = NULL, *split_realms = NULL;
 	int i;
 	int locked_rwsem = 0;
@@ -1053,7 +1037,7 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
 
 	/* decode */
 	if (msg->front.iov_len < sizeof(*h))
-		goto bad;
+		goto fail;
 	h = p;
 	op = le32_to_cpu(h->op);
 	split = le64_to_cpu(h->split);   /* non-zero if we are splitting an
@@ -1079,10 +1063,12 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
 		 * child.
 		 */
 		split_inos = p;
+		ceph_decode_need(&p, e, size_mul(num_split_inos, sizeof(u64)), fail);
 		p += sizeof(u64) * num_split_inos;
 		split_realms = p;
+		ceph_decode_need(&p, e, size_mul(num_split_realms, sizeof(u64)), fail);
 		p += sizeof(u64) * num_split_realms;
-		ceph_decode_need(&p, e, sizeof(*ri), bad);
+		ceph_decode_need(&p, e, sizeof(*ri), fail);
 		/* we will peek at realm info here, but will _not_
 		 * advance p, as the realm update will occur below in
 		 * ceph_update_snap_trace. */
@@ -1159,8 +1145,8 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
 		 * positioned at the start of realm info, as expected by
 		 * ceph_update_snap_trace().
 		 */
-		p += sizeof(u64) * num_split_inos;
-		p += sizeof(u64) * num_split_realms;
+		ceph_decode_skip_n(&p, e, size_mul(num_split_inos, sizeof(u64)), fail);
+		ceph_decode_skip_n(&p, e, size_mul(num_split_realms, sizeof(u64)), fail);
 	}
 
 	/*
@@ -1187,6 +1173,9 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
 	ceph_blog_exit(&__ji);
 	return;
 
+fail:
+	WRITE_ONCE(mdsc->fsc->mount_state, CEPH_MOUNT_FENCE_IO);
+	close_sessions = true;
 bad:
 	pr_err_client(cl, "corrupt snap message from mds%d\n", mds);
 	ceph_msg_dump(msg);
@@ -1197,7 +1186,7 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
 	ceph_dec_mds_stopping_blocker(mdsc);
 
 	if (close_sessions)
-		ceph_mdsc_close_sessions(mdsc);
+		ceph_mdsc_schedule_snap_fence(mdsc);
 	ceph_blog_exit(&__ji);
 	return;
 }
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] ceph: Use unsigned types for snapshot split counts
  2026-11-26  3:27 [PATCH v4] ceph: Use unsigned types for snapshot split counts Kaho Jiang
@ 2026-11-27  0:34 ` Xiubo Li
  2026-11-30 15:44 ` Alex Markuze
  1 sibling, 0 replies; 3+ messages in thread
From: Xiubo Li @ 2026-11-27  0:34 UTC (permalink / raw)
  To: Kaho Jiang
  Cc: Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko, ceph-devel,
	linux-kernel, stable, co+408fcc361565713f

Hi Kaho,

On 11/26/26 11:27, Kaho Jiang wrote:
> ceph_handle_snap() stores the unsigned 32-bit split counts from the
> message header in signed integers. Values with the high bit set become
> negative and, on 64-bit systems, cause the subsequent pointer arithmetic
> to move backwards before the message buffer.

[...]

> Use u32 for both counts and validate both split arrays against the
> remaining message buffer before advancing the decode pointer. Use
> size_mul() to detect multiplication overflow on 32-bit systems, and
> ceph_decode_skip_n() for checked skips in the non-split branch.

This changelog only describes the first half of the patch.  v4 also
moves the blocklist out of ceph_update_snap_trace(), adds a fence work
and changes handle_reply() and the umount path, and none of that is
mentioned (the subject still says "Use unsigned types ...").

Could you split it into two patches?  The u32 + bounds checks are a
small stable fix on their own; the fence rework is not ready yet, see
below.

I tested v4 on a KASAN + lockdep kernel with a 2-active-MDS vstart
cluster, using a test-only module param patch that corrupts incoming
snap messages: num_split_inos/num_split_realms forced to 0xfffffff0,
or the snap trace in a CLIENT_SNAP, in a reply snapblob or in a cap
IMPORT truncated to 4 bytes.  Same injection on the base tree and on
v4, mount_timeout=20 unless said otherwise.

v4 no longer applies to the testing branch, since 11add64882a2 ("ceph:
remove BLOG instrumentation") removed the ceph_blog_exit() context
lines.  The conflicts are trivial; I tested it rebased onto testing
3f90412e989c.

> Fixes: 963b61eb041e ("ceph: snapshot management")
> Cc: stable@vger.kernel.org
> Reported-by: co+408fcc361565713f@bugs.sh
> Assisted-by: LLM
> Signed-off-by: Kaho Jiang <kj2864@nyu.edu>
> ---
>  fs/ceph/mds_client.c | 34 +++++++++++++++++++++++++++++++++-
>  fs/ceph/mds_client.h |  3 +++
>  fs/ceph/snap.c       | 33 +++++++++++----------------------
>  3 files changed, 47 insertions(+), 23 deletions(-)
>
> diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
> index 15df9d22008d..4b416fa2ad1a 100644
> --- a/fs/ceph/mds_client.c
> +++ b/fs/ceph/mds_client.c
[...]
> @@ -4435,7 +4436,7 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
>
>       /* Defer closing the sessions after s_mutex lock being released */
>       if (close_sessions)
> -             ceph_mdsc_close_sessions(mdsc);
> +             ceph_mdsc_schedule_snap_fence(mdsc);

With this change a corrupt reply snapblob deadlocks the msgr worker
and umount.

Earlier in handle_reply() the target inode is looked up/created with
ceph_get_inode() before the snapblob is parsed, and it is only
unlocked later in ceph_fill_trace().  When ceph_update_snap_trace()
fails we jump to out_err and the inode stays hashed in I_NEW.  That
part is old; on the base tree it shows up at umount as

  WARNING: fs/inode.c:1987 at iput_final+0x626/0x870, CPU#17: umount/5384

On the base tree the sessions are torn down synchronously right here in
the same msgr worker, which is most likely why no later message looks
the inode up.  With the deferred fence the sessions stay open for
another mount_timeout, a cap message for that inode arrives, and the
msgr worker waits on the I_NEW inode forever; umount then blocks
flushing the msgr workqueue:

  kworker/10:2 (ceph-msgr):
   wait_on_new_inode+0x1d1/0x3f0
   ilookup5+0x18f/0x1c0
   ceph_handle_caps+0x8a6/0x23c0 [ceph]
   mds_dispatch+0x21d/0x490 [ceph]
  umount:
   __flush_workqueue+0x3ad/0x10c0
   ceph_mdsc_pre_umount+0x1c3/0x410 [ceph]
   ceph_kill_sb+0x100/0x840 [ceph]

With a corrupt snapblob in the reply to a create in a snapshotted
directory, v4 hung like this in 4 out of 4 runs and the base tree in
0 out of 4.  The out_err path needs to discard_new_inode() the target
inode (or the snapblob has to be parsed before ceph_get_inode()),
whatever the fence ends up looking like.

[...]
> +static void ceph_mdsc_snap_fence_workfn(struct work_struct *work)
> +{
> +     struct ceph_mds_client *mdsc =
> +             container_of(work, struct ceph_mds_client, snap_fence_work);
> +     struct ceph_client *cl = mdsc->fsc->client;
> +     int ret;
> +
> +     ret = ceph_monc_blocklist_add(&cl->monc, &cl->msgr.inst.addr);
> +     if (ret)
> +             pr_err_client(cl, "failed to blocklist %s: %d\n",
> +                           ceph_pr_addr(&cl->msgr.inst.addr), ret);

The "was blocklisted, do remount to continue" warning that
ceph_update_snap_trace() used to print is gone.  The base tree prints

  ceph: ... ceph_update_snap_trace <addr> was blocklisted,
  do remount to continue after corrupted snaptrace is fixed

and with v4 nothing tells the admin why the mount stopped working.
Please print it here when the blocklist succeeds.

> +
> +     ceph_mdsc_close_sessions(mdsc);

Two problems here.

First, the client has just been blocklisted, so the MDSs never ack the
REQUEST_CLOSE and ceph_mdsc_close_sessions() always waits the full
mount_timeout (20.3 s in every run).  With mount_timeout=0 it waits
forever.  The base tree does the same thing in the ceph-msgr worker
(verified: kworker/23:1+ceph-msgr stuck in ceph_mdsc_close_sessions()
<- ceph_handle_snap()).  v4 frees the msgr worker, but the wait now
blocks umount instead, see ceph_mdsc_destroy() below.

With a non-zero mount_timeout, ceph_kill_sb() stops waiting for the
stopping blocker after mount_timeout ("umount timed out") and runs its
own ceph_mdsc_close_sessions() while this one is still running, so the
two teardowns overlap:

  [1456.265977] ceph: INJ close_sessions begin comm=kworker/u199:5 pid=10748
  [1476.083255] ceph: ... umount timed out, 0
  [1476.083614] ceph: INJ close_sessions begin comm=umount pid=14578
  [1476.084088] ceph: INJ close_sessions end comm=umount pid=14578 took 1 ms
  [1476.594193] ceph: INJ close_sessions end comm=kworker/u199:5
pid=10748 took 20329 ms

(the INJ lines come from my test patch.)

Second, ceph_mdsc_close_sessions() is the umount teardown, not a fence.
After the wait it unregisters the sessions and calls
ceph_cleanup_snapid_map() and ceph_cleanup_global_and_empty_realms()
while the mount is still alive and snapshot inodes still hold their
snapid maps.  Every run with a snapshot inode cached hit:

  WARNING: snap.c:1365 at ceph_cleanup_snapid_map+0x40e/0x660 [ceph]
   ceph_mdsc_close_sessions+0x5cf/0x739 [ceph]
   ceph_mdsc_snap_fence_workfn.cold+0x8/0x23 [ceph]
  ...
  BUG: KASAN: slab-use-after-free in atomic_dec_and_lock+0x1b/0xa0
  Write of size 4 at addr ffff888107909ba8 by task umount/7518
   ceph_put_snapid_map+0x36/0x2d0 [ceph]
   ceph_evict_inode+0x59c/0x9a0 [ceph]
  Allocated by: ceph_get_snapid_map <- ceph_fill_inode <- handle_reply
  Freed by:     ceph_cleanup_snapid_map <- ceph_mdsc_close_sessions
                <- ceph_mdsc_snap_fence_workfn

This one is old too (the base tree hits the same UAF through the
synchronous call), but moving the call into a work doesn't fix it, and
Alex's point about retaining the required references until the
deferred cleanup finishes applies here.  The teardown also leaves
in-flight MDS requests waiting: on the base tree a snapshot mkdir that
raced with the corrupt CLIENT_SNAP sat in ceph_mdsc_wait_request()
until it was killed.

So I don't think ceph_mdsc_close_sessions() belongs in this path.
CEPH_MOUNT_FENCE_IO is already set (new writes and creates got -EIO in
all my runs); after the blocklist this should fail the pending MDS
requests with -EIO and drop each session's caps, as the
force-umount/session-reject paths do, without the snapid map and realm
cleanup and without waiting for a close ack that can't come.  The full
teardown should stay in umount.

> +     ceph_dec_osd_stopping_blocker(mdsc);
> +}
[...]
> @@ -7120,6 +7151,7 @@ void ceph_mdsc_destroy(struct ceph_fs_client *fsc)
>       wake_up_all(&mdsc->reset_state.blocked_wq);
>
>       cancel_work_sync(&mdsc->reset_work);
> +     cancel_work_sync(&mdsc->snap_fence_work);

With mount_timeout=0 this never returns, because the work is stuck in
ceph_mdsc_close_sessions() above, and umount hangs in D state until the
box is reset:

  kworker/u110:5+events_unbound:
   ceph_mdsc_close_sessions+0x432/0x739 [ceph]
   ceph_mdsc_snap_fence_workfn.cold+0x8/0x23 [ceph]
  umount:
   cancel_work_sync+0x81/0xa0
   ceph_mdsc_destroy+0x200/0x850 [ceph]
   destroy_fs_client+0x127/0x3b0 [ceph]
   ceph_kill_sb+0x2e6/0x840 [ceph]

umount must not wait on this work without a bound.

>       ceph_mdsc_stop(mdsc);
[...]
> diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
> index e03d89db61fe..968486b0c2d4 100644
> --- a/fs/ceph/snap.c
> +++ b/fs/ceph/snap.c
[...]
> @@ -924,22 +922,8 @@ int ceph_update_snap_trace(struct ceph_mds_client *mdsc,
>        * When receiving a corrupted snap trace we don't know what
>        * exactly has happened in MDS side. And we shouldn't continue
>        * writing to OSD, which may corrupt the snapshot contents.
> -      *
> -      * Just try to blocklist this kclient and then this kclient
> -      * must be remounted to continue after the corrupted metadata
> -      * fixed in the MDS side.
>        */
>       WRITE_ONCE(mdsc->fsc->mount_state, CEPH_MOUNT_FENCE_IO);
> -     ret = ceph_monc_blocklist_add(&client->monc, &client->msgr.inst.addr);
> -     if (ret)
> -             pr_err_client(cl, "failed to blocklist %s: %d\n",
> -                           ceph_pr_addr(&client->msgr.inst.addr), ret);

ceph_update_snap_trace() has a third caller that this patch doesn't
convert: ceph_handle_caps() for CEPH_CAP_OP_IMPORT still calls
ceph_mdsc_close_sessions() directly.  So with this removal a corrupt
snap trace in a cap IMPORT fences the client but no longer blocklists
it, and the close still runs (and waits) in the msgr worker:

  base:  blocklisted=1, close_sessions in kworker/10:1 (ceph-msgr), 20105 ms
  v4:    blocklisted=0, close_sessions in kworker/4:2  (ceph-msgr), 20082 ms

[...]
> @@ -1079,10 +1063,12 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
>                * child.
>                */
>               split_inos = p;
> +             ceph_decode_need(&p, e, size_mul(num_split_inos, sizeof(u64)), fail);
>               p += sizeof(u64) * num_split_inos;
>               split_realms = p;
> +             ceph_decode_need(&p, e, size_mul(num_split_realms, sizeof(u64)), fail);

These checks are good.  On the base tree, forcing either count to
0xfffffff0 reproduces your report on both the SPLIT and the non-split
paths:

  BUG: KASAN: slab-out-of-bounds in ceph_update_snap_trace+0xe11/0x12a0 [ceph]
  Read of size 8 at addr ffff88816738cff8 by task kworker/17:0/5385
   ceph_update_snap_trace+0xe11/0x12a0 [ceph]
   ceph_handle_snap+0x3ec/0xea0 [ceph]

and with v4 the same messages are rejected with "corrupt snap message
from mds0" and no out-of-bounds access.

[...]

Thanks,
- Xiubo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] ceph: Use unsigned types for snapshot split counts
  2026-11-26  3:27 [PATCH v4] ceph: Use unsigned types for snapshot split counts Kaho Jiang
  2026-11-27  0:34 ` Xiubo Li
@ 2026-11-30 15:44 ` Alex Markuze
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Markuze @ 2026-11-30 15:44 UTC (permalink / raw)
  To: Kaho Jiang
  Cc: Ilya Dryomov, Xiubo Li, Viacheslav Dubeyko, ceph-devel,
	linux-kernel, stable, co+408fcc361565713f

Hi Kaho,

Please send the unsigned split counts and array bounds checks as a
standalone fix for stable. Check both the SPLIT and non-SPLIT paths
without changing the existing snapshot error handling.

Please keep the fencing changes separate. As Xiubo noted, when snap trace
decoding fails during a cap IMPORT, v4 drops the blocklist attempt but
still closes sessions from the messenger worker. The new fence worker
also runs unmount cleanup that can free snapid mappings still held by
live snapshot inodes.

Thanks,
Alex

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-30 15:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26  3:27 [PATCH v4] ceph: Use unsigned types for snapshot split counts Kaho Jiang
2026-11-27  0:34 ` Xiubo Li
2026-11-30 15:44 ` Alex Markuze

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®