FAILED: patch "[PATCH] ceph: cap delegated inode count in ceph_parse_deleg_inos()" failed to apply to 6.1-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 4bd3158bd62466d57ed72a3f7bc5f205fedd6919
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090355-tradition-although-cffd@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 4bd3158bd62466d57ed72a3f7bc5f205fedd6919 Mon Sep 17 00:00:00 2001
From: Michael Bommarito <[email protected]>
Date: Tue, 7 Jul 2026 14:06:00 -0400
Subject: [PATCH] ceph: cap delegated inode count in ceph_parse_deleg_inos()
ceph_parse_deleg_inos() decodes interval sets of delegated inode numbers from an MDS create-with-delegation reply. For each set it reads a 64-bit start and a 64-bit len with ceph_decode_64_safe(), which only validates that the eight bytes are present in the message, not the value, and then loops over len while inserting entries into s_delegated_inos.
len is fully attacker controlled. A malicious or compromised MDS can send one huge interval, many intervals in one reply, duplicate intervals, or repeated replies that accumulate delegated inodes on the same session. The original code bounded none of these and could spin the insert loop or grow the xarray without limit.
Bound both dimensions with a single enforcement point. Track the number of delegated inodes held by each MDS session in an atomic counter and grow it only in ceph_insert_deleg_ino(), which uses atomic_add_unless() to refuse to push the count past CEPH_MAX_DELEG_INOS. Because that helper is the only place the counter grows, the per-session population can never exceed the cap, so no separate per-session pre-check is needed. The counter is decremented when async create consumes a delegated inode or when an insert fails, incremented when a delegated inode is restored, initialized with the session xarray, and reset when reconnect destroys the xarray.
A per-session cap alone still lets one reply spin the insert loop on duplicate ranges without growing the counter, so also cap the aggregate interval length accepted from a single reply. Together these bound both the loop trip count per reply and the xarray population across replies.
The cap is a fixed, client-chosen constant rather than a value derived from the MDS. mds_client_prealloc_inos is a userspace MDS configuration option; it is never sent to the kernel client on the wire, and a server-supplied bound could not be trusted for a defensive limit in any case. The constant is set well above that option's documented default of 1000 (a generous multiple), so legitimate refill behavior is unaffected while the CPU and xarray memory a malformed delegation stream can consume stays bounded.
Impact: a malicious or compromised Ceph MDS can no longer make a client spin through an unbounded delegated-inode interval or grow one session's delegated-inode xarray without limit.
fs/ceph/mds_client.c +53 -6
@@ -619,10 +619,36 @@ static int parse_reply_info_filelock(void **p, void *end,#define DELEGATED_INO_AVAILABLE xa_mk_value(1) +static int ceph_insert_deleg_ino (struct ceph_mds_session *s,u64 ino) +{ +struct ceph_client *cl = s->s_mdsc->fsc->client; +int err; + +/* +* Cap how many delegated inodes a single session may hold. This is +* the only place that grows the count, so atomic_add_unless() bounds +* it at exactly CEPH_MAX_DELEG_INOS; s_num_deleg_inos can never exceed +* that. +*/ +if (!atomic_add_unless (&s->s_num_deleg_inos,1 ,CEPH_MAX_DELEG_INOS )) { +pr_warn_ratelimited_client (cl, +"MDS session already holds %d delegated inodes\n" , +CEPH_MAX_DELEG_INOS ); +return -EOVERFLOW ; + } + + err =xa_insert (&s->s_delegated_inos, ino,DELEGATED_INO_AVAILABLE , +GFP_KERNEL ); +if (err) +atomic_dec (&s->s_num_deleg_inos); +return err; +} +static int ceph_parse_deleg_inos (void **p,void *end,struct ceph_mds_session *s) {struct ceph_client *cl = s->s_mdsc->fsc->client; +u64 msg_deleg_inos =0 ;u32 sets;ceph_decode_32_safe (p, end, sets, bad);
@@ -640,16 +666,34 @@ static int ceph_parse_deleg_inos(void **p, void *end, start, len);continue ; } + +/* +* Bound the number of inodes one reply may delegate. +* ceph_insert_deleg_ino() separately caps the per-session +* population, so this only has to stop one reply from spinning +* the insert loop under an attacker-controlled len. +*/ +if (len > (u64 )CEPH_MAX_DELEG_INOS || + msg_deleg_inos > (u64 )CEPH_MAX_DELEG_INOS - len) { +pr_warn_ratelimited_client (cl, +"MDS reply delegates too many inodes (have %llu, +%llu, max %d)\n" , + msg_deleg_inos, len,CEPH_MAX_DELEG_INOS ); +return -EIO ; + } + msg_deleg_inos += len; +while (len--) { -int err =xa_insert (&s->s_delegated_inos, start++, -DELEGATED_INO_AVAILABLE , -GFP_KERNEL ); +int err =ceph_insert_deleg_ino (s, start++); +if (!err) {doutc (cl,"added delegated inode 0x%llx\n" , start -1 ); }else if (err == -EBUSY ) {pr_warn_client (cl,"MDS delegated inode 0x%llx more than once.\n" , start -1 ); + }else if (err == -EOVERFLOW ) { +/* ceph_insert_deleg_ino() already warned. */ +return -EIO ; }else {return err; }
@@ -667,16 +711,17 @@ u64 ceph_get_deleg_ino(struct ceph_mds_session *s)xa_for_each (&s->s_delegated_inos, ino, val) { val =xa_erase (&s->s_delegated_inos, ino); -if (val ==DELEGATED_INO_AVAILABLE ) +if (val ==DELEGATED_INO_AVAILABLE ) { +atomic_dec (&s->s_num_deleg_inos);return ino; + } } return 0; }int ceph_restore_deleg_ino (struct ceph_mds_session *s,u64 ino) { -return xa_insert (&s->s_delegated_inos, ino,DELEGATED_INO_AVAILABLE , -GFP_KERNEL ); +return ceph_insert_deleg_ino (s, ino); }#else /* BITS_PER_LONG == 64 */ /*
@@ -1063,6 +1108,7 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,INIT_LIST_HEAD (&s->s_waiting);INIT_LIST_HEAD (&s->s_unsafe);xa_init (&s->s_delegated_inos); +atomic_set (&s->s_num_deleg_inos,0 );INIT_LIST_HEAD (&s->s_cap_releases);INIT_WORK (&s->s_cap_release_work, ceph_cap_release_work);
@@ -5115,6 +5161,7 @@ static int send_mds_reconnect(struct ceph_mds_client *mdsc,/* Serialized by s_mutex against concurrent ceph_get_deleg_ino(). */ xa_destroy (&session->s_delegated_inos); +atomic_set (&session->s_num_deleg_inos,0 );if (session->s_state ==CEPH_MDS_SESSION_CLOSED || session->s_state ==CEPH_MDS_SESSION_REJECTED ) { pr_info_client(cl, "mds%d skipping reconnect, session %s\n",
fs/ceph/mds_client.h +1 -0
@@ -300,6 +300,7 @@ struct ceph_mds_session {struct list_head s_waiting;/* waiting requests */ struct list_head s_unsafe;/* unsafe requests */ struct xarray s_delegated_inos; +atomic_t s_num_deleg_inos; };/*
fs/ceph/super.h +9 -0
@@ -641,6 +641,15 @@ static inline int ceph_ino_compare(struct inode *inode, void *data)#define CEPH_MDS_INO_LOG_OFFSET (2 * CEPH_MAX_MDS)#define CEPH_INO_SYSTEM_BASE ((6*CEPH_MAX_MDS) + (CEPH_MAX_MDS * CEPH_NUM_STRAY)) +/* +* Upper bound on the number of delegated inodes a single MDS session may +* hold. The MDS normally hands out a small preallocation window (the +* userspace mds_client_prealloc_inos option defaults to 1000) and refills +* it as the client consumes entries. This leaves generous headroom while +* bounding the CPU and memory a malformed delegation interval can consume. +*/ +#define CEPH_MAX_DELEG_INOS 8192 +static inline bool ceph_vino_is_reserved (const struct ceph_vino vino) { if (vino.ino >= CEPH_INO_SYSTEM_BASE ||
Sasha Levin
maintainerPATCH 1/3 ceph: remove unnecessary check for NULL in parse_longname()
From: Luís Henriques <[email protected]>
[ Upstream commit 2816a09678f50fc6a69e742e90cb1fd7a9f1f9ff ]
Function ceph_get_inode() never returns NULL; instead it returns an ERR_PTR() if something fails. Thus, the check for NULL in parse_longname() is useless and can be dropped. Instead, move there the debug code that does the error checking so that it's only executed if ceph_get_inode() is called.
Stable-dependency adaptation: fs/ceph/crypto.c is not present in 6.1, so drop the original hunk. Instead, carry the minimal existing-code context needed by the follow-up: use client-aware logging in the delegated-inode parser, serialize the delegated-inode xarray teardown, and reject reconnects for terminal sessions. This gives the follow-up's counter reset a clean and correct insertion point.
[ sashal: Reduced backport -- upstream 2816a09678f50 touches 1 file(s), this
backport carries 1. Not backported here:
fs/ceph/crypto.c
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: 4bd3158bd624 ("ceph: cap delegated inode count in ceph_parse_deleg_inos()")
--- fs/ceph/mds_client.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-)
fs/ceph/mds_client.c +25 -6
@@ -433,6 +433,7 @@ static int parse_reply_info_filelock(void **p, void *end,static int ceph_parse_deleg_inos (void **p,void *end,struct ceph_mds_session *s) { +struct ceph_client *cl = s->s_mdsc->fsc->client;u32 sets;ceph_decode_32_safe (p, end, sets, bad);
@@ -445,8 +446,9 @@ static int ceph_parse_deleg_inos(void **p, void *end,/* Don't accept a delegation of system inodes */ if (start <CEPH_INO_SYSTEM_BASE ) { -pr_warn_ratelimited ("ceph: ignoring reserved inode range delegation (start=0x%llx len=0x%llx)\n" , - start, len); +pr_warn_ratelimited_client (cl, +"ignoring reserved inode range delegation (start=0x%llx len=0x%llx)\n" , + start, len);continue ; }while (len--) {
@@ -454,10 +456,10 @@ static int ceph_parse_deleg_inos(void **p, void *end,DELEGATED_INO_AVAILABLE , GFP_KERNEL);if (!err) { -dout ("added delegated inode 0x%llx\n" , - start -1 ); +doutc (cl,"added delegated inode 0x%llx\n" , start -1 ); }else if (err == -EBUSY ) { -pr_warn ("MDS delegated inode 0x%llx more than once.\n" , +pr_warn_client (cl, +"MDS delegated inode 0x%llx more than once.\n" , start -1 ); }else {return err;
@@ -4200,6 +4202,7 @@ static int encode_snap_realms(struct ceph_mds_client *mdsc,static void send_mds_reconnect (struct ceph_mds_client *mdsc,struct ceph_mds_session *session) { +struct ceph_client *cl = mdsc->fsc->client;struct ceph_msg *reply;int mds = session->s_mds;int err = -ENOMEM ;
@@ -4218,9 +4221,21 @@ static void send_mds_reconnect(struct ceph_mds_client *mdsc,if (!reply) goto fail_nomsg; +mutex_lock (&session->s_mutex); + +/* Serialized by s_mutex against concurrent ceph_get_deleg_ino(). */ xa_destroy (&session->s_delegated_inos); +if (session->s_state ==CEPH_MDS_SESSION_CLOSED || + session->s_state ==CEPH_MDS_SESSION_REJECTED ) { +pr_info_client (cl,"mds%d skipping reconnect, session %s\n" , + mds, +ceph_session_state_name (session->s_state)); +mutex_unlock (&session->s_mutex); +ceph_msg_put (reply); + err = -ESTALE ; + goto fail_return; + } -mutex_lock (&session->s_mutex); session->s_state =CEPH_MDS_SESSION_RECONNECTING ; session->s_seq =0 ;
@@ -4361,6 +4376,10 @@ static void send_mds_reconnect(struct ceph_mds_client *mdsc, fail_nopagelist:pr_err ("error %d preparing reconnect for mds%d\n" , err, mds);return ; + +fail_return: +ceph_pagelist_release (recon_state.pagelist); +return ; }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 ceph: print cluster fsid and client global_id in all debug logs
From: Xiubo Li <[email protected]>
[ Upstream commit 38d46409c4639a1d659ebfa70e27a8bed6b8ee1d ]
Multiple CephFS mounts on a host is increasingly common so disambiguating messages like this is necessary and will make it easier to debug issues.
At the same this will improve the debug logs to make them easier to troubleshooting issues, such as print the ino# instead only printing the memory addresses of the corresponding inodes and print the dentry names instead of the corresponding memory addresses for the dentry,etc.
[ stable: retain only the delegated-inode parser conversion needed as
context for the dependent fix; the remaining debug-log churn is not required on this tree ]
[ sashal: Reduced backport -- upstream 38d46409c4639 touches 19 file(s), this
backport carries 1. Not backported here:
fs/ceph/acl.c
fs/ceph/addr.c
fs/ceph/caps.c
fs/ceph/crypto.c
fs/ceph/debugfs.c
fs/ceph/dir.c
fs/ceph/export.c
fs/ceph/file.c
... and 10 more
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: 4bd3158bd624 ("ceph: cap delegated inode count in ceph_parse_deleg_inos()")
--- fs/ceph/mds_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/mds_client.c +1 -1
@@ -437,7 +437,7 @@ static int ceph_parse_deleg_inos(void **p, void *end,u32 sets;ceph_decode_32_safe (p, end, sets, bad); -dout ("got %u sets of delegated inodes\n" , sets); +doutc (cl,"got %u sets of delegated inodes\n" , sets);while (sets--) {u64 start, len;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 ceph: cap delegated inode count in ceph_parse_deleg_inos()
In reply to Sasha LevinFrom: Michael Bommarito <[email protected]>
[ Upstream commit 4bd3158bd62466d57ed72a3f7bc5f205fedd6919 ]
ceph_parse_deleg_inos() decodes interval sets of delegated inode numbers from an MDS create-with-delegation reply. For each set it reads a 64-bit start and a 64-bit len with ceph_decode_64_safe(), which only validates that the eight bytes are present in the message, not the value, and then loops over len while inserting entries into s_delegated_inos.
len is fully attacker controlled. A malicious or compromised MDS can send one huge interval, many intervals in one reply, duplicate intervals, or repeated replies that accumulate delegated inodes on the same session. The original code bounded none of these and could spin the insert loop or grow the xarray without limit.
Bound both dimensions with a single enforcement point. Track the number of delegated inodes held by each MDS session in an atomic counter and grow it only in ceph_insert_deleg_ino(), which uses atomic_add_unless() to refuse to push the count past CEPH_MAX_DELEG_INOS. Because that helper is the only place the counter grows, the per-session population can never exceed the cap, so no separate per-session pre-check is needed. The counter is decremented when async create consumes a delegated inode or when an insert fails, incremented when a delegated inode is restored, initialized with the session xarray, and reset when reconnect destroys the xarray.
A per-session cap alone still lets one reply spin the insert loop on duplicate ranges without growing the counter, so also cap the aggregate interval length accepted from a single reply. Together these bound both the loop trip count per reply and the xarray population across replies.
The cap is a fixed, client-chosen constant rather than a value derived from the MDS. mds_client_prealloc_inos is a userspace MDS configuration option; it is never sent to the kernel client on the wire, and a server-supplied bound could not be trusted for a defensive limit in any case. The constant is set well above that option's documented default of 1000 (a generous multiple), so legitimate refill behavior is unaffected while the CPU and xarray memory a malformed delegation stream can consume stays bounded.
Impact: a malicious or compromised Ceph MDS can no longer make a client spin through an unbounded delegated-inode interval or grow one session's delegated-inode xarray without limit.
--- fs/ceph/mds_client.c | 59 +++++++++++++++++++++++++++++++++++++++----- fs/ceph/mds_client.h | 1 + fs/ceph/super.h | 9 +++++++ 3 files changed, 63 insertions(+), 6 deletions(-)
fs/ceph/mds_client.c +53 -6
@@ -430,10 +430,36 @@ static int parse_reply_info_filelock(void **p, void *end,#define DELEGATED_INO_AVAILABLE xa_mk_value(1) +static int ceph_insert_deleg_ino (struct ceph_mds_session *s,u64 ino) +{ +struct ceph_client *cl = s->s_mdsc->fsc->client; +int err; + +/* +* Cap how many delegated inodes a single session may hold. This is +* the only place that grows the count, so atomic_add_unless() bounds +* it at exactly CEPH_MAX_DELEG_INOS; s_num_deleg_inos can never exceed +* that. +*/ +if (!atomic_add_unless (&s->s_num_deleg_inos,1 ,CEPH_MAX_DELEG_INOS )) { +pr_warn_ratelimited_client (cl, +"MDS session already holds %d delegated inodes\n" , +CEPH_MAX_DELEG_INOS ); +return -EOVERFLOW ; + } + + err =xa_insert (&s->s_delegated_inos, ino,DELEGATED_INO_AVAILABLE , +GFP_KERNEL ); +if (err) +atomic_dec (&s->s_num_deleg_inos); +return err; +} +static int ceph_parse_deleg_inos (void **p,void *end,struct ceph_mds_session *s) {struct ceph_client *cl = s->s_mdsc->fsc->client; +u64 msg_deleg_inos =0 ;u32 sets;ceph_decode_32_safe (p, end, sets, bad);
@@ -451,16 +477,34 @@ static int ceph_parse_deleg_inos(void **p, void *end, start, len);continue ; } + +/* +* Bound the number of inodes one reply may delegate. +* ceph_insert_deleg_ino() separately caps the per-session +* population, so this only has to stop one reply from spinning +* the insert loop under an attacker-controlled len. +*/ +if (len > (u64 )CEPH_MAX_DELEG_INOS || + msg_deleg_inos > (u64 )CEPH_MAX_DELEG_INOS - len) { +pr_warn_ratelimited_client (cl, +"MDS reply delegates too many inodes (have %llu, +%llu, max %d)\n" , + msg_deleg_inos, len,CEPH_MAX_DELEG_INOS ); +return -EIO ; + } + msg_deleg_inos += len; +while (len--) { -int err =xa_insert (&s->s_delegated_inos, start++, -DELEGATED_INO_AVAILABLE , -GFP_KERNEL ); +int err =ceph_insert_deleg_ino (s, start++); +if (!err) {doutc (cl,"added delegated inode 0x%llx\n" , start -1 ); }else if (err == -EBUSY ) {pr_warn_client (cl,"MDS delegated inode 0x%llx more than once.\n" , start -1 ); + }else if (err == -EOVERFLOW ) { +/* ceph_insert_deleg_ino() already warned. */ +return -EIO ; }else {return err; }
@@ -478,16 +522,17 @@ u64 ceph_get_deleg_ino(struct ceph_mds_session *s)xa_for_each (&s->s_delegated_inos, ino, val) { val =xa_erase (&s->s_delegated_inos, ino); -if (val ==DELEGATED_INO_AVAILABLE ) +if (val ==DELEGATED_INO_AVAILABLE ) { +atomic_dec (&s->s_num_deleg_inos);return ino; + } } return 0; }int ceph_restore_deleg_ino (struct ceph_mds_session *s,u64 ino) { -return xa_insert (&s->s_delegated_inos, ino,DELEGATED_INO_AVAILABLE , -GFP_KERNEL ); +return ceph_insert_deleg_ino (s, ino); }#else /* BITS_PER_LONG == 64 */ /*
@@ -854,6 +899,7 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,INIT_LIST_HEAD (&s->s_waiting);INIT_LIST_HEAD (&s->s_unsafe);xa_init (&s->s_delegated_inos); +atomic_set (&s->s_num_deleg_inos,0 );INIT_LIST_HEAD (&s->s_cap_releases);INIT_WORK (&s->s_cap_release_work, ceph_cap_release_work);
@@ -4225,6 +4271,7 @@ static void send_mds_reconnect(struct ceph_mds_client *mdsc,/* Serialized by s_mutex against concurrent ceph_get_deleg_ino(). */ xa_destroy (&session->s_delegated_inos); +atomic_set (&session->s_num_deleg_inos,0 );if (session->s_state ==CEPH_MDS_SESSION_CLOSED || session->s_state ==CEPH_MDS_SESSION_REJECTED ) { pr_info_client(cl, "mds%d skipping reconnect, session %s\n",
fs/ceph/mds_client.h +1 -0
@@ -219,6 +219,7 @@ struct ceph_mds_session {struct list_head s_waiting;/* waiting requests */ struct list_head s_unsafe;/* unsafe requests */ struct xarray s_delegated_inos; +atomic_t s_num_deleg_inos; };/*
fs/ceph/super.h +9 -0
@@ -572,6 +572,15 @@ static inline int ceph_ino_compare(struct inode *inode, void *data)#define CEPH_MDS_INO_LOG_OFFSET (2 * CEPH_MAX_MDS)#define CEPH_INO_SYSTEM_BASE ((6*CEPH_MAX_MDS) + (CEPH_MAX_MDS * CEPH_NUM_STRAY)) +/* +* Upper bound on the number of delegated inodes a single MDS session may +* hold. The MDS normally hands out a small preallocation window (the +* userspace mds_client_prealloc_inos option defaults to 1000) and refills +* it as the client consumes entries. This leaves generous headroom while +* bounding the CPU and memory a malformed delegation interval can consume. +*/ +#define CEPH_MAX_DELEG_INOS 8192 +static inline bool ceph_vino_is_reserved (const struct ceph_vino vino) { if (vino.ino >= CEPH_INO_SYSTEM_BASE ||
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/3 ceph: remove unnecessary check for NULL in parse_longname()
In reply to [email protected]From: Luís Henriques <[email protected]>
[ Upstream commit 2816a09678f50fc6a69e742e90cb1fd7a9f1f9ff ]
Function ceph_get_inode() never returns NULL; instead it returns an ERR_PTR() if something fails. Thus, the check for NULL in parse_longname() is useless and can be dropped. Instead, move there the debug code that does the error checking so that it's only executed if ceph_get_inode() is called.
Stable-dependency adaptation: fs/ceph/crypto.c is not present in 6.1, so drop the original hunk. Instead, carry the minimal existing-code context needed by the follow-up: use client-aware logging in the delegated-inode parser, serialize the delegated-inode xarray teardown, and reject reconnects for terminal sessions. This gives the follow-up's counter reset a clean and correct insertion point.
[ sashal: Reduced backport -- upstream 2816a09678f50 touches 1 file(s), this
backport carries 1. Not backported here:
fs/ceph/crypto.c
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: 4bd3158bd624 ("ceph: cap delegated inode count in ceph_parse_deleg_inos()")
--- fs/ceph/mds_client.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-)
fs/ceph/mds_client.c +25 -6
@@ -433,6 +433,7 @@ static int parse_reply_info_filelock(void **p, void *end,static int ceph_parse_deleg_inos (void **p,void *end,struct ceph_mds_session *s) { +struct ceph_client *cl = s->s_mdsc->fsc->client;u32 sets;ceph_decode_32_safe (p, end, sets, bad);
@@ -445,8 +446,9 @@ static int ceph_parse_deleg_inos(void **p, void *end,/* Don't accept a delegation of system inodes */ if (start <CEPH_INO_SYSTEM_BASE ) { -pr_warn_ratelimited ("ceph: ignoring reserved inode range delegation (start=0x%llx len=0x%llx)\n" , - start, len); +pr_warn_ratelimited_client (cl, +"ignoring reserved inode range delegation (start=0x%llx len=0x%llx)\n" , + start, len);continue ; }while (len--) {
@@ -454,10 +456,10 @@ static int ceph_parse_deleg_inos(void **p, void *end,DELEGATED_INO_AVAILABLE , GFP_KERNEL);if (!err) { -dout ("added delegated inode 0x%llx\n" , - start -1 ); +doutc (cl,"added delegated inode 0x%llx\n" , start -1 ); }else if (err == -EBUSY ) { -pr_warn ("MDS delegated inode 0x%llx more than once.\n" , +pr_warn_client (cl, +"MDS delegated inode 0x%llx more than once.\n" , start -1 ); }else {return err;
@@ -4200,6 +4202,7 @@ static int encode_snap_realms(struct ceph_mds_client *mdsc,static void send_mds_reconnect (struct ceph_mds_client *mdsc,struct ceph_mds_session *session) { +struct ceph_client *cl = mdsc->fsc->client;struct ceph_msg *reply;int mds = session->s_mds;int err = -ENOMEM ;
@@ -4218,9 +4221,21 @@ static void send_mds_reconnect(struct ceph_mds_client *mdsc,if (!reply) goto fail_nomsg; +mutex_lock (&session->s_mutex); + +/* Serialized by s_mutex against concurrent ceph_get_deleg_ino(). */ xa_destroy (&session->s_delegated_inos); +if (session->s_state ==CEPH_MDS_SESSION_CLOSED || + session->s_state ==CEPH_MDS_SESSION_REJECTED ) { +pr_info_client (cl,"mds%d skipping reconnect, session %s\n" , + mds, +ceph_session_state_name (session->s_state)); +mutex_unlock (&session->s_mutex); +ceph_msg_put (reply); + err = -ESTALE ; + goto fail_return; + } -mutex_lock (&session->s_mutex); session->s_state =CEPH_MDS_SESSION_RECONNECTING ; session->s_seq =0 ;
@@ -4361,6 +4376,10 @@ static void send_mds_reconnect(struct ceph_mds_client *mdsc, fail_nopagelist:pr_err ("error %d preparing reconnect for mds%d\n" , err, mds);return ; + +fail_return: +ceph_pagelist_release (recon_state.pagelist); +return ; }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 ceph: print cluster fsid and client global_id in all debug logs
From: Xiubo Li <[email protected]>
[ Upstream commit 38d46409c4639a1d659ebfa70e27a8bed6b8ee1d ]
Multiple CephFS mounts on a host is increasingly common so disambiguating messages like this is necessary and will make it easier to debug issues.
At the same this will improve the debug logs to make them easier to troubleshooting issues, such as print the ino# instead only printing the memory addresses of the corresponding inodes and print the dentry names instead of the corresponding memory addresses for the dentry,etc.
[ stable: retain only the delegated-inode parser conversion needed as
context for the dependent fix; the remaining debug-log churn is not required on this tree ]
[ sashal: Reduced backport -- upstream 38d46409c4639 touches 19 file(s), this
backport carries 1. Not backported here:
fs/ceph/acl.c
fs/ceph/addr.c
fs/ceph/caps.c
fs/ceph/crypto.c
fs/ceph/debugfs.c
fs/ceph/dir.c
fs/ceph/export.c
fs/ceph/file.c
... and 10 more
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: 4bd3158bd624 ("ceph: cap delegated inode count in ceph_parse_deleg_inos()")
--- fs/ceph/mds_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/mds_client.c +1 -1
@@ -437,7 +437,7 @@ static int ceph_parse_deleg_inos(void **p, void *end,u32 sets;ceph_decode_32_safe (p, end, sets, bad); -dout ("got %u sets of delegated inodes\n" , sets); +doutc (cl,"got %u sets of delegated inodes\n" , sets);while (sets--) {u64 start, len;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 ceph: cap delegated inode count in ceph_parse_deleg_inos()
In reply to Sasha LevinFrom: Michael Bommarito <[email protected]>
[ Upstream commit 4bd3158bd62466d57ed72a3f7bc5f205fedd6919 ]
ceph_parse_deleg_inos() decodes interval sets of delegated inode numbers from an MDS create-with-delegation reply. For each set it reads a 64-bit start and a 64-bit len with ceph_decode_64_safe(), which only validates that the eight bytes are present in the message, not the value, and then loops over len while inserting entries into s_delegated_inos.
len is fully attacker controlled. A malicious or compromised MDS can send one huge interval, many intervals in one reply, duplicate intervals, or repeated replies that accumulate delegated inodes on the same session. The original code bounded none of these and could spin the insert loop or grow the xarray without limit.
Bound both dimensions with a single enforcement point. Track the number of delegated inodes held by each MDS session in an atomic counter and grow it only in ceph_insert_deleg_ino(), which uses atomic_add_unless() to refuse to push the count past CEPH_MAX_DELEG_INOS. Because that helper is the only place the counter grows, the per-session population can never exceed the cap, so no separate per-session pre-check is needed. The counter is decremented when async create consumes a delegated inode or when an insert fails, incremented when a delegated inode is restored, initialized with the session xarray, and reset when reconnect destroys the xarray.
A per-session cap alone still lets one reply spin the insert loop on duplicate ranges without growing the counter, so also cap the aggregate interval length accepted from a single reply. Together these bound both the loop trip count per reply and the xarray population across replies.
The cap is a fixed, client-chosen constant rather than a value derived from the MDS. mds_client_prealloc_inos is a userspace MDS configuration option; it is never sent to the kernel client on the wire, and a server-supplied bound could not be trusted for a defensive limit in any case. The constant is set well above that option's documented default of 1000 (a generous multiple), so legitimate refill behavior is unaffected while the CPU and xarray memory a malformed delegation stream can consume stays bounded.
Impact: a malicious or compromised Ceph MDS can no longer make a client spin through an unbounded delegated-inode interval or grow one session's delegated-inode xarray without limit.
--- fs/ceph/mds_client.c | 59 +++++++++++++++++++++++++++++++++++++++----- fs/ceph/mds_client.h | 1 + fs/ceph/super.h | 9 +++++++ 3 files changed, 63 insertions(+), 6 deletions(-)
fs/ceph/mds_client.c +53 -6
@@ -430,10 +430,36 @@ static int parse_reply_info_filelock(void **p, void *end,#define DELEGATED_INO_AVAILABLE xa_mk_value(1) +static int ceph_insert_deleg_ino (struct ceph_mds_session *s,u64 ino) +{ +struct ceph_client *cl = s->s_mdsc->fsc->client; +int err; + +/* +* Cap how many delegated inodes a single session may hold. This is +* the only place that grows the count, so atomic_add_unless() bounds +* it at exactly CEPH_MAX_DELEG_INOS; s_num_deleg_inos can never exceed +* that. +*/ +if (!atomic_add_unless (&s->s_num_deleg_inos,1 ,CEPH_MAX_DELEG_INOS )) { +pr_warn_ratelimited_client (cl, +"MDS session already holds %d delegated inodes\n" , +CEPH_MAX_DELEG_INOS ); +return -EOVERFLOW ; + } + + err =xa_insert (&s->s_delegated_inos, ino,DELEGATED_INO_AVAILABLE , +GFP_KERNEL ); +if (err) +atomic_dec (&s->s_num_deleg_inos); +return err; +} +static int ceph_parse_deleg_inos (void **p,void *end,struct ceph_mds_session *s) {struct ceph_client *cl = s->s_mdsc->fsc->client; +u64 msg_deleg_inos =0 ;u32 sets;ceph_decode_32_safe (p, end, sets, bad);
@@ -451,16 +477,34 @@ static int ceph_parse_deleg_inos(void **p, void *end, start, len);continue ; } + +/* +* Bound the number of inodes one reply may delegate. +* ceph_insert_deleg_ino() separately caps the per-session +* population, so this only has to stop one reply from spinning +* the insert loop under an attacker-controlled len. +*/ +if (len > (u64 )CEPH_MAX_DELEG_INOS || + msg_deleg_inos > (u64 )CEPH_MAX_DELEG_INOS - len) { +pr_warn_ratelimited_client (cl, +"MDS reply delegates too many inodes (have %llu, +%llu, max %d)\n" , + msg_deleg_inos, len,CEPH_MAX_DELEG_INOS ); +return -EIO ; + } + msg_deleg_inos += len; +while (len--) { -int err =xa_insert (&s->s_delegated_inos, start++, -DELEGATED_INO_AVAILABLE , -GFP_KERNEL ); +int err =ceph_insert_deleg_ino (s, start++); +if (!err) {doutc (cl,"added delegated inode 0x%llx\n" , start -1 ); }else if (err == -EBUSY ) {pr_warn_client (cl,"MDS delegated inode 0x%llx more than once.\n" , start -1 ); + }else if (err == -EOVERFLOW ) { +/* ceph_insert_deleg_ino() already warned. */ +return -EIO ; }else {return err; }
@@ -478,16 +522,17 @@ u64 ceph_get_deleg_ino(struct ceph_mds_session *s)xa_for_each (&s->s_delegated_inos, ino, val) { val =xa_erase (&s->s_delegated_inos, ino); -if (val ==DELEGATED_INO_AVAILABLE ) +if (val ==DELEGATED_INO_AVAILABLE ) { +atomic_dec (&s->s_num_deleg_inos);return ino; + } } return 0; }int ceph_restore_deleg_ino (struct ceph_mds_session *s,u64 ino) { -return xa_insert (&s->s_delegated_inos, ino,DELEGATED_INO_AVAILABLE , -GFP_KERNEL ); +return ceph_insert_deleg_ino (s, ino); }#else /* BITS_PER_LONG == 64 */ /*
@@ -854,6 +899,7 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,INIT_LIST_HEAD (&s->s_waiting);INIT_LIST_HEAD (&s->s_unsafe);xa_init (&s->s_delegated_inos); +atomic_set (&s->s_num_deleg_inos,0 );INIT_LIST_HEAD (&s->s_cap_releases);INIT_WORK (&s->s_cap_release_work, ceph_cap_release_work);
@@ -4225,6 +4271,7 @@ static void send_mds_reconnect(struct ceph_mds_client *mdsc,/* Serialized by s_mutex against concurrent ceph_get_deleg_ino(). */ xa_destroy (&session->s_delegated_inos); +atomic_set (&session->s_num_deleg_inos,0 );if (session->s_state ==CEPH_MDS_SESSION_CLOSED || session->s_state ==CEPH_MDS_SESSION_REJECTED ) { pr_info_client(cl, "mds%d skipping reconnect, session %s\n",
fs/ceph/mds_client.h +1 -0
@@ -219,6 +219,7 @@ struct ceph_mds_session {struct list_head s_waiting;/* waiting requests */ struct list_head s_unsafe;/* unsafe requests */ struct xarray s_delegated_inos; +atomic_t s_num_deleg_inos; };/*
fs/ceph/super.h +9 -0
@@ -572,6 +572,15 @@ static inline int ceph_ino_compare(struct inode *inode, void *data)#define CEPH_MDS_INO_LOG_OFFSET (2 * CEPH_MAX_MDS)#define CEPH_INO_SYSTEM_BASE ((6*CEPH_MAX_MDS) + (CEPH_MAX_MDS * CEPH_NUM_STRAY)) +/* +* Upper bound on the number of delegated inodes a single MDS session may +* hold. The MDS normally hands out a small preallocation window (the +* userspace mds_client_prealloc_inos option defaults to 1000) and refills +* it as the client consumes entries. This leaves generous headroom while +* bounding the CPU and memory a malformed delegation interval can consume. +*/ +#define CEPH_MAX_DELEG_INOS 8192 +static inline bool ceph_vino_is_reserved (const struct ceph_vino vino) { if (vino.ino >= CEPH_INO_SYSTEM_BASE ||
Signature · 1 line
2.53.0