History

Merge tag 'ceph-for-7.2-rc5' of https://github.com/ceph/ceph-client

Pull ceph fixes from Ilya Dryomov: "A bunch of assorted fixes with the majority being hardening against malformed input and invalid data scenarios that don't happen in real deployments but can be utilized to trigger use-after-free and similar issues, some error path leak fixups and two patches from Max to avoid a potential hang in __ceph_get_caps() and unintended nesting of current->journal_info while handling replies from the MDS. All marked for stable" * tag 'ceph-for-7.2-rc5' of https://github.com/ceph/ceph-client: ceph: avoid fs reclaim while using current->journal_info ceph: add owner/capability checks for CEPH_IOC_SET_LAYOUT* ceph: fix hanging __ceph_get_caps() with stale mds_wanted rbd: Reset positive result codes to zero in object map update path libceph: bound pg_{temp,upmap,upmap_items} length to CEPH_PG_MAX_SIZE libceph: refresh auth->authorizer_buf{,_len} after authorizer update ceph: fix refcount leak in ceph_readdir() libceph: guard missing CRUSH type name lookup libceph: remove debugfs files before client teardown libceph: bound get_version reply decode to front len ceph: fix writeback_count leak in write_folio_nounlock() libceph: fix two unsafe bare decodes in decode_lockers() ceph: fix pre-auth out-of-bounds read on snaptrace in ceph_handle_caps() libceph: Reject monmaps advertising zero monitors libceph: reject zero bucket types in crush_decode libceph: Fix multiplication overflow in decode_new_up_state_weight()

Linus Torvalds committed 3 months ago

Commit dad0a872 parents 981f4a2 5b6023413 files · +90 −19Browse files

Unified · Split

13 files
  1. drivers/block/rbd.c +6 −1
  2. fs/ceph/addr.c +9 −0
  3. fs/ceph/caps.c +16 −2
  4. fs/ceph/dir.c +6 −1
  5. fs/ceph/file.c +5 −4
  6. fs/ceph/ioctl.c +6 −0
  7. fs/ceph/mds_client.c +11 −0
  8. fs/ceph/mds_client.h +1 −0
  9. net/ceph/auth_x.c +8 −1
  10. net/ceph/ceph_common.c +2 −2
  11. net/ceph/cls_lock_client.c +6 −2
  12. net/ceph/mon_client.c +2 −2
  13. net/ceph/osdmap.c +12 −4
