ceph: support subvolume quarantine
Subsystems (4)
Alex Markuze
maintainerv4 cover ceph: support subvolume quarantine
CephFS subvolume quarantine isolates a subvolume while allowing recovery clients with q/Q MDS auth caps to access it. Advertise support only after cached data and metadata access paths can enforce quarantine.
This v4 combines the fscrypt symlink-cache prerequisite and the Ceph quarantine series as requested by Eric and Xiubo. The dcache export is retained. The generic fscrypt change precedes the Ceph patches, and its Ceph opt-in is folded into the patch adding the get_link checks.
Changes since v3:
- Disable only the two fscrypt symlink-cache writers. Leave cache readers unchanged and update fscrypt_symlink_getattr() kernel-doc. Explain the held O_PATH descriptor / empty-path readlinkat() bypass and the allocation and decryption cost of uncached encrypted symlink accesses.
- Avoid unconditional snapshot RPCs only when the connected head inode is the target's actual subvolume root, identified by its nonzero MDS-provided subvolume ID, with a valid AUTH_SHARED cap from a quarantine-aware MDS and no local quarantine marks. A snapshot P/.snap/S/V/file cannot use ancestor P's cap to authorize access in V. Synthetic snapdirs inherit their parent's subvolume ID. Unknown IDs, other head ancestors, expired root caps and disconnected snapshots retain MDS checks. 32-bit clients also revalidate because membership IDs use plain 64-bit READ/WRITE_ONCE accesses.
- Wait interruptibly and retry unstable namespace generations or MDS authorizations in blocking cap acquisition and revalidation. Preserve nonblocking behavior. Track splice owners and reject recursive LSM hooks with EBUSY, including hooks outside MDS reply processing.
- Gate ACL cache suppression and namespace mutation bookkeeping on negotiated quarantine support. Invalidate older cached ACLs when support is first enabled and pair namespace tokens across that transition.
- Remove the impossible NULL d_parent guards raised during VFS review.
Validation:
Nine deterministic source-extraction regression runners pass, including ASan/UBSan/LSan checks of VFS readlink and fscrypt target ownership. A warm same-subvolume-root snapshot harness performs 1000 getattr calls, 1024 read authorizations and 52 snapdir checks without an MDS RPC. A depth-300 harness completes 20000 blocking revalidations with injected namespace splices without EAGAIN. Additional cases cover feature activation, ACL cache invalidation, old-MDS caps, detached snapshots, epoch/rename races, interrupted waits, recovery permissions and stale cap messages. The ancestor snapshot regression fails on the earlier v4 draft and passes with the fix:
zero local marks and a valid outside head cap still require per-operation MDS authorization for reads, cached stat and xattrs. Unknown IDs, non-root head caps and 32-bit clients also retain MDS revalidation.
A complete W=1 kernel and module build passes with GCC 14.2.0 and the normalized x86_64-rhel-9.4 robot config: vmlinux, bzImage and all 2233 configured modules, including ceph.ko and libceph.ko. MODPOST succeeds, and the GPL d_find_alias_rcu export resolves. Additional W=1 builds pass on x86-64 with ACL/encryption enabled and disabled, and on i386 with those features enabled. All five patches pass strict checkpatch and apply in order to reproduce the tested source tree.
These are source harnesses, not live CephFS benchmark results. Live cluster, KASAN/lockdep, failover and snapshot throughput tests have not been rerun for v4. Xiubo's v3 runtime results are separate evidence.
Remaining protocol limits:
Already installed snapshot PTEs still need server notifications to revoke access without a new filesystem callback. Snapshots without proven coverage by a cap on their own subvolume root, and all 32-bit snapshot operations, still authorize each operation through the MDS.
Disable messages carry no generation, so same-rank ordering relies on ordered delivery. Overlapping ordinary rw and q/Q grants still require server-side auth-cap filtering; Xiubo reproduced that with ceph-fuse too.
v3: https://lore.kernel.org/r/[email protected]/
v2: https://lore.kernel.org/r/[email protected]/
fscrypt discussion: https://lore.kernel.org/r/a01d0a297a3e174d21741a3ad586ce546327603e.1792081664.git.amarkuze@redhat.com/
Alex Markuze (5):
dcache: export d_find_alias_rcu() for modular filesystems
fscrypt: allow filesystems to disable symlink target caching
ceph: add subvolume quarantine wire definitions
ceph: record subvolume quarantine from MDS cap updates
ceph: fail quarantined subvolume access with EACCES
fs/ceph/acl.c | 33 +- fs/ceph/addr.c | 72 ++- fs/ceph/caps.c | 317 +++++++++++- fs/ceph/crypto.c | 1 + fs/ceph/debugfs.c | 1 + fs/ceph/dir.c | 54 +- fs/ceph/file.c | 112 ++++- fs/ceph/inode.c | 919 ++++++++++++++++++++++++++++++++++- fs/ceph/ioctl.c | 13 + fs/ceph/mds_client.c | 28 +- fs/ceph/mds_client.h | 30 +- fs/ceph/super.c | 4 + fs/ceph/super.h | 99 +++- fs/ceph/xattr.c | 54 +- fs/crypto/hooks.c | 28 +- fs/dcache.c | 1 + include/linux/ceph/ceph_fs.h | 13 + include/linux/fscrypt.h | 7 + net/ceph/ceph_common.c | 2 + 19 files changed, 1676 insertions(+), 112 deletions(-)
Alex Markuze
maintainerPATCH v4 1/5 dcache: export d_find_alias_rcu() for modular filesystems
The Ceph subvolume quarantine ancestry walk needs to find a dentry alias under RCU without taking a reference. d_find_alias_rcu() provides these semantics, but it is not exported, so a modular Ceph client fails at modpost with an undefined reference to the helper.
Export d_find_alias_rcu() to GPL modules so filesystem modules can use the existing RCU lookup without changing its lifetime rules.
--- fs/dcache.c | 1 + 1 file changed, 1 insertion(+)
fs/dcache.c +1 -0
@@ -1248,6 +1248,7 @@ struct dentry *d_find_alias_rcu(struct inode *inode)spin_unlock (&inode->i_lock);return de; } +EXPORT_SYMBOL_GPL (d_find_alias_rcu);/* * Try to kill dentries associated with this inode.
Alex Markuze
maintainerPATCH v4 2/5 fscrypt: allow filesystems to disable symlink target caching
In reply to Alex Markuzefscrypt caches decrypted symlink targets in inode->i_link. The VFS can return that target without calling the filesystem's ->get_link(), so access checks in that callback cannot revoke a previously cached link. CephFS subvolume quarantine needs those checks even when readlinkat() uses an empty path on an O_PATH descriptor opened before quarantine.
Add a filesystem opt-out that prevents both creation-time and lookup- time cache installation. Leave cache readers unchanged: the option is fixed before inode creation, so they find no cached target. Uncached targets use the existing delayed-free callback.
Opting out costs a temporary allocation and decryption on each access to an encrypted symlink, including readlink, traversal and lstat. Other filesystems keep their existing caching behavior. The Ceph opt-in is in the quarantine enforcement patch in this series.
--- fs/crypto/hooks.c | 28 +++++++++++++++------------- include/linux/fscrypt.h | 7 +++++++ 2 files changed, 22 insertions(+), 13 deletions(-)
fs/crypto/hooks.c +15 -13
@@ -321,11 +321,13 @@ int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,*/ sd->encrypted_path[ciphertext_len] ='\0' ; -/* Cache the plaintext symlink target for later use by get_link() */ - err = -ENOMEM ; - inode->i_link =kmemdup (target, len +1 ,GFP_NOFS ); -if (!inode->i_link) - goto err_free_sd; +/* Cache the plaintext target unless the filesystem revalidates it. */ +if (!inode->i_sb->s_cop->no_symlink_cache) { + err = -ENOMEM ; + inode->i_link =kmemdup (target, len +1 ,GFP_NOFS ); +if (!inode->i_link) + goto err_free_sd; + }if (!disk_link->name) disk_link->name = (unsigned char *)sd;
@@ -411,12 +413,12 @@ const char *fscrypt_get_symlink(struct inode *inode, const void *caddr, pstr.name[pstr.len] ='\0' ;/* -* Cache decrypted symlink targets in i_link for later use. Don't cache -* symlink targets encoded without the key, since those become outdated -* once the key is added. This pairs with the READ_ONCE() above and in -* the VFS path lookup code. +* Cache decrypted targets unless the filesystem revalidates them. +* Don't cache targets encoded without the key, since those become +* outdated once the key is added. This pairs with the READ_ONCE() +* above and in the VFS path lookup code. */ -if (!has_key || +if (inode->i_sb->s_cop->no_symlink_cache || !has_key ||cmpxchg_release (&inode->i_link,NULL , pstr.name) !=NULL )set_delayed_call (done, kfree_link, pstr.name);
@@ -442,9 +444,9 @@ EXPORT_SYMBOL_GPL(fscrypt_get_symlink);* This requires reading the symlink target from disk if needed, setting up the * inode's encryption key if possible, and then decrypting or encoding the * symlink target. This makes lstat() more heavyweight than is normally the -* case. However, decrypted symlink targets will be cached in ->i_link, so -* usually the symlink won't have to be read and decrypted again later if/when -* it is actually followed, readlink() is called, or lstat() is called again. +* case. Unless the filesystem sets no_symlink_cache, decrypted targets +* are cached in ->i_link, avoiding another read and decryption when the +* symlink is followed, readlink() is called, or lstat() is called again. * * Return: 0 on success, -errno on failure */
include/linux/fscrypt.h +7 -0
@@ -107,6 +107,13 @@ struct fscrypt_operations {*/ unsigned int supports_subblock_data_units : 1; +/* +* Don't populate ->i_link, so every access calls ->get_link() and the +* filesystem can revalidate access. Set before creating any inodes; +* this option cannot invalidate previously cached targets. +*/ + unsigned int no_symlink_cache : 1; +/* * This field exists only for backwards compatibility reasons and should * only be set by the filesystems that are setting it already. It
Alex Markuze
maintainerPATCH v4 3/5 ceph: add subvolume quarantine wire definitions
In reply to Alex MarkuzeThe MDS revokes a quarantined subvolume's caps to PIN and reports -CEPH_EQUARANTINED in MClientCaps v14. This wire errno is 1000 and must be translated to EACCES before returning it to applications. When quarantine is lifted, MQuarantineDisable identifies the inode whose local mark can be cleared.
Add the errno, message type and packed disable payload, and teach ceph_msg_type_name() the message name. Advertise the session feature only after the client can enforce quarantine on cached access.
--- include/linux/ceph/ceph_fs.h | 13 +++++++++++++ net/ceph/ceph_common.c | 2 ++ 2 files changed, 15 insertions(+)
include/linux/ceph/ceph_fs.h +13 -0
@@ -154,6 +154,7 @@ const char *ceph_con_mode_name(int mode);#define CEPH_MSG_CLIENT_SNAP 0x312#define CEPH_MSG_CLIENT_CAPRELEASE 0x313#define CEPH_MSG_CLIENT_QUOTA 0x314 +#define CEPH_MSG_CLIENT_QUARANTINE_DISABLE 0x315/* pool ops */ #define CEPH_MSG_POOLOP_REPLY 48
@@ -921,4 +922,16 @@ struct ceph_mds_quota {__le64 max_files;/* quota max. files */ } __attribute__ ((packed)); +/* +* Cap oserrno used by the MDS when a subvolume is quarantined. +* This is not a VFS errno; applications see -EACCES. +*/ +#define CEPH_EQUARANTINED 1000 + +/* MDS -> client: quarantine lifted for one inode (ino, oserrno). */ +struct ceph_mds_quarantine_disable { +__le64 ino; +__le32 oserrno; +} __packed; +#endif
net/ceph/ceph_common.c +2 -0
@@ -83,6 +83,8 @@ const char *ceph_msg_type_name(int type)case CEPH_MSG_CLIENT_CAPS :return "client_caps" ;case CEPH_MSG_CLIENT_CAPRELEASE :return "client_cap_release" ;case CEPH_MSG_CLIENT_QUOTA :return "client_quota" ; +case CEPH_MSG_CLIENT_QUARANTINE_DISABLE : +return "client_quarantine_disable" ;case CEPH_MSG_CLIENT_SNAP :return "client_snap" ;case CEPH_MSG_CLIENT_LEASE :return "client_lease" ;case CEPH_MSG_POOLOP_REPLY :return "poolop_reply" ;
Alex Markuze
maintainerPATCH v4 4/5 ceph: record subvolume quarantine from MDS cap updates
In reply to Alex MarkuzeMClientCaps v14 appends a signed quarantine errno after the v13 subvolume ID. Decode it and keep a sticky, counted mark on the inode. A PIN-only update can reset the errno without clearing that mark. An accepted grant above PIN or a disable from the reporting rank clears it. A fresh metadata request can also confirm recovery across ranks. Ignore older cap sequences when changing quarantine state.
Retain a pending mark when the reporting cap or session is lost, so that later access must ask the MDS rather than reuse cached caps. Wake cap waiters when quarantine state changes.
Skip ancestry checks when no inode is marked. Otherwise cache complete RCU parent walks by generation; incomplete walks remain unknown and require an MDS answer. Bound retries and take no inode or dentry references during the walk. Invalidate generations across renames and alias attachments. Sleeping splices disable cached answers without leaving the generation odd across an LSM callback.
This patch records state without advertising quarantine support. The following patch adds the access checks before enabling it.
--- fs/ceph/caps.c | 122 ++++++++++- fs/ceph/dir.c | 9 + fs/ceph/file.c | 2 + fs/ceph/inode.c | 476 ++++++++++++++++++++++++++++++++++++++++++- fs/ceph/mds_client.c | 23 ++- fs/ceph/mds_client.h | 16 ++ fs/ceph/super.c | 2 + fs/ceph/super.h | 71 ++++++- 8 files changed, 713 insertions(+), 8 deletions(-)
fs/ceph/caps.c +121 -1
@@ -692,8 +692,9 @@ void change_auth_cap_ses(struct ceph_inode_info *ci,* @fmode is the open file mode, if we are opening a file, otherwise * it is < 0. (This is so we can atomically add the cap and add an * open file reference to it.) +* Returns false when the raw grant predates the recorded cap sequence. */ -void ceph_add_cap(struct inode *inode, +bool ceph_add_cap(struct inode *inode, struct ceph_mds_session *session, u64 cap_id, unsigned issued, unsigned wanted, unsigned seq, unsigned mseq, u64 realmino, int flags,
@@ -706,6 +707,7 @@ void ceph_add_cap(struct inode *inode,int mds = session->s_mds;int actual_wanted;u32 gen; +bool cap_current = true;lockdep_assert_held (&ci->i_ceph_lock);
@@ -737,6 +739,7 @@ void ceph_add_cap(struct inode *inode,atomic64_inc (&mdsc->metric.total_caps);spin_unlock (&session->s_cap_lock); }else { + cap_current =ceph_seq_cmp (seq, cap->seq) >=0 ;spin_lock (&session->s_cap_lock);list_move_tail (&cap->session_caps, &session->s_caps);spin_unlock (&session->s_cap_lock);
@@ -823,6 +826,7 @@ void ceph_add_cap(struct inode *inode, cap->mseq = mseq; cap->cap_gen = gen;wake_up_all (&ci->i_cap_wq); +return cap_current; }/*
@@ -1264,6 +1268,11 @@ static void __ceph_remove_cap(struct ceph_inode_info *ci, struct ceph_cap *cap, mdsc =ceph_inode_to_fs_client (&ci->netfs.inode)->mdsc; +/* Losing the reporting cap requires fresh MDS revalidation. */ +if (READ_ONCE (ci->i_qtine_mds) == cap->mds && +ceph_quarantine_reset (ci)) +wake_up_all (&ci->i_cap_wq); +/* remove from inode's cap rbtree, and clear auth cap */ rb_erase (&cap->ci_node, &ci->i_caps);if (ci->i_auth_cap == cap)
@@ -3729,6 +3738,9 @@ struct cap_extra_info {u8 *fscrypt_auth;u32 fscrypt_auth_len;u64 fscrypt_file_size; +/* MClientCaps v14 oserrno; valid only when oserrno_valid is set */ +s32 oserrno; +bool oserrno_valid; };/*
@@ -3757,6 +3769,45 @@ static int parse_inline_data(void **p, void *end,return -EIO ; } +/* +* Record quarantine state carried by an MClientCaps oserrno. +* Caller holds i_ceph_lock. Returns true when waiters should be woken +* because quarantine changed or a pending reset was resolved. +* +* -EQUARANTINED refreshes the sticky flag and its reporting MDS rank. +* A current grant above PIN with errno 0 clears only that rank's mark. +* Another rank needs a successful metadata request for the current epoch. +* A PIN-only update may zero qtine_errno while leaving the flag set. +*/ +static bool ceph_apply_quarantine (struct ceph_inode_info *ci,int mds, +int newcaps,int oserrno) +{ +bool was, now, pending; + + was =READ_ONCE (ci->i_qtine_errno) == -CEPH_EQUARANTINED || +test_bit (CEPH_I_QUARANTINE_BIT , &ci->i_ceph_flags); + pending =test_bit (CEPH_I_QUARANTINE_PENDING_BIT , &ci->i_ceph_flags); + +if ((newcaps & ~CEPH_CAP_PIN ) && was && oserrno ==0 && +READ_ONCE (ci->i_qtine_mds) == mds) +ceph_quarantine_clear (ci); + +if (oserrno == -CEPH_EQUARANTINED ) { +ceph_quarantine_set (ci); +WRITE_ONCE (ci->i_qtine_mds, mds); + } + +if (newcaps || was || +test_bit (CEPH_I_QUARANTINE_BIT , &ci->i_ceph_flags)) +WRITE_ONCE (ci->i_qtine_errno, oserrno); + + now =READ_ONCE (ci->i_qtine_errno) == -CEPH_EQUARANTINED || +test_bit (CEPH_I_QUARANTINE_BIT , &ci->i_ceph_flags); +return was != now || + pending !=test_bit (CEPH_I_QUARANTINE_PENDING_BIT , + &ci->i_ceph_flags); +} +/* * Handle a cap GRANT message from the MDS. (Note that a GRANT may * actually be a revocation if it specifies a smaller cap set.)
@@ -3781,6 +3832,7 @@ static void handle_cap_grant(struct inode *inode,u64 max_size =le64_to_cpu (grant->max_size);unsigned char check_caps =0 ;bool was_stale = cap->cap_gen <atomic_read (&session->s_cap_gen); +bool quarantine_current =ceph_seq_cmp (seq, cap->seq) >=0 ;bool wake = false;bool writeback = false;bool queue_trunc = false;
@@ -4128,6 +4180,15 @@ static void handle_cap_grant(struct inode *inode, fill_inline = true; } +if (quarantine_current && extra_info->oserrno_valid && +ceph_apply_quarantine (ci, session->s_mds, newcaps, + extra_info->oserrno)) { +boutc (cl,"quarantine oserrno %d caps %s %llx.%llx\n" , + extra_info->oserrno,ceph_cap_string (newcaps), +ceph_vinop (inode)); + wake = true; + } +if (le32_to_cpu (grant->op) ==CEPH_CAP_OP_IMPORT ) {if (ci->i_auth_cap == cap) {if (newcaps & ~extra_info->issued)
@@ -4826,6 +4887,20 @@ void ceph_handle_caps(struct ceph_mds_session *session, goto bad; } +if (msg_version >=13 ) { +/* v13: subvolume_id. The inode id is learned from replies. */ +ceph_decode_skip_64 (&p, end, bad); + } + +if (msg_version >=14 ) { +u32 raw_errno; + +/* v14: signed oserrno, -CEPH_EQUARANTINED when quarantined */ +ceph_decode_32_safe (&p, end, raw_errno, bad); + extra_info.oserrno = (s32 )raw_errno; + extra_info.oserrno_valid = true; + } +/* lookup ino */ inode =ceph_find_inode (mdsc->fsc->sb, vino); boutc(cl, " caps mds%d op %s ino %llx.%llx inode %p seq %u iseq %u mseq %u\n",
@@ -4981,6 +5056,51 @@ void ceph_handle_caps(struct ceph_mds_session *session, goto out; } +void ceph_handle_quarantine_disable (struct ceph_mds_client *mdsc, +struct ceph_mds_session *session, +struct ceph_msg *msg) +{ +struct super_block *sb = mdsc->fsc->sb; +struct ceph_client *cl = mdsc->fsc->client; +struct ceph_mds_quarantine_disable *h = msg->front.iov_base; +struct ceph_vino vino; +struct inode *inode; +struct ceph_inode_info *ci; + +if (!ceph_inc_mds_stopping_blocker (mdsc, session)) +return ; + +if (msg->front.iov_len <sizeof (*h)) { +pr_err_client (cl,"corrupt quarantine_disable mds%d len %d\n" , + session->s_mds, (int )msg->front.iov_len); +ceph_msg_dump (msg); + goto out; + } + + vino.ino =le64_to_cpu (h->ino); + vino.snap =CEPH_NOSNAP ; + inode =ceph_find_inode (sb, vino); +if (!inode) { +doutc (cl,"quarantine disable ino %llx not cached\n" , vino.ino); + goto out; + } + + ci =ceph_inode (inode); +spin_lock (&ci->i_ceph_lock); +/* Another rank's disable must not erase a newer negative. */ +if (!test_bit (CEPH_I_QUARANTINE_BIT , &ci->i_ceph_flags) || +READ_ONCE (ci->i_qtine_mds) == session->s_mds) { +ceph_quarantine_clear (ci); +WRITE_ONCE (ci->i_qtine_errno,0 ); + } +spin_unlock (&ci->i_ceph_lock); +wake_up_all (&ci->i_cap_wq); +doutc (cl,"quarantine disable ino %llx\n" , vino.ino); +iput (inode); +out: +ceph_dec_mds_stopping_blocker (mdsc); +} +/* * Process the expired end of one delayed cap list, whose entries were * queued @hold jiffies before they expire.
fs/ceph/dir.c +9 -0
@@ -795,7 +795,9 @@ struct dentry *ceph_handle_snapdir(struct ceph_mds_request *req,struct dentry *res;struct inode *inode =ceph_get_snapdir (parent); +ceph_quarantine_splice_start (parent->i_sb); res =d_splice_alias (inode, dentry); +ceph_quarantine_splice_finish (parent->i_sb); boutc_formats(cl, "ENOENT on snapdir %p '%s', linking to snapdir %p %llx.%llx. Spliced dentry %p\n", "ENOENT on snapdir %p '%pd', linking to snapdir %p %llx.%llx. Spliced dentry %p\n",
@@ -1373,7 +1375,9 @@ static int ceph_link(struct dentry *old_dentry, struct inode *dir,d_drop (dentry); }else if (!req->r_reply_info.head->is_dentry) {ihold (d_inode (old_dentry)); +ceph_quarantine_splice_start (dir->i_sb);d_instantiate (dentry,d_inode (old_dentry)); +ceph_quarantine_splice_finish (dir->i_sb); }ceph_mdsc_put_request (req);ceph_blog_exit (&__ji);
@@ -1701,12 +1705,17 @@ static int ceph_rename(struct mnt_idmap *idmap, struct inode *old_dir, } err =ceph_mdsc_do_request (mdsc, old_dir, req);if (!err && !req->r_reply_info.head->is_dentry) { +struct inode *moved; +/* * Normally d_move() is done by fill_trace (called by * do_request, above). If there is no trace, we need * to do it here. */ + moved =d_inode (old_dentry); +ceph_quarantine_move_start (moved, old_dir, new_dir);d_move (old_dentry, new_dentry); +ceph_quarantine_move_finish (moved, old_dir, new_dir); }ceph_mdsc_put_request (req);ceph_blog_exit (&__ji);
fs/ceph/file.c +2 -0
@@ -785,7 +785,9 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode,if (d_in_lookup (dentry) ||d_really_is_negative (dentry)) {if (!d_unhashed (dentry))d_drop (dentry); +ceph_quarantine_splice_start (dir->i_sb); dn =d_splice_alias (inode, dentry); +ceph_quarantine_splice_finish (dir->i_sb);WARN_ON_ONCE (dn && dn != dentry); } file->f_mode |=FMODE_CREATED ;
fs/ceph/inode.c +475 -1
542 lines not on this page · raw message
fs/ceph/mds_client.c +22 -1
@@ -2041,10 +2041,12 @@ static int remove_session_caps_cb(struct inode *inode, int mds, void *arg)struct ceph_inode_info *ci =ceph_inode (inode);struct ceph_client *cl =ceph_inode_to_client (inode);bool invalidate = false; +bool reset;struct ceph_cap *cap;int iputs =0 ;spin_lock (&ci->i_ceph_lock); + reset =ceph_quarantine_reset (ci); cap =__get_cap_for_mds (ci, mds);if (cap) { boutc(cl, " removing cap %p, ci is %p, inode is %p\n",
@@ -2054,7 +2056,7 @@ static int remove_session_caps_cb(struct inode *inode, int mds, void *arg) }spin_unlock (&ci->i_ceph_lock); -if (cap) +if (cap || reset)wake_up_all (&ci->i_cap_wq);if (invalidate)ceph_queue_invalidate (inode);
@@ -2860,6 +2862,7 @@ ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode)mutex_init (&req->r_fill_mutex); req->r_mdsc = mdsc; + req->r_quarantine_epoch =atomic64_read_acquire (&mdsc->quarantine_epoch); req->r_started = jiffies; req->r_start_latency =ktime_get (); req->r_resend_mds =-1 ;
@@ -5009,6 +5012,7 @@ static int reconnect_caps_cb(struct inode *inode, int mds, void *arg)struct ceph_path_info path_info = {0 };int err;u64 snap_follows; +bool reset = false; dentry =d_find_primary (inode);if (dentry) {
@@ -5023,9 +5027,16 @@ static int reconnect_caps_cb(struct inode *inode, int mds, void *arg) }spin_lock (&ci->i_ceph_lock); +/* +* Require a fresh MDS answer after reconnect. A PIN import may +* carry no quarantine errno, so it must not reopen cached snap caps. +*/ + reset =ceph_quarantine_reset (ci); cap =__get_cap_for_mds (ci, mds);if (!cap) {spin_unlock (&ci->i_ceph_lock); +if (reset) +wake_up_all (&ci->i_cap_wq); err =0 ; goto out_err; }
@@ -5088,6 +5099,8 @@ static int reconnect_caps_cb(struct inode *inode, int mds, void *arg) snap_follows = capsnap->follows; }spin_unlock (&ci->i_ceph_lock); +if (reset) +wake_up_all (&ci->i_cap_wq);if (recon_state->msg_version >=2 ) {int num_fcntl_locks, num_flock_locks;
@@ -6468,6 +6481,11 @@ int ceph_mdsc_init(struct ceph_fs_client *fsc)init_completion (&mdsc->safe_umount_waiters);spin_lock_init (&mdsc->stopping_lock);atomic_set (&mdsc->stopping_blockers,0 ); +atomic_set (&mdsc->quarantine_count,0 ); +atomic_set (&mdsc->quarantine_writers,0 ); +atomic_set (&mdsc->quarantine_splices,0 ); +atomic64_set (&mdsc->quarantine_epoch,0 ); +spin_lock_init (&mdsc->quarantine_lock);init_completion (&mdsc->stopping_waiter);atomic64_set (&mdsc->dirty_folios,0 );init_waitqueue_head (&mdsc->flush_end_wq);
@@ -7368,6 +7386,9 @@ static void mds_dispatch(struct ceph_connection *con, struct ceph_msg *msg)case CEPH_MSG_CLIENT_QUOTA :ceph_handle_quota (mdsc, s, msg);break ; +case CEPH_MSG_CLIENT_QUARANTINE_DISABLE : +ceph_handle_quarantine_disable (mdsc, s, msg); +break ;default : pr_err_client(cl, "received unknown message type %d %s\n",
fs/ceph/mds_client.h +16 -0
@@ -375,6 +375,7 @@ struct ceph_mds_request {int r_fmode;/* file mode, if expecting cap */ int r_request_release_offset;const struct cred *r_cred; +u64 r_quarantine_epoch;/* generation when the request was created */ struct mnt_idmap *r_mnt_idmap;struct timespec64 r_stamp;
@@ -506,6 +507,21 @@ struct ceph_mds_client {spinlock_t stopping_lock;/* protect snap_empty */ int stopping;/* the stage of shutting down */ atomic_t stopping_blockers; +/* +* Inodes with CEPH_I_QUARANTINE set. Hot paths skip the +* ancestor walk while this is zero. +* quarantine_epoch is a seqcount: even while idle, odd while +* quarantine_writers is non-zero. Writers are mark changes and +* cross-directory renames. quarantine_lock covers the writers +* update and the epoch bump together. Sleeping alias splices use +* quarantine_splices instead: readers walk without cached answers +* while it is non-zero. Each splice edge also bumps the epoch. +*/ +atomic_t quarantine_count; +atomic_t quarantine_writers; +atomic_t quarantine_splices; +atomic64_t quarantine_epoch; +spinlock_t quarantine_lock;/* writers update + epoch bump */ struct completion stopping_waiter;atomic64_t dirty_folios;
fs/ceph/super.c +2 -0
@@ -1139,7 +1139,9 @@ static struct dentry *open_root_dentry(struct ceph_fs_client *fsc,struct inode *inode = req->r_target_inode; req->r_target_inode =NULL ;doutc (cl,"success\n" ); +ceph_quarantine_splice_start (fsc->sb); root =d_make_root (inode); +ceph_quarantine_splice_finish (fsc->sb);if (!root) { root =ERR_PTR (-ENOMEM ); goto out;
fs/ceph/super.h +66 -5
95 lines not on this page · raw message
Alex Markuze
maintainerPATCH v4 5/5 ceph: fail quarantined subvolume access with EACCES
In reply to Alex MarkuzeAdvertise CEPHFS_FEATURE_QUARANTINE after gating cached data and metadata access. The MDS can then return EACCES for quarantined requests instead of parking them until quarantine is lifted.
Reject cached access to a directly marked inode. Ask the MDS when ancestry is incomplete or an inherited mark may permit recovery with q/Q auth caps. Scope read confirmations to the exact inode, credentials and epoch; authorize writes separately with a mode- specific OPEN. Keep nonblocking acquisition free of RPCs and drop locked folios before blocking revalidation.
Wait interruptibly for namespace writers and retry invalidated MDS answers instead of leaking EAGAIN from blocking reads and readdir. Track the tasks performing sleeping splices and reject their recursive LSM hooks with EBUSY rather than waiting on their own operation. Keep the fill-trace recursion guard, including cross-mount calls. Wake waiters when mark writers and splices finish.
Keep snapshot access cached only when the connected head inode is the subvolume root identified by the target's nonzero MDS subvolume ID, holds a valid AUTH_SHARED cap from a quarantine-aware authoritative MDS, and there are no local quarantine marks. An ancestor snapshot P/.snap/S/V/file must not use P's cap to authorize access inside V:
quarantining V leaves P's cap valid and may supply no local marks. Copy the parent's subvolume ID into synthetic snapdir inodes too. Unknown IDs, other head ancestors, expired root caps and active quarantine still require an MDS answer. Keep 32-bit clients on that path because membership IDs use plain 64-bit READ/WRITE_ONCE accesses. Preserve connected paths and exact inode/snapshot LOOKUPINO fallback, including reply-identity and required-payload checks.
Gate VFS ACL cache suppression and namespace mutation bookkeeping on negotiated quarantine support. Invalidate older cached ACLs when the first supporting session opens and pair mutation tokens across that transition. Keep support enabled across subsequent reconnects.
Select fscrypt's symlink cache opt-out alongside the get_link checks. This closes readlinkat() with an empty path on a held O_PATH symlink fd. Pathname lookup already rejects quarantined paths; an existing O_PATH fd bypasses that lookup and needs the get_link check itself. Encrypted symlink readlink, traversal and lstat now allocate and decrypt a temporary target on each access.
Gate cached stat, xattr, directory, ioctl and mmap access. Keep ACL inheritance in the encoded xattr blob and fail ENOMEM if it cannot be installed. Leave metadata submission and lock release on their normal paths, and route uncertain async mutations to the MDS. Fresh metadata replies recover after a lost disable notification. Existing snapshot PTEs still require server notifications for revocation.
--- fs/ceph/acl.c | 33 ++- fs/ceph/addr.c | 72 ++++-- fs/ceph/caps.c | 195 +++++++++++++++- fs/ceph/crypto.c | 1 + fs/ceph/debugfs.c | 1 + fs/ceph/dir.c | 57 +++-- fs/ceph/file.c | 114 +++++++--- fs/ceph/inode.c | 521 ++++++++++++++++++++++++++++++++++++++----- fs/ceph/ioctl.c | 13 ++ fs/ceph/mds_client.c | 5 + fs/ceph/mds_client.h | 14 +- fs/ceph/super.c | 6 +- fs/ceph/super.h | 40 +++- fs/ceph/xattr.c | 54 ++++- 14 files changed, 980 insertions(+), 146 deletions(-)
fs/ceph/acl.c +31 -2
@@ -18,18 +18,45 @@#include "mds_client.h" static inline void ceph_set_cached_acl (struct inode *inode, -int type,struct posix_acl *acl) +int type,struct posix_acl *acl) {struct ceph_inode_info *ci =ceph_inode (inode);spin_lock (&ci->i_ceph_lock); -if (__ceph_caps_issued_mask_metric (ci,CEPH_CAP_XATTR_SHARED ,0 )) +if (!READ_ONCE (ceph_sb_to_mdsc (inode->i_sb)->quarantine_supported) && +__ceph_caps_issued_mask_metric (ci,CEPH_CAP_XATTR_SHARED ,0 ))set_cached_acl (inode, type, acl);else forget_cached_acl (inode, type);spin_unlock (&ci->i_ceph_lock); } +void ceph_quarantine_uncache_inode_acls (struct inode *inode) +{ +struct ceph_inode_info *ci =ceph_inode (inode); +struct posix_acl *acl, *default_acl; + +spin_lock (&ci->i_ceph_lock); + acl =xchg (&inode->i_acl,ACL_DONT_CACHE ); + default_acl =xchg (&inode->i_default_acl,ACL_DONT_CACHE ); +spin_unlock (&ci->i_ceph_lock); +if (!is_uncached_acl (acl)) +posix_acl_release (acl); +if (!is_uncached_acl (default_acl)) +posix_acl_release (default_acl); +} + +void ceph_quarantine_disable_acl_cache (struct super_block *sb) +{ +struct inode *inode; + +/* Cover inodes cached before the first supporting session opened. */ +spin_lock (&sb->s_inode_list_lock); +list_for_each_entry (inode, &sb->s_inodes, i_sb_list) +ceph_quarantine_uncache_inode_acls (inode); +spin_unlock (&sb->s_inode_list_lock); +} +struct posix_acl *ceph_get_acl (struct inode *inode,int type,bool rcu) {struct ceph_client *cl =ceph_inode_to_client (inode);
@@ -73,6 +100,8 @@ struct posix_acl *ceph_get_acl(struct inode *inode, int type, bool rcu) acl =posix_acl_from_xattr (&init_user_ns, value, size); }else if (size == -ENODATA || size ==0 ) { acl =NULL ; + }else if (size == -EACCES ) { + acl =ERR_PTR (-EACCES ); }else {pr_err_ratelimited_client (cl,"%llx.%llx failed, err=%d\n" ,ceph_vinop (inode), size);
fs/ceph/addr.c +56 -16
100 lines not on this page · raw message
fs/ceph/caps.c +186 -9
275 lines not on this page · raw message
fs/ceph/crypto.c +1 -0
@@ -92,6 +92,7 @@ static struct fscrypt_operations ceph_fscrypt_ops = { .inode_info_offs = (int)offsetof(struct ceph_inode_info, i_crypt_info) - (int)offsetof(struct ceph_inode_info, netfs.inode), .needs_bounce_pages = 1, + .no_symlink_cache = 1, .get_context = ceph_crypt_get_context, .set_context = ceph_crypt_set_context, .get_dummy_policy = ceph_get_dummy_policy,
fs/ceph/debugfs.c +1 -0
@@ -53,6 +53,7 @@ static const struct ceph_session_feature_desc ceph_session_feature_table[] = { { CEPHFS_FEATURE_HAS_OWNER_UIDGID, "HAS_OWNER_UIDGID" }, { CEPHFS_FEATURE_MDS_AUTH_CAPS_CHECK, "MDS_AUTH_CAPS_CHECK" }, { CEPHFS_FEATURE_SUBVOLUME_METRICS, "SUBVOLUME_METRICS" }, + { CEPHFS_FEATURE_QUARANTINE, "QUARANTINE" }, };static int mdsmap_show (struct seq_file *s,void *p)
fs/ceph/dir.c +39 -18
140 lines not on this page · raw message
fs/ceph/file.c +89 -25
186 lines not on this page · raw message
fs/ceph/inode.c +459 -62
762 lines not on this page · raw message
fs/ceph/ioctl.c +13 -0
@@ -201,6 +201,10 @@ static long ceph_ioctl_get_dataloc(struct file *file, void __user *arg)if (copy_from_user (&dl, arg,sizeof (dl)))return -EFAULT ; + r =ceph_do_getattr (inode,CEPH_STAT_CAP_LAYOUT , false); +if (r) +return r; +down_read (&osdc->lock);ceph_calc_file_object_mapping (&ci->i_layout, dl.file_offset,1 , &dl.object_no, &dl.object_offset, &xlen);
@@ -401,12 +405,18 @@ long ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg)case FS_IOC_GET_ENCRYPTION_POLICY : ret =vet_mds_for_fscrypt (file); +if (ret) +return ret; + ret =ceph_quarantine_revalidate (inode);if (ret)return ret;return fscrypt_ioctl_get_policy (file, (void __user *)arg);case FS_IOC_GET_ENCRYPTION_POLICY_EX : ret =vet_mds_for_fscrypt (file); +if (ret) +return ret; + ret =ceph_quarantine_revalidate (inode);if (ret)return ret;return fscrypt_ioctl_get_policy_ex (file, (void __user *)arg);
@@ -429,6 +439,9 @@ long ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg)case FS_IOC_GET_ENCRYPTION_NONCE : ret =vet_mds_for_fscrypt (file); +if (ret) +return ret; + ret =ceph_quarantine_revalidate (inode);if (ret)return ret;return fscrypt_ioctl_get_nonce (file, (void __user *)arg);
fs/ceph/mds_client.c +5 -0
@@ -4667,6 +4667,8 @@ static void handle_session(struct ceph_mds_session *session, mdsc->s_cap_auths = cap_auths; session->s_features = features; +if (test_bit (CEPHFS_FEATURE_QUARANTINE , &session->s_features)) +ceph_quarantine_enable (mdsc);if (test_bit (CEPHFS_FEATURE_METRIC_COLLECT , &session->s_features))ceph_metric_bind_session (mdsc, session);
@@ -6482,6 +6484,9 @@ int ceph_mdsc_init(struct ceph_fs_client *fsc)spin_lock_init (&mdsc->stopping_lock);atomic_set (&mdsc->stopping_blockers,0 );atomic_set (&mdsc->quarantine_count,0 ); + mdsc->quarantine_supported = false; +init_waitqueue_head (&mdsc->quarantine_waitq); +INIT_LIST_HEAD (&mdsc->quarantine_splice_owners);atomic_set (&mdsc->quarantine_writers,0 );atomic_set (&mdsc->quarantine_splices,0 );atomic64_set (&mdsc->quarantine_epoch,0 );
fs/ceph/mds_client.h +13 -1
@@ -39,7 +39,14 @@ enum ceph_feature_type {CEPHFS_FEATURE_MDS_AUTH_CAPS_CHECK ,CEPHFS_FEATURE_SUBVOLUME_METRICS , - CEPHFS_FEATURE_MAX = CEPHFS_FEATURE_SUBVOLUME_METRICS, +/* +* Bit 23 is CEPHFS_FEATURE_BLOCKDIFF on the MDS and is not +* advertised here. Bit 24 is subvolume quarantine; it must stay +* aligned with the userspace client. +*/ +CEPHFS_FEATURE_QUARANTINE =24 , + + CEPHFS_FEATURE_MAX = CEPHFS_FEATURE_QUARANTINE, };#define CEPHFS_FEATURES_CLIENT_SUPPORTED { \
@@ -57,6 +64,7 @@ enum ceph_feature_type {CEPHFS_FEATURE_HAS_OWNER_UIDGID , \CEPHFS_FEATURE_MDS_AUTH_CAPS_CHECK , \CEPHFS_FEATURE_SUBVOLUME_METRICS , \ + CEPHFS_FEATURE_QUARANTINE, \ }/*
@@ -507,6 +515,10 @@ struct ceph_mds_client {spinlock_t stopping_lock;/* protect snap_empty */ int stopping;/* the stage of shutting down */ atomic_t stopping_blockers; +/* Once negotiated, keep tracking across reconnects and mixed ranks. */ +bool quarantine_supported; +wait_queue_head_t quarantine_waitq; +struct list_head quarantine_splice_owners;/* quarantine_lock */ /* * Inodes with CEPH_I_QUARANTINE set. Hot paths skip the * ancestor walk while this is zero.
fs/ceph/super.c +4 -2
@@ -1137,11 +1137,13 @@ static struct dentry *open_root_dentry(struct ceph_fs_client *fsc, err =ceph_mdsc_do_request (mdsc,NULL , req);if (err ==0 ) {struct inode *inode = req->r_target_inode; +struct ceph_quarantine_splice qsplice; + req->r_target_inode =NULL ;doutc (cl,"success\n" ); -ceph_quarantine_splice_start (fsc->sb); +ceph_quarantine_splice_start (fsc->sb, &qsplice); root =d_make_root (inode); -ceph_quarantine_splice_finish (fsc->sb); +ceph_quarantine_splice_finish (&qsplice);if (!root) { root =ERR_PTR (-ENOMEM ); goto out;
fs/ceph/super.h +31 -9
@@ -1306,16 +1306,27 @@ enum ceph_qstate ceph_inode_quarantine_state(struct inode *inode);enum ceph_qstate ceph_inode_quarantine_write_state (struct inode *inode);bool ceph_inode_quarantine_direct (struct inode *inode);int ceph_quarantine_revalidate (struct inode *inode); +int ceph_quarantine_wait (struct inode *inode); +bool ceph_snapshot_needs_revalidate (struct inode *inode); +bool ceph_quarantine_head_cap_valid (struct inode *inode); +void ceph_quarantine_enable (struct ceph_mds_client *mdsc);int ceph_snapshot_read_auth (struct inode *inode);void ceph_quarantine_set (struct ceph_inode_info *ci);bool ceph_quarantine_clear (struct ceph_inode_info *ci);bool ceph_quarantine_reset (struct ceph_inode_info *ci); -void ceph_quarantine_move_start (struct inode *inode,struct inode *old_dir, -struct inode *new_dir); -void ceph_quarantine_move_finish (struct inode *inode,struct inode *old_dir, -struct inode *new_dir); -void ceph_quarantine_splice_start (struct super_block *sb); -void ceph_quarantine_splice_finish (struct super_block *sb); +struct ceph_mds_client *ceph_quarantine_move_start (struct inode *inode, +struct inode *old_dir, +struct inode *new_dir); +void ceph_quarantine_move_finish (struct ceph_mds_client *mdsc); +struct ceph_quarantine_splice { +struct ceph_mds_client *mdsc; +struct task_struct *task; +struct list_head item; +}; + +void ceph_quarantine_splice_start (struct super_block *sb, +struct ceph_quarantine_splice *splice); +void ceph_quarantine_splice_finish (struct ceph_quarantine_splice *splice);void ceph_handle_quarantine_disable (struct ceph_mds_client *mdsc,struct ceph_mds_session *session,struct ceph_msg *msg);
@@ -1379,6 +1390,7 @@ static inline int ceph_security_init_secctx(struct dentry *dentry, umode_t mode, {return 0 ; } +static inline void ceph_security_invalidate_secctx (struct inode *inode) { }
@@ -1394,8 +1406,9 @@ int ceph_set_acl(struct mnt_idmap *idmap, struct dentry *dentry, struct posix_acl *acl, int type);int ceph_pre_init_acls (struct inode *dir,umode_t *mode,struct ceph_acl_sec_ctx *as_ctx); -void ceph_init_inode_acls (struct inode *inode, -struct ceph_acl_sec_ctx *as_ctx); +void ceph_init_inode_acls (struct inode *inode,struct ceph_acl_sec_ctx *as_ctx); +void ceph_quarantine_uncache_inode_acls (struct inode *inode); +void ceph_quarantine_disable_acl_cache (struct super_block *sb);static inline void ceph_forget_all_cached_acls (struct inode *inode) {
@@ -1412,11 +1425,20 @@ static inline int ceph_pre_init_acls(struct inode *dir, umode_t *mode, {return 0 ; } +static inline void ceph_init_inode_acls (struct inode *inode,struct ceph_acl_sec_ctx *as_ctx) { } +static inline void ceph_quarantine_uncache_inode_acls (struct inode *inode) +{ +} + +static inline void ceph_quarantine_disable_acl_cache (struct super_block *sb) +{ +} +static inline void ceph_forget_all_cached_acls (struct inode *inode) { }
@@ -1578,7 +1600,7 @@ static inline bool ceph_has_inline_data(const struct ceph_inode_info *ci)/* file.c */ extern const struct file_operations ceph_file_fops; -extern int ceph_renew_caps (struct inode *inode,int fmode); +int ceph_renew_caps (struct inode *inode,int fmode,bool force);extern int ceph_open (struct inode *inode,struct file *file);extern int ceph_atomic_open (struct inode *dir,struct dentry *dentry,struct file *file,unsigned flags,umode_t mode);
fs/ceph/xattr.c +52 -2
90 lines not on this page · raw message
Eric Biggers
maintainerQuoted 3 lines · Alex Markuze
CephFS subvolume quarantine isolates a subvolume while allowing recovery clients with q/Q MDS auth caps to access it. Advertise support only after cached data and metadata access paths can enforce quarantine.
No base-commit given, and this fails to apply to current mainline, current linux-next, and also to the current default branch of
https://github.com/ceph/ceph-client.git which MAINTAINERS lists for fs/ceph/. So it isn't possible to review this.
Note that Sashiko was unable to apply it too, so no reviews from Sashiko are available either.
It's getting to the point where I should just immediately delete all patches that don't have a base-commit. It's a waste of time to even bother trying to look at them.
- Eric
Alex Markuze
maintainerMy bad, resending.
Quoted 20 lines · Eric Biggers
Quoted 3 lines · Alex Markuze
CephFS subvolume quarantine isolates a subvolume while allowing recovery clients with q/Q MDS auth caps to access it. Advertise support only after cached data and metadata access paths can enforce quarantine.
No base-commit given, and this fails to apply to current mainline, current linux-next, and also to the current default branch of
https://github.com/ceph/ceph-client.git whichMAINTAINERSlists forfs/ceph/. So it isn't possible to review this.Note that Sashiko was unable to apply it too, so no reviews from Sashiko are available either.
It's getting to the point where I should just immediately delete all patches that don't have a base-commit. It's a waste of time to even bother trying to look at them.
- Eric