ceph: support subvolume quarantine
Subsystems (3)
Alex Markuze
maintainerv3 cover ceph: support subvolume quarantine
CephFS subvolume quarantine isolates a subvolume while allowing access by recovery clients with q/Q MDS auth caps. The kernel client currently does not advertise quarantine support, so the MDS can hold its requests until quarantine is lifted.
This series handles MClientCaps v14 quarantine notifications, checks cached data and metadata access, and handles disable notifications. Fresh MDS replies allow recovery after a lost disable. It applies directly to the base below and has no fscrypt prerequisite.
The first patch exports d_find_alias_rcu() to GPL modules. The remaining three patches add the wire definitions, record quarantine state and ancestry generations, then install the access checks before advertising the session feature.
Changes since v2:
- Add the VFS export prerequisite to fix the undefined d_find_alias_rcu symbol reported by the kernel test robot with CONFIG_CEPH_FS=m. The fix carries Reported-by and Closes tags.
- Keep all three Ceph patches unchanged from v2.
- Replace object-only compile validation with a complete W=1 kernel and module build using GCC 14.2.0 and the robot's x86_64-rhel-9.4 config.
Validation:
A complete W=1 build with the kernel.org GCC 14.2.0 toolchain and the robot's x86_64-rhel-9.4 config after olddefconfig passes. It produces vmlinux, bzImage and all 2,233 configured modules, including ceph.ko and libceph.ko. MODPOST succeeds, and Module.symvers contains the GPL export of d_find_alias_rcu. Configuration changes are limited to olddefconfig's toolchain capability normalization; there are no manual config changes. W=1 warnings remain elsewhere in the kernel; none come from Ceph or dcache.c.
All four patches pass strict checkpatch and apply in order to reproduce the tested source tree. Seven deterministic source-extraction regression runners pass; the ASan/UBSan/LSan VFS runner also demonstrates the remaining cached encrypted-readlink bypass.
Known limitation: cached encrypted symlink targets can bypass quarantine checks. fscrypt populates inode->i_link, which the VFS can use for readlink or symlink traversal without calling Ceph's get_link operation. Uncached encrypted targets and plaintext symlinks still pass through Ceph's checks. Closing the encrypted-target cache gap needs the separate fscrypt support and Ceph opt-in follow-up.
Live cluster, KASAN/lockdep, multi-MDS recovery and depth benchmarks have not been run for this version. Existing snapshot mappings need server notifications to revoke already installed PTEs. Disable messages carry no generation, so same-rank ordering relies on ordered MDS delivery. Recovery assumes the intended rwq/rwQ delegation; overlapping ordinary rw and read-only q/Q grants still need server-side cap filtering.
v2: https://lore.kernel.org/r/[email protected]
Robot report:
https://lore.kernel.org/oe-kbuild-all/[email protected]/
Alex Markuze (4):
dcache: export d_find_alias_rcu() for modular filesystems
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 | 28 +- fs/ceph/addr.c | 72 ++- fs/ceph/caps.c | 291 +++++++++++- fs/ceph/debugfs.c | 1 + fs/ceph/dir.c | 51 ++- fs/ceph/file.c | 117 +++-- fs/ceph/inode.c | 841 ++++++++++++++++++++++++++++++++++- fs/ceph/ioctl.c | 13 + fs/ceph/mds_client.c | 23 +- fs/ceph/mds_client.h | 26 +- fs/ceph/super.c | 2 + fs/ceph/super.h | 80 +++- fs/ceph/xattr.c | 54 ++- fs/dcache.c | 1 + include/linux/ceph/ceph_fs.h | 13 + net/ceph/ceph_common.c | 2 + 16 files changed, 1482 insertions(+), 133 deletions(-)
base-commit: ed0502cb11f84fff29f374238e526ae94d9bdfde
Signature · 1 line
2.34.1
Alex Markuze
maintainerPATCH v3 1/4 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.
Signature · 1 line
2.34.1
Alex Markuze
maintainerPATCH v3 2/4 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" ;
Signature · 1 line
2.34.1
Alex Markuze
maintainerPATCH v3 3/4 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
Signature · 1 line
2.34.1
Alex Markuze
maintainerPATCH v3 4/4 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, request credentials and generation; authorize writes separately with a mode-specific OPEN. A new mark or parent change invalidates an earlier confirmation. Keep nonblocking cap acquisition free of MDS requests and drop locked folios before blocking revalidation.
Gate cached stat, xattr, directory, ioctl and mmap access. Prevent VFS ACL and plaintext symlink caches from bypassing those checks while keeping ACL inheritance in the encoded xattr blob. Return ENOMEM if that blob cannot be installed.
Encrypted symlinks still use fscrypt's decrypted-target i_link cache. The VFS can return a cached target or follow it without entering Ceph's get_link callback. This leaves a quarantine enforcement gap for cached encrypted symlinks. Closing it requires separate fscrypt support and a Ceph opt-in; neither is part of this series.
Snapshot caps receive no revocations, so authorize each operation with a fresh MDS request. Preserve connected snapshot paths, falling back to an exact inode/snapshot LOOKUPINO for disconnected handles. Validate reply identity and required payloads before exposing data. Already installed snapshot PTEs still need a server notification to revoke access without a new filesystem callback.
Keep metadata submission, including POSIX and flock unlocks, on its normal path. Fall back from uncertain async creates and unlinks to synchronous requests. Fresh getattr, lookup and open replies can recover after a lost quarantine-disable notification.
--- fs/ceph/acl.c | 28 +--- fs/ceph/addr.c | 72 +++++++-- fs/ceph/caps.c | 169 ++++++++++++++++++-- fs/ceph/debugfs.c | 1 + fs/ceph/dir.c | 42 +++-- fs/ceph/file.c | 115 ++++++++++---- fs/ceph/inode.c | 365 ++++++++++++++++++++++++++++++++++++++++--- fs/ceph/ioctl.c | 13 ++ fs/ceph/mds_client.h | 10 +- fs/ceph/super.h | 9 +- fs/ceph/xattr.c | 54 ++++++- 11 files changed, 753 insertions(+), 125 deletions(-)
fs/ceph/acl.c +2 -26
@@ -17,19 +17,6 @@#include "super.h" #include "mds_client.h" -static inline void ceph_set_cached_acl (struct inode *inode, -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 )) -set_cached_acl (inode, type, acl); -else -forget_cached_acl (inode, type); -spin_unlock (&ci->i_ceph_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 +60,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);
@@ -81,9 +70,6 @@ struct posix_acl *ceph_get_acl(struct inode *inode, int type, bool rcu)kfree (value); -if (!IS_ERR (acl)) -ceph_set_cached_acl (inode, type, acl); -return acl; }
@@ -154,8 +140,6 @@ int ceph_set_acl(struct mnt_idmap *idmap, struct dentry *dentry, goto out_free; } -ceph_set_cached_acl (inode, type, acl); - out_free:kfree (value); out:
@@ -249,11 +233,3 @@ int ceph_pre_init_acls(struct inode *dir, umode_t *mode,ceph_pagelist_release (pagelist);return err; } - -void ceph_init_inode_acls (struct inode *inode,struct ceph_acl_sec_ctx *as_ctx) -{ -if (!inode) -return ; -ceph_set_cached_acl (inode,ACL_TYPE_ACCESS , as_ctx->acl); -ceph_set_cached_acl (inode,ACL_TYPE_DEFAULT , as_ctx->default_acl); -}
fs/ceph/addr.c +56 -16
100 lines not on this page · raw message
fs/ceph/caps.c +160 -9
249 lines not on this page · raw message
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 +30 -12
86 lines not on this page · raw message
fs/ceph/file.c +87 -28
198 lines not on this page · raw message
fs/ceph/inode.c +342 -23
528 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.h +9 -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, \ }/*
fs/ceph/super.h +1 -8
@@ -1394,8 +1394,6 @@ 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);static inline void ceph_forget_all_cached_acls (struct inode *inode) {
@@ -1412,11 +1410,6 @@ 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_forget_all_cached_acls (struct inode *inode) { }
@@ -1578,7 +1571,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
Signature · 1 line
2.34.1
Quoted 2 lines · Alex Markuze
CephFS subvolume quarantine isolates a subvolume while allowing access by recovery clients with q/Q MDS auth caps.
Hi Alex,
I tested v3 on a KASAN/lockdep kernel against a vstart cluster with MDS quarantine support. Basic quarantine, held fds, disable/recovery, MDS failover, umount while quarantined and fsstress with quarantine cycling all behave as expected, with clean dmesg. The v1 flock leak is fixed. A recovery client with "allow rwq path=<subvol>" works, and a read-only "rq" client can read but not write. I saw no hot-path regression on unrelated directories, with or without a quarantine active.
Problems:
1) Snapshot access now costs an MDS round trip per operation, even when no subvolume is quarantined. __ceph_do_getattr() forces snapshot inodes, the snapdir path does a forced getattr on the parent, and __ceph_get_caps() calls ceph_snapshot_read_auth() on every acquisition. Compared with the base modules:
1000 x stat() of a file under .snap: 0.20s -> 20.07s,
0 -> 6000 MDS requests
1024 x 4k read() of a snapshot file: 0.51s -> 3.93s,
8 -> 1041 MDS requests
ls -l of a 52-entry snapshot dir: 0.64s -> 3.62sBackup workloads that read from .snap will notice. Can this be limited to clients that actually have quarantined state, or driven by an MDS notification instead of per-operation requests?
2) Blocking read() and getdents() can fail with EAGAIN. With one subvolume quarantined, a file outside it at depth 300 gave 24 EAGAIN out of 20000 preads and 16 out of 20000 listdirs, while another task was creating, renaming and listing files on the same mount. The ancestry walk stops at 256 levels, the result is CEPH_Q_UNKNOWN, and ceph_quarantine_revalidate() returns -EAGAIN when a splice is in progress, the epoch is odd, or after three requests. Callers pass that straight to userspace. Disconnected aliases (NFS re-export, open_by_handle_at) should hit the same path. These calls should wait or retry rather than fail.
3) Some changes apply to every mount whether or not the MDS supports
quarantine: ACL_DONT_CACHE on all inodes, and quarantine_lock plus two atomics on every d_splice_alias()/d_instantiate()/cross-directory d_move(). Please gate them on the feature.
For reference, overlapping grants such as "allow rw fsname=a, allow rwq fsname=a path=<subvol>" (in either order) deny quarantined access with both the kernel client and ceph-fuse, so that one is on the MDS side, as the cover letter says.
Thanks,
Xiubo
Quoted 85 lines · Alex Markuze
CephFS subvolume quarantine isolates a subvolume while allowing access by recovery clients with q/Q MDS auth caps. The kernel client currently does not advertise quarantine support, so the MDS can hold its requests until quarantine is lifted.
This series handles MClientCaps v14 quarantine notifications, checks cached data and metadata access, and handles disable notifications. Fresh MDS replies allow recovery after a lost disable. It applies directly to the base below and has no fscrypt prerequisite.
The first patch exports
d_find_alias_rcu()to GPL modules. The remaining three patches add the wire definitions, record quarantine state and ancestry generations, then install the access checks before advertising the session feature.Changes since v2:
- Add the VFS export prerequisite to fix the undefinedd_find_alias_rcusymbol reported by the kernel test robot withCONFIG_CEPH_FS=m. The fix carries Reported-by and Closes tags.
- Keep all three Ceph patches unchanged from v2.
- Replace object-only compile validation with a complete W=1 kernel and module build using GCC 14.2.0 and the robot's x86_64-rhel-9.4 config.Validation:
A complete W=1 build with the kernel.org GCC 14.2.0 toolchain and the robot's x86_64-rhel-9.4 config after olddefconfig passes. It produces vmlinux, bzImage and all 2,233 configured modules, including ceph.ko and libceph.ko. MODPOST succeeds, and Module.symvers contains the GPL export ofd_find_alias_rcu. Configuration changes are limited to olddefconfig's toolchain capability normalization; there are no manual config changes. W=1 warnings remain elsewhere in the kernel; none come from Ceph ordcache.c.
All four patches pass strict checkpatch and apply in order to reproduce the tested source tree. Seven deterministic source-extraction regression runners pass; the ASan/UBSan/LSan VFS runner also demonstrates the remaining cached encrypted-readlink bypass.Known limitation: cached encrypted symlink targets can bypass quarantine checks. fscrypt populates
inode->i_link, which the VFS can use for readlink or symlink traversal without calling Ceph'sget_linkoperation. Uncached encrypted targets and plaintext symlinks still pass through Ceph's checks. Closing the encrypted-target cache gap needs the separate fscrypt support and Ceph opt-in follow-up.Live cluster, KASAN/lockdep, multi-MDS recovery and depth benchmarks have not been run for this version. Existing snapshot mappings need server notifications to revoke already installed PTEs. Disable messages carry no generation, so same-rank ordering relies on ordered MDS delivery. Recovery assumes the intended rwq/rwQ delegation; overlapping ordinary rw and read-only q/Q grants still need server-side cap filtering.
v2: https://lore.kernel.org/r/[email protected]
Robot report:
https://lore.kernel.org/oe-kbuild-all/[email protected]/Alex Markuze (4):
dcache: exportd_find_alias_rcu()for modular filesystems
ceph: add subvolume quarantine wire definitions
ceph: record subvolume quarantine from MDS cap updates
ceph: fail quarantined subvolume access with EACCESfs/ceph/acl.c | 28 +- fs/ceph/addr.c | 72 ++- fs/ceph/caps.c | 291 +++++++++++- fs/ceph/debugfs.c | 1 + fs/ceph/dir.c | 51 ++- fs/ceph/file.c | 117 +++-- fs/ceph/inode.c | 841 ++++++++++++++++++++++++++++++++++- fs/ceph/ioctl.c | 13 + fs/ceph/mds_client.c | 23 +- fs/ceph/mds_client.h | 26 +- fs/ceph/super.c | 2 + fs/ceph/super.h | 80 +++- fs/ceph/xattr.c | 54 ++- fs/dcache.c | 1 + include/linux/ceph/ceph_fs.h | 13 + net/ceph/ceph_common.c | 2 + 16 files changed, 1482 insertions(+), 133 deletions(-)base-commit:
ed0502cb11f84fff29f374238e526ae94d9bdfde--
2.34.1