drivers/block/rbd.c+6−1
@@ -1950,9 +1950,14 @@ static int rbd_object_map_update_finish(struct rbd_obj_request *obj_req, · 1949 unmodified lines
19501950 bool has_current_state;
19511951 void *p;
19521952
1953− if (osd_req->r_result)
1953+ if (osd_req->r_result < 0)
19541954 return osd_req->r_result;
19551955
1956+ /*
1957+ * Writes aren't allowed to return a data payload.
1958+ */
1959+ WARN_ON_ONCE(osd_req->r_result > 0);
1960+
19561961 /*
19571962 * Nothing to do for a snapshot object map.
19581963 */
fs/ceph/addr.c+9−0
@@ -790,6 +790,9 @@ static int write_folio_nounlock(struct folio *folio, · 789 unmodified lines
790790 ceph_wbc.truncate_size, true);
791791 if (IS_ERR(req)) {
792792 folio_redirty_for_writepage(wbc, folio);
793+ if (atomic_long_dec_return(&fsc->writeback_count) <
794+ CONGESTION_OFF_THRESH(fsc->mount_options->congestion_kb))
795+ fsc->write_congested = false;
793796 return PTR_ERR(req);
794797 }
795798
@@ -809,6 +812,9 @@ static int write_folio_nounlock(struct folio *folio, · 13 unmodified lines
809812 folio_redirty_for_writepage(wbc, folio);
810813 folio_end_writeback(folio);
811814 ceph_osdc_put_request(req);
815+ if (atomic_long_dec_return(&fsc->writeback_count) <
816+ CONGESTION_OFF_THRESH(fsc->mount_options->congestion_kb))
817+ fsc->write_congested = false;
812818 return PTR_ERR(bounce_page);
813819 }
814820 }
@@ -847,6 +853,9 @@ static int write_folio_nounlock(struct folio *folio, · 32 unmodified lines
847853 ceph_vinop(inode), folio);
848854 folio_redirty_for_writepage(wbc, folio);
849855 folio_end_writeback(folio);
856+ if (atomic_long_dec_return(&fsc->writeback_count) <
857+ CONGESTION_OFF_THRESH(fsc->mount_options->congestion_kb))
858+ fsc->write_congested = false;
850859 return err;
851860 }
852861 if (err == -EBLOCKLISTED)
fs/ceph/caps.c+16−2
@@ -3094,7 +3094,19 @@ int __ceph_get_caps(struct inode *inode, struct ceph_file_info *fi, int need, · 3093 unmodified lines
30943094 ret = -ERESTARTSYS;
30953095 break;
30963096 }
3097− wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
3097+
3098+ /*
3099+ * If a cap update is lost after
3100+ * mds_wanted was raised, waiting
3101+ * forever will never make progress.
3102+ * Retry the renew path periodically
3103+ * so we can resend synchronously.
3104+ */
3105+ if (!wait_woken(&wait, TASK_INTERRUPTIBLE,
3106+ CEPH_GET_CAPS_WAIT_TIMEOUT)) {
3107+ ret = -EUCLEAN;
3108+ break;
3109+ }
30983110 }
30993111
31003112 remove_wait_queue(&ci->i_cap_wq, &wait);
@@ -3128,7 +3140,8 @@ int __ceph_get_caps(struct inode *inode, struct ceph_file_info *fi, int need, · 27 unmodified lines
31283140 continue;
31293141 }
31303142 if (ret == -EUCLEAN) {
3131− /* session was killed, try renew caps */
3143+ /* session was killed or a waited cap
3144+ * request needs a retry */
31323145 ret = ceph_renew_caps(inode, flags);
31333146 if (ret == 0)
31343147 continue;
@@ -4375,6 +4388,7 @@ void ceph_handle_caps(struct ceph_mds_session *session, · 1240 unmodified lines
43754388
43764389 snaptrace = h + 1;
43774390 snaptrace_len = le32_to_cpu(h->snap_trace_len);
4391+ ceph_decode_need(&snaptrace, end, snaptrace_len, bad);
43784392 p = snaptrace + snaptrace_len;
43794393
43804394 if (msg_version >= 2) {
fs/ceph/dir.c+6−1
@@ -546,11 +546,16 @@ more: · 545 unmodified lines
546546 pr_warn_client(cl,
547547 "%p %llx.%llx rde->offset 0x%llx ctx->pos 0x%llx\n",
548548 inode, ceph_vinop(inode), rde->offset, ctx->pos);
549+ ceph_mdsc_put_request(dfi->last_readdir);
550+ dfi->last_readdir = NULL;
549551 return -EIO;
550552 }
551553
552− if (WARN_ON_ONCE(!rde->inode.in))
554+ if (WARN_ON_ONCE(!rde->inode.in)) {
555+ ceph_mdsc_put_request(dfi->last_readdir);
556+ dfi->last_readdir = NULL;
553557 return -EIO;
558+ }
554559
555560 ctx->pos = rde->offset;
556561 doutc(cl, "%p %llx.%llx (%d/%d) -> %llx '%.*s' %p\n", inode,
fs/ceph/file.c+5−4
@@ -314,7 +314,7 @@ static int ceph_init_file(struct inode *inode, struct file *file, int fmode) · 313 unmodified lines
314314 }
315315
316316 /*
317− * try renew caps after session gets killed.
317+ * Retry cap acquisition after a stale session or a lost cap update.
318318 */
319319 int ceph_renew_caps(struct inode *inode, int fmode)
320320 {
@@ -322,14 +322,15 @@ int ceph_renew_caps(struct inode *inode, int fmode) · 1 unmodified line
322322 struct ceph_client *cl = mdsc->fsc->client;
323323 struct ceph_inode_info *ci = ceph_inode(inode);
324324 struct ceph_mds_request *req;
325− int err, flags, wanted;
325+ int err, flags, wanted, issued;
326326
327327 spin_lock(&ci->i_ceph_lock);
328328 __ceph_touch_fmode(ci, mdsc, fmode);
329329 wanted = __ceph_caps_file_wanted(ci);
330+ issued = __ceph_caps_issued(ci, NULL);
330331 if (__ceph_is_any_real_caps(ci) &&
331− (!(wanted & CEPH_CAP_ANY_WR) || ci->i_auth_cap)) {
332− int issued = __ceph_caps_issued(ci, NULL);
332+ (!(wanted & CEPH_CAP_ANY_WR) || ci->i_auth_cap) &&
333+ (issued & wanted) == wanted) {
333334 spin_unlock(&ci->i_ceph_lock);
334335 doutc(cl, "%p %llx.%llx want %s issued %s updating mds_wanted\n",
335336 inode, ceph_vinop(inode), ceph_cap_string(wanted),
fs/ceph/ioctl.c+6−0
@@ -72,6 +72,9 @@ static long ceph_ioctl_set_layout(struct file *file, void __user *arg) · 71 unmodified lines
7272 struct ceph_ioctl_layout nl;
7373 int err;
7474
75+ if (!inode_owner_or_capable(&nop_mnt_idmap, inode))
76+ return -EACCES;
77+
7578 if (copy_from_user(&l, arg, sizeof(l)))
7679 return -EFAULT;
7780
@@ -142,6 +145,9 @@ static long ceph_ioctl_set_layout_policy (struct file *file, void __user *arg) · 64 unmodified lines
142145 int err;
143146 struct ceph_mds_client *mdsc = ceph_sb_to_fs_client(inode->i_sb)->mdsc;
144147
148+ if (!inode_owner_or_capable(&nop_mnt_idmap, inode))
149+ return -EACCES;
150+
145151 /* copy and validate */
146152 if (copy_from_user(&l, arg, sizeof(l)))
147153 return -EFAULT;
fs/ceph/mds_client.c+11−0
@@ -6,6 +6,7 @@ · 5 unmodified lines
66 #include <linux/slab.h>
77 #include <linux/gfp.h>
88 #include <linux/sched.h>
9+#include <linux/sched/mm.h>
910 #include <linux/delay.h>
1011 #include <linux/debugfs.h>
1112 #include <linux/seq_file.h>
@@ -4015,6 +4016,7 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg) · 4003 unmodified lines
40154016 struct ceph_mds_reply_head *head = msg->front.iov_base;
40164017 struct ceph_mds_reply_info_parsed *rinfo; /* parsed reply info */
40174018 struct ceph_snap_realm *realm;
4019+ unsigned int nofs_flags;
40184020 u64 tid;
40194021 int err, result;
40204022 int mds = session->s_mds;
@@ -4158,6 +4160,14 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg) · 137 unmodified lines
41584160
41594161 /* insert trace into our cache */
41604162 mutex_lock(&req->r_fill_mutex);
4163+
4164+ /* disable fs reclaim while we are using current->journal_info
4165+ * for our own purposes, or else shrinkers of other
4166+ * filesystems might dereference this pointer as a different
4167+ * type
4168+ */
4169+ nofs_flags = memalloc_nofs_save();
4170+
41614171 current->journal_info = req;
41624172 err = ceph_fill_trace(mdsc->fsc->sb, req);
41634173 if (err == 0) {
@@ -4166,6 +4176,7 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg) · 2 unmodified lines
41664176 err = ceph_readdir_prepopulate(req, req->r_session);
41674177 }
41684178 current->journal_info = NULL;
4179+ memalloc_nofs_restore(nofs_flags);
41694180 mutex_unlock(&req->r_fill_mutex);
41704181
41714182 up_read(&mdsc->snap_rwsem);
fs/ceph/mds_client.h+1−0
@@ -77,6 +77,7 @@ struct ceph_fs_client; · 76 unmodified lines
7777 struct ceph_cap;
7878
7979 #define MDS_AUTH_UID_ANY -1
80+#define CEPH_GET_CAPS_WAIT_TIMEOUT (5 * HZ)
8081 #define CEPH_CAP_FLUSH_WAIT_TIMEOUT_SEC 60
8182 #define CEPH_CAP_FLUSH_MAX_DUMP_ENTRIES 5
8283 #define CEPH_CAP_FLUSH_MAX_DUMP_ITERS 5
net/ceph/auth_x.c+8−1
@@ -849,9 +849,16 @@ static int ceph_x_update_authorizer( · 848 unmodified lines
849849
850850 au = (struct ceph_x_authorizer *)auth->authorizer;
851851 if (au->secret_id < th->secret_id) {
852+ int ret;
853+
852854 dout("ceph_x_update_authorizer service %u secret %llu < %llu\n",
853855 au->service, au->secret_id, th->secret_id);
854− return ceph_x_build_authorizer(ac, th, au);
856+ ret = ceph_x_build_authorizer(ac, th, au);
857+ if (ret)
858+ return ret;
859+
860+ auth->authorizer_buf = au->buf->vec.iov_base;
861+ auth->authorizer_buf_len = au->buf->vec.iov_len;
855862 }
856863 return 0;
857864 }
net/ceph/ceph_common.c+2−2
@@ -762,13 +762,13 @@ void ceph_destroy_client(struct ceph_client *client) · 761 unmodified lines
762762
763763 atomic_set(&client->msgr.stopping, 1);
764764
765+ ceph_debugfs_client_cleanup(client);
766+
765767 /* unmount */
766768 ceph_osdc_stop(&client->osdc);
767769 ceph_monc_stop(&client->monc);
768770 ceph_messenger_fini(&client->msgr);
769771
770− ceph_debugfs_client_cleanup(client);
771−
772772 ceph_destroy_options(client->options);
773773
774774 kfree(client);
net/ceph/cls_lock_client.c+6−2
@@ -299,7 +299,7 @@ static int decode_lockers(void **p, void *end, u8 *type, char **tag, · 298 unmodified lines
299299 if (ret)
300300 return ret;
301301
302− *num_lockers = ceph_decode_32(p);
302+ ceph_decode_32_safe(p, end, *num_lockers, err_inval);
303303 *lockers = kzalloc_objs(**lockers, *num_lockers, GFP_NOIO);
304304 if (!*lockers)
305305 return -ENOMEM;
@@ -310,7 +310,8 @@ static int decode_lockers(void **p, void *end, u8 *type, char **tag, · 4 unmodified lines
310310 goto err_free_lockers;
311311 }
312312
313− *type = ceph_decode_8(p);
313+ ret = -EINVAL;
314+ ceph_decode_8_safe(p, end, *type, err_free_lockers);
314315 s = ceph_extract_encoded_string(p, end, NULL, GFP_NOIO);
315316 if (IS_ERR(s)) {
316317 ret = PTR_ERR(s);
@@ -320,6 +321,9 @@ static int decode_lockers(void **p, void *end, u8 *type, char **tag, · 3 unmodified lines
320321 *tag = s;
321322 return 0;
322323
324+err_inval:
325+ return -EINVAL;
326+
323327 err_free_lockers:
324328 ceph_free_lockers(*lockers, *num_lockers);
325329 return ret;
net/ceph/mon_client.c+2−2
@@ -114,7 +114,7 @@ static struct ceph_monmap *ceph_monmap_decode(void **p, void *end, bool msgr2) · 113 unmodified lines
114114
115115 dout("%s fsid %pU epoch %u num_mon %u\n", __func__, &fsid, epoch,
116116 num_mon);
117− if (num_mon > CEPH_MAX_MON)
117+ if (num_mon == 0 || num_mon > CEPH_MAX_MON)
118118 goto e_inval;
119119
120120 monmap = kmalloc_flex(*monmap, mon_inst, num_mon, GFP_NOIO);
@@ -821,7 +821,7 @@ static void handle_get_version_reply(struct ceph_mon_client *monc, · 700 unmodified lines
821821 struct ceph_mon_generic_request *req;
822822 u64 tid = le64_to_cpu(msg->hdr.tid);
823823 void *p = msg->front.iov_base;
824− void *end = p + msg->front_alloc_len;
824+ void *const end = p + msg->front.iov_len;
825825 u64 handle;
826826
827827 dout("%s msg %p tid %llu\n", __func__, msg, tid);
net/ceph/osdmap.c+12−4
@@ -518,6 +518,8 @@ static struct crush_map *crush_decode(void *pbyval, void *end) · 517 unmodified lines
518518 ceph_decode_need(p, end, 4*sizeof(u32), bad);
519519 b->id = ceph_decode_32(p);
520520 b->type = ceph_decode_16(p);
521+ if (b->type == 0)
522+ goto bad;
521523 b->alg = ceph_decode_8(p);
522524 if (b->alg != alg) {
523525 b->alg = 0;
@@ -1436,7 +1438,7 @@ static struct ceph_pg_mapping *__decode_pg_temp(void **p, void *end, · 912 unmodified lines
14361438 ceph_decode_32_safe(p, end, len, e_inval);
14371439 if (len == 0 && incremental)
14381440 return NULL; /* new_pg_temp: [] to remove */
1439− if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / sizeof(u32))
1441+ if (len > CEPH_PG_MAX_SIZE)
14401442 return ERR_PTR(-EINVAL);
14411443
14421444 ceph_decode_need(p, end, len * sizeof(u32), e_inval);
@@ -1617,7 +1619,7 @@ static struct ceph_pg_mapping *__decode_pg_upmap_items(void **p, void *end, · 174 unmodified lines
16171619 u32 len, i;
16181620
16191621 ceph_decode_32_safe(p, end, len, e_inval);
1620− if ((size_t)len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
1622+ if (len > CEPH_PG_MAX_SIZE)
16211623 return ERR_PTR(-EINVAL);
16221624
16231625 ceph_decode_need(p, end, 2 * len * sizeof(u32), e_inval);
@@ -1842,6 +1844,8 @@ static int decode_new_up_state_weight(void **p, void *end, u8 struct_v, · 218 unmodified lines
18421844 void *new_up_client;
18431845 void *new_state;
18441846 void *new_weight_end;
1847+ const u32 new_state_item_size =
1848+ sizeof(u32) + (struct_v >= 5 ? sizeof(u32) : sizeof(u8));
18451849 u32 len;
18461850 int ret;
18471851 int i;
@@ -1862,7 +1866,8 @@ static int decode_new_up_state_weight(void **p, void *end, u8 struct_v, · 14 unmodified lines
18621866
18631867 new_state = *p;
18641868 ceph_decode_32_safe(p, end, len, e_inval);
1865− len *= sizeof(u32) + (struct_v >= 5 ? sizeof(u32) : sizeof(u8));
1869+ if (check_mul_overflow(len, new_state_item_size, &len))
1870+ goto e_inval;
18661871 ceph_decode_need(p, end, len, e_inval);
18671872 *p += len;
18681873
@@ -3055,8 +3060,11 @@ static int get_immediate_parent(struct crush_map *c, int id, · 1186 unmodified lines
30553060 if (b->items[j] != id)
30563061 continue;
30573062
3058− *parent_type_id = b->type;
30593063 type_cn = lookup_crush_name(&c->type_names, b->type);
3064+ if (WARN_ON_ONCE(!type_cn))
3065+ continue;
3066+
3067+ *parent_type_id = b->type;
30603068 parent_loc->cl_type_name = type_cn->cn_name;
30613069 parent_loc->cl_name = cn->cn_name;
30623070 return b->id;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t