ceph: support subvolume quarantine
Subsystems (3)
Alex Markuze
maintainerv2 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 Ceph-only 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.
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. This series leaves that gap open. Uncached encrypted targets still pass through Ceph's checks, and plaintext symlinks use the revalidating callback. Closing the encrypted-target cache gap needs separate fscrypt support and a Ceph opt-in.
The three patches add the wire definitions, record quarantine state and ancestry generations, then install the access checks before advertising the session feature. The fscrypt cache opt-out is separate follow-up work.
Changes since v1:
- Keep metadata submission on its normal path, including POSIX and flock unlocks. Uncertain async creates and unlinks fall back to the MDS.
- Treat incomplete ancestry as unknown and ask the MDS. Preserve pending state across session loss, and use accepted cap replies to recover.
- Skip ancestry walks when no inode is marked. Cache complete RCU walks by generation, bound retries, and invalidate across parent changes without holding an odd generation over sleeping LSM hooks.
- Scope MDS read confirmations to the exact inode, credentials and generation. Authorize writes separately with a mode-specific OPEN.
- Check cached ACL, plaintext symlink, directory, attribute, ioctl and mmap paths. Authorize snapshot operations with a fresh MDS request; preserve connected snapshot paths and validate exact inode/snapshot replies.
- Keep nonblocking cap checks free of RPCs and release locked folios before blocking revalidation.
Validation: W=1 Ceph/libceph object builds on x86-64 with ACL, encryption, inline data and fscache enabled and disabled, and on i386 with ACL and encryption enabled. Seven deterministic source-extraction regression runners pass. The ASan/UBSan/LSan VFS runner also demonstrates the remaining cached encrypted-readlink bypass; it does not claim that gap is fixed. Live cluster, KASAN/lockdep, multi-MDS recovery and depth benchmarks have not been run for this version.
Protocol limits: 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.
Alex Markuze (3):
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 ++- include/linux/ceph/ceph_fs.h | 13 + net/ceph/ceph_common.c | 2 + 15 files changed, 1481 insertions(+), 133 deletions(-)
base-commit: ed0502cb11f84fff29f374238e526ae94d9bdfde
Signature · 1 line
2.34.1
Alex Markuze
maintainerPATCH v2 1/3 ceph: add subvolume quarantine wire definitions
The 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 v2 2/3 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
kernel test robot
build botRe: [PATCH v2 2/3] ceph: record subvolume quarantine from MDS cap updates
kernel test robot noticed the following build errors:
Hi Alex,
kernel test robot noticed the following build errors:
[auto build test ERROR on ed0502cb11f84fff29f374238e526ae94d9bdfde]
url: https://github.com/intel-lab-lkp/linux/commits/Alex-Markuze/ceph-add-subvolume-quarantine-wire-definitions/20261015-161202 base: ed0502cb11f84fff29f374238e526ae94d9bdfde patch link: https://lore.kernel.org/r/3e9b7bcfa68bd2f6bf6917f608254570a0769a12.1792074165.git.amarkuze%40redhat.com patch subject: [PATCH v2 2/3] ceph: record subvolume quarantine from MDS cap updates config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20261017/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261017/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: fs/ceph/ceph.ko: symbol 'd_find_alias_rcu' undefined!
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Alex Markuze
maintainerPATCH v2 3/3 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
Alex Markuze
maintainerv3 cover ceph: support subvolume quarantine
In reply to Alex MarkuzeCephFS 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
Al Viro
maintainerRe: [PATCH v3 4/4] ceph: fail quarantined subvolume access with EACCES
Quoted 19 lines
fs/ceph/inode.c +19
-0+/* A snapshot path must reach a head inode to encode its snapshot name. */ +static bool ceph_snapshot_has_path (struct inode *inode) +{ +struct dentry *alias =d_find_alias (inode); +struct dentry *cur; +unsigned int seq, depth =0 ; +bool connected = false; + +if (!alias) +return false; + +rcu_read_lock (); + seq =read_seqbegin (&rename_lock); + cur = alias; +while (cur && depth++ <256 ) { +struct inode *in =d_inode_rcu (cur); +struct dentry *parent; + +if (!in)
fs/ceph/inode.c int ceph_try_to_choose_auth_mds(struct inode *inode, int mask) · line 3773
Quoted 10 lines
fs/ceph/inode.c +10
-0+break ; +if (!ceph_in_snap (in)) { + connected = true; +break ; + } +if (d_unhashed (cur) || + (READ_ONCE (cur->d_flags) &DCACHE_DISCONNECTED )) +break ; + parent =READ_ONCE (cur->d_parent); +if (!parent || parent == cur)
^^^^^^^
Please, explain how could that possibly happen.
Quoted 372 lines
fs/ceph/inode.c +122
-3+break ; + cur = parent; + } +if (read_seqretry (&rename_lock, seq)) + connected = false; +rcu_read_unlock (); +dput (alias); +return connected; +} + +static int ceph_snapshot_reply_error (struct inode *inode, +struct ceph_mds_request *req,int mask) +{ +struct ceph_inode_info *ci =ceph_inode (inode); +bool have_xattrs; + +if (!req->r_target_inode || +ceph_ino (req->r_target_inode) !=ceph_ino (inode) || +ceph_snap (req->r_target_inode) !=ceph_snap (inode)) +return -EOPNOTSUPP ; + +/* LOOKUPINO can authorize access without returning the requested blob. */ +if ((mask &CEPH_CAP_XATTR_SHARED ) && + req->r_reply_info.targeti.xattr_len <4 ) { +spin_lock (&ci->i_ceph_lock); + have_xattrs = ci->i_xattrs.version !=0 ; +spin_unlock (&ci->i_ceph_lock); +if (!have_xattrs) +return -EOPNOTSUPP ; + } +if ((mask &CEPH_CAP_FILE_RD ) && + req->r_reply_info.targeti.inline_version ==0 && +ceph_has_inline_data (ci) &&i_size_read (inode) >0 ) +return -EOPNOTSUPP ; +return 0 ; +} + +static int ceph_snapshot_lookupino (struct inode *inode, +struct folio *locked_folio,int mask) +{ +struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (inode->i_sb); +struct ceph_mds_request *req; +int err; + + req =ceph_mdsc_create_request (mdsc,CEPH_MDS_OP_LOOKUPINO ,USE_ANY_MDS ); +if (IS_ERR (req)) +return PTR_ERR (req); +/* No r_inode: an NFS alias may not encode a snapshot pathname. */ + req->r_ino1 =ceph_vino (inode); + req->r_args.lookupino.snapid =cpu_to_le64 (ceph_snap (inode)); + req->r_args.lookupino.mask =cpu_to_le32 (mask); + req->r_num_caps =1 ; + req->r_locked_folio = locked_folio; + err =ceph_mdsc_do_request (mdsc,NULL , req); +if (!err) + err =ceph_snapshot_reply_error (inode, req, mask); +if (locked_folio && !err) { +u64 version = req->r_reply_info.targeti.inline_version; + +if (version ==0 ) + err = -EINVAL ; +else if (version ==CEPH_INLINE_NONE || version ==1 ) + err = -ENODATA ; +else + err = req->r_reply_info.targeti.inline_len; + } +ceph_mdsc_put_request (req); +return err; +} + +int ceph_snapshot_read_auth (struct inode *inode) +{ +/* +* Preserve a connected snapshot path: its head inode may have been +* deleted and no longer be cached by the MDS. Disconnected handles +* fall back to LOOKUPINO, with the exact inode and snapshot ID. +* The authorization is scoped to this operation, never cached. +*/ +return ceph_do_getattr (inode,CEPH_CAP_AUTH_SHARED , true); +} +/* * Verify that we have a lease on the given mask. If not, * do a getattr against an mds. @@ -3582,20 +3863,43 @@ int __ceph_do_getattr(struct inode *inode, struct folio *locked_folio,struct ceph_client *cl = fsc->client;struct ceph_mds_client *mdsc = fsc->mdsc;struct ceph_mds_request *req; +u64 qepoch;int mode;int err;if (ceph_snap (inode) ==CEPH_SNAPDIR ) { +struct inode *parent; +boutc (cl,"inode %p %llx.%llx SNAPDIR\n" , inode,ceph_vinop (inode)); -return 0 ; +/* The synthetic snapdir has the real directory's ino. */ + parent =ceph_lookup_inode (inode->i_sb,ceph_ino (inode)); +if (IS_ERR (parent)) +return PTR_ERR (parent); + err =ceph_do_getattr (parent, mask, true); +iput (parent); +return err; } +if (ceph_in_snap (inode) && !ceph_snapshot_has_path (inode)) +return ceph_snapshot_lookupino (inode, locked_folio, mask); + +/* +* Cached caps would satisfy getattr after the MDS has revoked +* access, and a short walk has no ancestor to consult. Ask the +* MDS so a lost quarantine-disable can clear the mark, and so +* an uncached parent chain is not treated as clear. Immutable snapshot +* caps cannot receive revocations and always require an MDS check. +*/ +if (ceph_in_snap (inode) || +ceph_inode_quarantine_state (inode) !=CEPH_Q_CLEAR ) + force = true;boutc (cl,"inode %p %llx.%llx mask %s mode 0%o\n" , inode,ceph_vinop (inode),ceph_cap_string (mask), inode->i_mode);if (!force &&ceph_caps_issued_mask_metric (ceph_inode (inode), mask,1 ))return 0 ; + qepoch = (u64 )atomic64_read_acquire (&mdsc->quarantine_epoch); mode =ceph_try_to_choose_auth_mds (inode, mask); req =ceph_mdsc_create_request (mdsc,CEPH_MDS_OP_GETATTR , mode);if (IS_ERR (req))@@ -3606,6 +3910,15 @@ int __ceph_do_getattr(struct inode *inode, struct folio *locked_folio, req->r_args.getattr.mask =cpu_to_le32 (mask); req->r_locked_folio = locked_folio; err =ceph_mdsc_do_request (mdsc,NULL , req); +if (ceph_in_snap (inode)) { +if (err == -EINVAL || err == -ESTALE || + (!err &&ceph_snapshot_reply_error (inode, req, mask))) { +ceph_mdsc_put_request (req); +return ceph_snapshot_lookupino (inode, locked_folio, mask); + } + } +if (!err && !ceph_in_snap (inode)) +ceph_quarantine_remember_clear (inode, qepoch, req->r_cred);if (locked_folio && err ==0 ) {u64 inline_version = req->r_reply_info.targeti.inline_version;if (inline_version ==0 ) {@@ -3751,8 +4064,14 @@ int ceph_getattr(struct mnt_idmap *idmap, const struct path *path,return -ESTALE ; } -/* Skip the getattr altogether if we're asked not to sync */ -if ((flags &AT_STATX_SYNC_TYPE ) !=AT_STATX_DONT_SYNC ) { +/* +* AT_STATX_DONT_SYNC would return the cached attrs. A +* quarantined inode, or one whose parents are not cached, +* still has to ask the MDS. Snapshot caps cannot receive revocations. +*/ +if (ceph_in_snap (inode) || +ceph_inode_quarantine_state (inode) !=CEPH_Q_CLEAR || + (flags &AT_STATX_SYNC_TYPE ) !=AT_STATX_DONT_SYNC ) { err =ceph_do_getattr (inode,statx_to_caps (request_mask, inode->i_mode), flags &AT_STATX_FORCE_SYNC );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@@ -997,6 +997,7 @@ ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value,struct ceph_vxattr *vxattr;int req_mask;ssize_t err; +bool ask_mds = false;if (strncmp (name,XATTR_CEPH_PREFIX ,XATTR_CEPH_PREFIX_LEN )) goto handle_non_vxattrs;@@ -1034,7 +1035,19 @@ ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value,ceph_vinop (inode), name, ci->i_xattrs.version, ci->i_xattrs.index_version); -if (ci->i_xattrs.version ==0 || +/* +* A shared cap would answer from the cache. The state check may +* schedule, so drop i_ceph_lock first. A reply reading the blob +* it just installed must still use that cache. +*/ +if (!ceph_current_fill_trace_request ()) { +spin_unlock (&ci->i_ceph_lock); + ask_mds =ceph_in_snap (inode) || +ceph_inode_quarantine_state (inode) !=CEPH_Q_CLEAR ; +spin_lock (&ci->i_ceph_lock); + } + +if (ask_mds || ci->i_xattrs.version ==0 || !((req_mask &CEPH_CAP_XATTR_SHARED ) ||__ceph_caps_issued_mask_metric (ci,CEPH_CAP_XATTR_SHARED ,1 ))) {spin_unlock (&ci->i_ceph_lock);@@ -1089,6 +1102,7 @@ ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size)struct ceph_client *cl =ceph_inode_to_client (inode);struct ceph_inode_info *ci =ceph_inode (inode);bool len_only = (size ==0 ); +bool ask_mds = false;u32 namelen;int err;struct ceph_journal_info __ji;@@ -1100,7 +1114,15 @@ ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size)ceph_vinop (inode), ci->i_xattrs.version, ci->i_xattrs.index_version); -if (ci->i_xattrs.version ==0 || +/* Same as __ceph_getxattr(): do not serve a shared cap hit. */ +if (!ceph_current_fill_trace_request ()) { +spin_unlock (&ci->i_ceph_lock); + ask_mds =ceph_in_snap (inode) || +ceph_inode_quarantine_state (inode) !=CEPH_Q_CLEAR ; +spin_lock (&ci->i_ceph_lock); + } + +if (ask_mds || ci->i_xattrs.version ==0 || !__ceph_caps_issued_mask_metric (ci,CEPH_CAP_XATTR_SHARED ,1 )) {spin_unlock (&ci->i_ceph_lock); err =ceph_do_getattr (inode,CEPH_STAT_CAP_XATTR , true);@@ -1222,6 +1244,7 @@ int __ceph_setxattr(struct inode *inode, const char *name,int required_blob_size;bool check_realm = false;bool lock_snap_rwsem = false; +bool checked_quarantine = false;if (ceph_in_snap (inode))return -EROFS ;@@ -1319,6 +1342,33 @@ int __ceph_setxattr(struct inode *inode, const char *name, goto retry; } +/* +* XATTR_EXCL applies the new blob with no MDS round trip. +* The state check may schedule, so drop i_ceph_lock first. +*/ +if (!checked_quarantine) { +enum ceph_qstate qstate; + +spin_unlock (&ci->i_ceph_lock); + qstate =ceph_inode_quarantine_write_state (inode); +if (qstate ==CEPH_Q_UNDER && +ceph_inode_quarantine_direct (inode)) { +ceph_buffer_put (old_blob); +if (lock_snap_rwsem) +up_read (&mdsc->snap_rwsem); + err = -EACCES ; + goto out; + } +if (qstate !=CEPH_Q_CLEAR ) { +ceph_buffer_put (old_blob); + old_blob =NULL ; + goto do_sync_unlocked; + } + checked_quarantine = true; +spin_lock (&ci->i_ceph_lock); + goto retry; + } + err =__set_xattr (ci, newname, name_len, newval, val_len, flags, value ?1 :-1 , &xattr);Signature · 1 line
2.34.1
Alex Markuze
maintainerRe: [PATCH v3 4/4] ceph: fail quarantined subvolume access with EACCES
Quoted 31 lines · Al Viro
Quoted 20 lines
fs/ceph/inode.c +19
-0+/* A snapshot path must reach a head inode to encode its snapshot name. */ +static bool ceph_snapshot_has_path (struct inode *inode) +{ +struct dentry *alias =d_find_alias (inode); +struct dentry *cur; +unsigned int seq, depth =0 ; +bool connected = false; + +if (!alias) +return false; + +rcu_read_lock (); + seq =read_seqbegin (&rename_lock); + cur = alias; +while (cur && depth++ <256 ) { +struct inode *in =d_inode_rcu (cur); +struct dentry *parent; + +if (!in)fs/ceph/inode.c int ceph_try_to_choose_auth_mds(struct inode *inode, int mask) · line 3773
Quoted 10 lines
fs/ceph/inode.c +10
-0+break ; +if (!ceph_in_snap (in)) { + connected = true; +break ; + } +if (d_unhashed (cur) || + (READ_ONCE (cur->d_flags) &DCACHE_DISCONNECTED )) +break ; + parent =READ_ONCE (cur->d_parent); +if (!parent || parent == cur)^^^^^^^
Quoted 1 line
Please, explain how could that possibly happen.
This can't happen in the code as currently written; it's a cheap redundancy.
Quoted 373 lines
Quoted 372 lines
fs/ceph/inode.c +122
-3+break ; + cur = parent; + } +if (read_seqretry (&rename_lock, seq)) + connected = false; +rcu_read_unlock (); +dput (alias); +return connected; +} + +static int ceph_snapshot_reply_error (struct inode *inode, +struct ceph_mds_request *req,int mask) +{ +struct ceph_inode_info *ci =ceph_inode (inode); +bool have_xattrs; + +if (!req->r_target_inode || +ceph_ino (req->r_target_inode) !=ceph_ino (inode) || +ceph_snap (req->r_target_inode) !=ceph_snap (inode)) +return -EOPNOTSUPP ; + +/* LOOKUPINO can authorize access without returning the requested blob. */ +if ((mask &CEPH_CAP_XATTR_SHARED ) && + req->r_reply_info.targeti.xattr_len <4 ) { +spin_lock (&ci->i_ceph_lock); + have_xattrs = ci->i_xattrs.version !=0 ; +spin_unlock (&ci->i_ceph_lock); +if (!have_xattrs) +return -EOPNOTSUPP ; + } +if ((mask &CEPH_CAP_FILE_RD ) && + req->r_reply_info.targeti.inline_version ==0 && +ceph_has_inline_data (ci) &&i_size_read (inode) >0 ) +return -EOPNOTSUPP ; +return 0 ; +} + +static int ceph_snapshot_lookupino (struct inode *inode, +struct folio *locked_folio,int mask) +{ +struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (inode->i_sb); +struct ceph_mds_request *req; +int err; + + req =ceph_mdsc_create_request (mdsc,CEPH_MDS_OP_LOOKUPINO ,USE_ANY_MDS ); +if (IS_ERR (req)) +return PTR_ERR (req); +/* No r_inode: an NFS alias may not encode a snapshot pathname. */ + req->r_ino1 =ceph_vino (inode); + req->r_args.lookupino.snapid =cpu_to_le64 (ceph_snap (inode)); + req->r_args.lookupino.mask =cpu_to_le32 (mask); + req->r_num_caps =1 ; + req->r_locked_folio = locked_folio; + err =ceph_mdsc_do_request (mdsc,NULL , req); +if (!err) + err =ceph_snapshot_reply_error (inode, req, mask); +if (locked_folio && !err) { +u64 version = req->r_reply_info.targeti.inline_version; + +if (version ==0 ) + err = -EINVAL ; +else if (version ==CEPH_INLINE_NONE || version ==1 ) + err = -ENODATA ; +else + err = req->r_reply_info.targeti.inline_len; + } +ceph_mdsc_put_request (req); +return err; +} + +int ceph_snapshot_read_auth (struct inode *inode) +{ +/* +* Preserve a connected snapshot path: its head inode may have been +* deleted and no longer be cached by the MDS. Disconnected handles +* fall back to LOOKUPINO, with the exact inode and snapshot ID. +* The authorization is scoped to this operation, never cached. +*/ +return ceph_do_getattr (inode,CEPH_CAP_AUTH_SHARED , true); +} +/* * Verify that we have a lease on the given mask. If not, * do a getattr against an mds. @@ -3582,20 +3863,43 @@ int __ceph_do_getattr(struct inode *inode, struct folio *locked_folio,struct ceph_client *cl = fsc->client;struct ceph_mds_client *mdsc = fsc->mdsc;struct ceph_mds_request *req; +u64 qepoch;int mode;int err;if (ceph_snap (inode) ==CEPH_SNAPDIR ) { +struct inode *parent; +boutc (cl,"inode %p %llx.%llx SNAPDIR\n" , inode,ceph_vinop (inode)); -return 0 ; +/* The synthetic snapdir has the real directory's ino. */ + parent =ceph_lookup_inode (inode->i_sb,ceph_ino (inode)); +if (IS_ERR (parent)) +return PTR_ERR (parent); + err =ceph_do_getattr (parent, mask, true); +iput (parent); +return err; } +if (ceph_in_snap (inode) && !ceph_snapshot_has_path (inode)) +return ceph_snapshot_lookupino (inode, locked_folio, mask); + +/* +* Cached caps would satisfy getattr after the MDS has revoked +* access, and a short walk has no ancestor to consult. Ask the +* MDS so a lost quarantine-disable can clear the mark, and so +* an uncached parent chain is not treated as clear. Immutable snapshot +* caps cannot receive revocations and always require an MDS check. +*/ +if (ceph_in_snap (inode) || +ceph_inode_quarantine_state (inode) !=CEPH_Q_CLEAR ) + force = true;boutc (cl,"inode %p %llx.%llx mask %s mode 0%o\n" , inode,ceph_vinop (inode),ceph_cap_string (mask), inode->i_mode);if (!force &&ceph_caps_issued_mask_metric (ceph_inode (inode), mask,1 ))return 0 ; + qepoch = (u64 )atomic64_read_acquire (&mdsc->quarantine_epoch); mode =ceph_try_to_choose_auth_mds (inode, mask); req =ceph_mdsc_create_request (mdsc,CEPH_MDS_OP_GETATTR , mode);if (IS_ERR (req))@@ -3606,6 +3910,15 @@ int __ceph_do_getattr(struct inode *inode, struct folio *locked_folio, req->r_args.getattr.mask =cpu_to_le32 (mask); req->r_locked_folio = locked_folio; err =ceph_mdsc_do_request (mdsc,NULL , req); +if (ceph_in_snap (inode)) { +if (err == -EINVAL || err == -ESTALE || + (!err &&ceph_snapshot_reply_error (inode, req, mask))) { +ceph_mdsc_put_request (req); +return ceph_snapshot_lookupino (inode, locked_folio, mask); + } + } +if (!err && !ceph_in_snap (inode)) +ceph_quarantine_remember_clear (inode, qepoch, req->r_cred);if (locked_folio && err ==0 ) {u64 inline_version = req->r_reply_info.targeti.inline_version;if (inline_version ==0 ) {@@ -3751,8 +4064,14 @@ int ceph_getattr(struct mnt_idmap *idmap, const struct path *path,return -ESTALE ; } -/* Skip the getattr altogether if we're asked not to sync */ -if ((flags &AT_STATX_SYNC_TYPE ) !=AT_STATX_DONT_SYNC ) { +/* +* AT_STATX_DONT_SYNC would return the cached attrs. A +* quarantined inode, or one whose parents are not cached, +* still has to ask the MDS. Snapshot caps cannot receive revocations. +*/ +if (ceph_in_snap (inode) || +ceph_inode_quarantine_state (inode) !=CEPH_Q_CLEAR || + (flags &AT_STATX_SYNC_TYPE ) !=AT_STATX_DONT_SYNC ) { err =ceph_do_getattr (inode,statx_to_caps (request_mask, inode->i_mode), flags &AT_STATX_FORCE_SYNC );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
-3@@ -997,6 +997,7 @@ ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value,struct ceph_vxattr *vxattr;int req_mask;ssize_t err; +bool ask_mds = false;if (strncmp (name,XATTR_CEPH_PREFIX ,XATTR_CEPH_PREFIX_LEN )) goto handle_non_vxattrs;@@ -1034,7 +1035,19 @@ ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value,ceph_vinop (inode), name, ci->i_xattrs.version, ci->i_xattrs.index_version); -if (ci->i_xattrs.version ==0 || +/* +* A shared cap would answer from the cache. The state check may +* schedule, so drop i_ceph_lock first. A reply reading the blob +* it just installed must still use that cache. +*/ +if (!ceph_current_fill_trace_request ()) { +spin_unlock (&ci->i_ceph_lock); + ask_mds =ceph_in_snap (inode) || +ceph_inode_quarantine_state (inode) !=CEPH_Q_CLEAR ; +spin_lock (&ci->i_ceph_lock); + } + +if (ask_mds || ci->i_xattrs.version ==0 || !((req_mask &CEPH_CAP_XATTR_SHARED ) ||__ceph_caps_issued_mask_metric (ci,CEPH_CAP_XATTR_SHARED ,1 ))) {spin_unlock (&ci->i_ceph_lock);@@ -1089,6 +1102,7 @@ ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size)struct ceph_client *cl =ceph_inode_to_client (inode);struct ceph_inode_info *ci =ceph_inode (inode);bool len_only = (size ==0 ); +bool ask_mds = false;u32 namelen;int err;struct ceph_journal_info __ji;@@ -1100,7 +1114,15 @@ ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size)ceph_vinop (inode), ci->i_xattrs.version, ci->i_xattrs.index_version); -if (ci->i_xattrs.version ==0 || +/* Same as __ceph_getxattr(): do not serve a shared cap hit. */ +if (!ceph_current_fill_trace_request ()) { +spin_unlock (&ci->i_ceph_lock); + ask_mds =ceph_in_snap (inode) || +ceph_inode_quarantine_state (inode) !=CEPH_Q_CLEAR ; +spin_lock (&ci->i_ceph_lock); + } + +if (ask_mds || ci->i_xattrs.version ==0 || !__ceph_caps_issued_mask_metric (ci,CEPH_CAP_XATTR_SHARED ,1 )) {spin_unlock (&ci->i_ceph_lock); err =ceph_do_getattr (inode,CEPH_STAT_CAP_XATTR , true);@@ -1222,6 +1244,7 @@ int __ceph_setxattr(struct inode *inode, const char *name,int required_blob_size;bool check_realm = false;bool lock_snap_rwsem = false; +bool checked_quarantine = false;if (ceph_in_snap (inode))return -EROFS ;@@ -1319,6 +1342,33 @@ int __ceph_setxattr(struct inode *inode, const char *name, goto retry; } +/* +* XATTR_EXCL applies the new blob with no MDS round trip. +* The state check may schedule, so drop i_ceph_lock first. +*/ +if (!checked_quarantine) { +enum ceph_qstate qstate; + +spin_unlock (&ci->i_ceph_lock); + qstate =ceph_inode_quarantine_write_state (inode); +if (qstate ==CEPH_Q_UNDER && +ceph_inode_quarantine_direct (inode)) { +ceph_buffer_put (old_blob); +if (lock_snap_rwsem) +up_read (&mdsc->snap_rwsem); + err = -EACCES ; + goto out; + } +if (qstate !=CEPH_Q_CLEAR ) { +ceph_buffer_put (old_blob); + old_blob =NULL ; + goto do_sync_unlocked; + } + checked_quarantine = true; +spin_lock (&ci->i_ceph_lock); + goto retry; + } + err =__set_xattr (ci, newname, name_len, newval, val_len, flags, value ?1 :-1 , &xattr); --2.34.1