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()
Unified · Split
| @@ -1950,9 +1950,14 @@ static int rbd_object_map_update_finish(struct rbd_obj_request *obj_req, · 1949 unmodified lines | |||
| 1950 | bool has_current_state; | 1950 | bool has_current_state; |
| 1951 | void *p; | 1951 | void *p; |
| 1952 | 1952 | ||
| 1953 | if (osd_req->r_result) | 1953 | if (osd_req->r_result < 0) |
| 1954 | return osd_req->r_result; | 1954 | return osd_req->r_result; |
| 1955 | 1955 | ||
| 1956 | /* | ||
| 1957 | * Writes aren't allowed to return a data payload. | ||
| 1958 | */ | ||
| 1959 | WARN_ON_ONCE(osd_req->r_result > 0); | ||
| 1960 | |||
| 1956 | /* | 1961 | /* |
| 1957 | * Nothing to do for a snapshot object map. | 1962 | * Nothing to do for a snapshot object map. |
| 1958 | */ | 1963 | */ |
| @@ -790,6 +790,9 @@ static int write_folio_nounlock(struct folio *folio, · 789 unmodified lines | |||
| 790 | ceph_wbc.truncate_size, true); | 790 | ceph_wbc.truncate_size, true); |
| 791 | if (IS_ERR(req)) { | 791 | if (IS_ERR(req)) { |
| 792 | folio_redirty_for_writepage(wbc, folio); | 792 | 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; | ||
| 793 | return PTR_ERR(req); | 796 | return PTR_ERR(req); |
| 794 | } | 797 | } |
| 795 | 798 | ||
| @@ -809,6 +812,9 @@ static int write_folio_nounlock(struct folio *folio, · 13 unmodified lines | |||
| 809 | folio_redirty_for_writepage(wbc, folio); | 812 | folio_redirty_for_writepage(wbc, folio); |
| 810 | folio_end_writeback(folio); | 813 | folio_end_writeback(folio); |
| 811 | ceph_osdc_put_request(req); | 814 | 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; | ||
| 812 | return PTR_ERR(bounce_page); | 818 | return PTR_ERR(bounce_page); |
| 813 | } | 819 | } |
| 814 | } | 820 | } |
| @@ -847,6 +853,9 @@ static int write_folio_nounlock(struct folio *folio, · 32 unmodified lines | |||
| 847 | ceph_vinop(inode), folio); | 853 | ceph_vinop(inode), folio); |
| 848 | folio_redirty_for_writepage(wbc, folio); | 854 | folio_redirty_for_writepage(wbc, folio); |
| 849 | folio_end_writeback(folio); | 855 | 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; | ||
| 850 | return err; | 859 | return err; |
| 851 | } | 860 | } |
| 852 | if (err == -EBLOCKLISTED) | 861 | if (err == -EBLOCKLISTED) |
| @@ -3094,7 +3094,19 @@ int __ceph_get_caps(struct inode *inode, struct ceph_file_info *fi, int need, · 3093 unmodified lines | |||
| 3094 | ret = -ERESTARTSYS; | 3094 | ret = -ERESTARTSYS; |
| 3095 | break; | 3095 | break; |
| 3096 | } | 3096 | } |
| 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 | } | ||
| 3098 | } | 3110 | } |
| 3099 | 3111 | ||
| 3100 | remove_wait_queue(&ci->i_cap_wq, &wait); | 3112 | 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 | |||
| 3128 | continue; | 3140 | continue; |
| 3129 | } | 3141 | } |
| 3130 | if (ret == -EUCLEAN) { | 3142 | if (ret == -EUCLEAN) { |
| 3131 | /* session was killed, try renew caps */ | 3143 | /* session was killed or a waited cap |
| 3144 | * request needs a retry */ | ||
| 3132 | ret = ceph_renew_caps(inode, flags); | 3145 | ret = ceph_renew_caps(inode, flags); |
| 3133 | if (ret == 0) | 3146 | if (ret == 0) |
| 3134 | continue; | 3147 | continue; |
| @@ -4375,6 +4388,7 @@ void ceph_handle_caps(struct ceph_mds_session *session, · 1240 unmodified lines | |||
| 4375 | 4388 | ||
| 4376 | snaptrace = h + 1; | 4389 | snaptrace = h + 1; |
| 4377 | snaptrace_len = le32_to_cpu(h->snap_trace_len); | 4390 | snaptrace_len = le32_to_cpu(h->snap_trace_len); |
| 4391 | ceph_decode_need(&snaptrace, end, snaptrace_len, bad); | ||
| 4378 | p = snaptrace + snaptrace_len; | 4392 | p = snaptrace + snaptrace_len; |
| 4379 | 4393 | ||
| 4380 | if (msg_version >= 2) { | 4394 | if (msg_version >= 2) { |
| @@ -546,11 +546,16 @@ more: · 545 unmodified lines | |||
| 546 | pr_warn_client(cl, | 546 | pr_warn_client(cl, |
| 547 | "%p %llx.%llx rde->offset 0x%llx ctx->pos 0x%llx\n", | 547 | "%p %llx.%llx rde->offset 0x%llx ctx->pos 0x%llx\n", |
| 548 | inode, ceph_vinop(inode), rde->offset, ctx->pos); | 548 | inode, ceph_vinop(inode), rde->offset, ctx->pos); |
| 549 | ceph_mdsc_put_request(dfi->last_readdir); | ||
| 550 | dfi->last_readdir = NULL; | ||
| 549 | return -EIO; | 551 | return -EIO; |
| 550 | } | 552 | } |
| 551 | 553 | ||
| 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; | ||
| 553 | return -EIO; | 557 | return -EIO; |
| 558 | } | ||
| 554 | 559 | ||
| 555 | ctx->pos = rde->offset; | 560 | ctx->pos = rde->offset; |
| 556 | doutc(cl, "%p %llx.%llx (%d/%d) -> %llx '%.*s' %p\n", inode, | 561 | doutc(cl, "%p %llx.%llx (%d/%d) -> %llx '%.*s' %p\n", inode, |
| @@ -314,7 +314,7 @@ static int ceph_init_file(struct inode *inode, struct file *file, int fmode) · 313 unmodified lines | |||
| 314 | } | 314 | } |
| 315 | 315 | ||
| 316 | /* | 316 | /* |
| 317 | * try renew caps after session gets killed. | 317 | * Retry cap acquisition after a stale session or a lost cap update. |
| 318 | */ | 318 | */ |
| 319 | int ceph_renew_caps(struct inode *inode, int fmode) | 319 | int ceph_renew_caps(struct inode *inode, int fmode) |
| 320 | { | 320 | { |
| @@ -322,14 +322,15 @@ int ceph_renew_caps(struct inode *inode, int fmode) · 1 unmodified line | |||
| 322 | struct ceph_client *cl = mdsc->fsc->client; | 322 | struct ceph_client *cl = mdsc->fsc->client; |
| 323 | struct ceph_inode_info *ci = ceph_inode(inode); | 323 | struct ceph_inode_info *ci = ceph_inode(inode); |
| 324 | struct ceph_mds_request *req; | 324 | struct ceph_mds_request *req; |
| 325 | int err, flags, wanted; | 325 | int err, flags, wanted, issued; |
| 326 | 326 | ||
| 327 | spin_lock(&ci->i_ceph_lock); | 327 | spin_lock(&ci->i_ceph_lock); |
| 328 | __ceph_touch_fmode(ci, mdsc, fmode); | 328 | __ceph_touch_fmode(ci, mdsc, fmode); |
| 329 | wanted = __ceph_caps_file_wanted(ci); | 329 | wanted = __ceph_caps_file_wanted(ci); |
| 330 | issued = __ceph_caps_issued(ci, NULL); | ||
| 330 | if (__ceph_is_any_real_caps(ci) && | 331 | if (__ceph_is_any_real_caps(ci) && |
| 331 | (!(wanted & CEPH_CAP_ANY_WR) || ci->i_auth_cap)) { | 332 | (!(wanted & CEPH_CAP_ANY_WR) || ci->i_auth_cap) && |
| 332 | int issued = __ceph_caps_issued(ci, NULL); | 333 | (issued & wanted) == wanted) { |
| 333 | spin_unlock(&ci->i_ceph_lock); | 334 | spin_unlock(&ci->i_ceph_lock); |
| 334 | doutc(cl, "%p %llx.%llx want %s issued %s updating mds_wanted\n", | 335 | doutc(cl, "%p %llx.%llx want %s issued %s updating mds_wanted\n", |
| 335 | inode, ceph_vinop(inode), ceph_cap_string(wanted), | 336 | inode, ceph_vinop(inode), ceph_cap_string(wanted), |
| @@ -72,6 +72,9 @@ static long ceph_ioctl_set_layout(struct file *file, void __user *arg) · 71 unmodified lines | |||
| 72 | struct ceph_ioctl_layout nl; | 72 | struct ceph_ioctl_layout nl; |
| 73 | int err; | 73 | int err; |
| 74 | 74 | ||
| 75 | if (!inode_owner_or_capable(&nop_mnt_idmap, inode)) | ||
| 76 | return -EACCES; | ||
| 77 | |||
| 75 | if (copy_from_user(&l, arg, sizeof(l))) | 78 | if (copy_from_user(&l, arg, sizeof(l))) |
| 76 | return -EFAULT; | 79 | return -EFAULT; |
| 77 | 80 | ||
| @@ -142,6 +145,9 @@ static long ceph_ioctl_set_layout_policy (struct file *file, void __user *arg) · 64 unmodified lines | |||
| 142 | int err; | 145 | int err; |
| 143 | struct ceph_mds_client *mdsc = ceph_sb_to_fs_client(inode->i_sb)->mdsc; | 146 | struct ceph_mds_client *mdsc = ceph_sb_to_fs_client(inode->i_sb)->mdsc; |
| 144 | 147 | ||
| 148 | if (!inode_owner_or_capable(&nop_mnt_idmap, inode)) | ||
| 149 | return -EACCES; | ||
| 150 | |||
| 145 | /* copy and validate */ | 151 | /* copy and validate */ |
| 146 | if (copy_from_user(&l, arg, sizeof(l))) | 152 | if (copy_from_user(&l, arg, sizeof(l))) |
| 147 | return -EFAULT; | 153 | return -EFAULT; |
| @@ -6,6 +6,7 @@ · 5 unmodified lines | |||
| 6 | #include <linux/slab.h> | 6 | #include <linux/slab.h> |
| 7 | #include <linux/gfp.h> | 7 | #include <linux/gfp.h> |
| 8 | #include <linux/sched.h> | 8 | #include <linux/sched.h> |
| 9 | #include <linux/sched/mm.h> | ||
| 9 | #include <linux/delay.h> | 10 | #include <linux/delay.h> |
| 10 | #include <linux/debugfs.h> | 11 | #include <linux/debugfs.h> |
| 11 | #include <linux/seq_file.h> | 12 | #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 | |||
| 4015 | struct ceph_mds_reply_head *head = msg->front.iov_base; | 4016 | struct ceph_mds_reply_head *head = msg->front.iov_base; |
| 4016 | struct ceph_mds_reply_info_parsed *rinfo; /* parsed reply info */ | 4017 | struct ceph_mds_reply_info_parsed *rinfo; /* parsed reply info */ |
| 4017 | struct ceph_snap_realm *realm; | 4018 | struct ceph_snap_realm *realm; |
| 4019 | unsigned int nofs_flags; | ||
| 4018 | u64 tid; | 4020 | u64 tid; |
| 4019 | int err, result; | 4021 | int err, result; |
| 4020 | int mds = session->s_mds; | 4022 | 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 | |||
| 4158 | 4160 | ||
| 4159 | /* insert trace into our cache */ | 4161 | /* insert trace into our cache */ |
| 4160 | mutex_lock(&req->r_fill_mutex); | 4162 | 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 | |||
| 4161 | current->journal_info = req; | 4171 | current->journal_info = req; |
| 4162 | err = ceph_fill_trace(mdsc->fsc->sb, req); | 4172 | err = ceph_fill_trace(mdsc->fsc->sb, req); |
| 4163 | if (err == 0) { | 4173 | if (err == 0) { |
| @@ -4166,6 +4176,7 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg) · 2 unmodified lines | |||
| 4166 | err = ceph_readdir_prepopulate(req, req->r_session); | 4176 | err = ceph_readdir_prepopulate(req, req->r_session); |
| 4167 | } | 4177 | } |
| 4168 | current->journal_info = NULL; | 4178 | current->journal_info = NULL; |
| 4179 | memalloc_nofs_restore(nofs_flags); | ||
| 4169 | mutex_unlock(&req->r_fill_mutex); | 4180 | mutex_unlock(&req->r_fill_mutex); |
| 4170 | 4181 | ||
| 4171 | up_read(&mdsc->snap_rwsem); | 4182 | up_read(&mdsc->snap_rwsem); |
| @@ -77,6 +77,7 @@ struct ceph_fs_client; · 76 unmodified lines | |||
| 77 | struct ceph_cap; | 77 | struct ceph_cap; |
| 78 | 78 | ||
| 79 | #define MDS_AUTH_UID_ANY -1 | 79 | #define MDS_AUTH_UID_ANY -1 |
| 80 | #define CEPH_GET_CAPS_WAIT_TIMEOUT (5 * HZ) | ||
| 80 | #define CEPH_CAP_FLUSH_WAIT_TIMEOUT_SEC 60 | 81 | #define CEPH_CAP_FLUSH_WAIT_TIMEOUT_SEC 60 |
| 81 | #define CEPH_CAP_FLUSH_MAX_DUMP_ENTRIES 5 | 82 | #define CEPH_CAP_FLUSH_MAX_DUMP_ENTRIES 5 |
| 82 | #define CEPH_CAP_FLUSH_MAX_DUMP_ITERS 5 | 83 | #define CEPH_CAP_FLUSH_MAX_DUMP_ITERS 5 |
| @@ -849,9 +849,16 @@ static int ceph_x_update_authorizer( · 848 unmodified lines | |||
| 849 | 849 | ||
| 850 | au = (struct ceph_x_authorizer *)auth->authorizer; | 850 | au = (struct ceph_x_authorizer *)auth->authorizer; |
| 851 | if (au->secret_id < th->secret_id) { | 851 | if (au->secret_id < th->secret_id) { |
| 852 | int ret; | ||
| 853 | |||
| 852 | dout("ceph_x_update_authorizer service %u secret %llu < %llu\n", | 854 | dout("ceph_x_update_authorizer service %u secret %llu < %llu\n", |
| 853 | au->service, au->secret_id, th->secret_id); | 855 | 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; | ||
| 855 | } | 862 | } |
| 856 | return 0; | 863 | return 0; |
| 857 | } | 864 | } |
| @@ -762,13 +762,13 @@ void ceph_destroy_client(struct ceph_client *client) · 761 unmodified lines | |||
| 762 | 762 | ||
| 763 | atomic_set(&client->msgr.stopping, 1); | 763 | atomic_set(&client->msgr.stopping, 1); |
| 764 | 764 | ||
| 765 | ceph_debugfs_client_cleanup(client); | ||
| 766 | |||
| 765 | /* unmount */ | 767 | /* unmount */ |
| 766 | ceph_osdc_stop(&client->osdc); | 768 | ceph_osdc_stop(&client->osdc); |
| 767 | ceph_monc_stop(&client->monc); | 769 | ceph_monc_stop(&client->monc); |
| 768 | ceph_messenger_fini(&client->msgr); | 770 | ceph_messenger_fini(&client->msgr); |
| 769 | 771 | ||
| 770 | ceph_debugfs_client_cleanup(client); | ||
| 771 | |||
| 772 | ceph_destroy_options(client->options); | 772 | ceph_destroy_options(client->options); |
| 773 | 773 | ||
| 774 | kfree(client); | 774 | kfree(client); |
| @@ -299,7 +299,7 @@ static int decode_lockers(void **p, void *end, u8 *type, char **tag, · 298 unmodified lines | |||
| 299 | if (ret) | 299 | if (ret) |
| 300 | return ret; | 300 | return ret; |
| 301 | 301 | ||
| 302 | *num_lockers = ceph_decode_32(p); | 302 | ceph_decode_32_safe(p, end, *num_lockers, err_inval); |
| 303 | *lockers = kzalloc_objs(**lockers, *num_lockers, GFP_NOIO); | 303 | *lockers = kzalloc_objs(**lockers, *num_lockers, GFP_NOIO); |
| 304 | if (!*lockers) | 304 | if (!*lockers) |
| 305 | return -ENOMEM; | 305 | return -ENOMEM; |
| @@ -310,7 +310,8 @@ static int decode_lockers(void **p, void *end, u8 *type, char **tag, · 4 unmodified lines | |||
| 310 | goto err_free_lockers; | 310 | goto err_free_lockers; |
| 311 | } | 311 | } |
| 312 | 312 | ||
| 313 | *type = ceph_decode_8(p); | 313 | ret = -EINVAL; |
| 314 | ceph_decode_8_safe(p, end, *type, err_free_lockers); | ||
| 314 | s = ceph_extract_encoded_string(p, end, NULL, GFP_NOIO); | 315 | s = ceph_extract_encoded_string(p, end, NULL, GFP_NOIO); |
| 315 | if (IS_ERR(s)) { | 316 | if (IS_ERR(s)) { |
| 316 | ret = PTR_ERR(s); | 317 | ret = PTR_ERR(s); |
| @@ -320,6 +321,9 @@ static int decode_lockers(void **p, void *end, u8 *type, char **tag, · 3 unmodified lines | |||
| 320 | *tag = s; | 321 | *tag = s; |
| 321 | return 0; | 322 | return 0; |
| 322 | 323 | ||
| 324 | err_inval: | ||
| 325 | return -EINVAL; | ||
| 326 | |||
| 323 | err_free_lockers: | 327 | err_free_lockers: |
| 324 | ceph_free_lockers(*lockers, *num_lockers); | 328 | ceph_free_lockers(*lockers, *num_lockers); |
| 325 | return ret; | 329 | return ret; |
| @@ -114,7 +114,7 @@ static struct ceph_monmap *ceph_monmap_decode(void **p, void *end, bool msgr2) · 113 unmodified lines | |||
| 114 | 114 | ||
| 115 | dout("%s fsid %pU epoch %u num_mon %u\n", __func__, &fsid, epoch, | 115 | dout("%s fsid %pU epoch %u num_mon %u\n", __func__, &fsid, epoch, |
| 116 | num_mon); | 116 | num_mon); |
| 117 | if (num_mon > CEPH_MAX_MON) | 117 | if (num_mon == 0 || num_mon > CEPH_MAX_MON) |
| 118 | goto e_inval; | 118 | goto e_inval; |
| 119 | 119 | ||
| 120 | monmap = kmalloc_flex(*monmap, mon_inst, num_mon, GFP_NOIO); | 120 | 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 | |||
| 821 | struct ceph_mon_generic_request *req; | 821 | struct ceph_mon_generic_request *req; |
| 822 | u64 tid = le64_to_cpu(msg->hdr.tid); | 822 | u64 tid = le64_to_cpu(msg->hdr.tid); |
| 823 | void *p = msg->front.iov_base; | 823 | void *p = msg->front.iov_base; |
| 824 | void *end = p + msg->front_alloc_len; | 824 | void *const end = p + msg->front.iov_len; |
| 825 | u64 handle; | 825 | u64 handle; |
| 826 | 826 | ||
| 827 | dout("%s msg %p tid %llu\n", __func__, msg, tid); | 827 | dout("%s msg %p tid %llu\n", __func__, msg, tid); |
| @@ -518,6 +518,8 @@ static struct crush_map *crush_decode(void *pbyval, void *end) · 517 unmodified lines | |||
| 518 | ceph_decode_need(p, end, 4*sizeof(u32), bad); | 518 | ceph_decode_need(p, end, 4*sizeof(u32), bad); |
| 519 | b->id = ceph_decode_32(p); | 519 | b->id = ceph_decode_32(p); |
| 520 | b->type = ceph_decode_16(p); | 520 | b->type = ceph_decode_16(p); |
| 521 | if (b->type == 0) | ||
| 522 | goto bad; | ||
| 521 | b->alg = ceph_decode_8(p); | 523 | b->alg = ceph_decode_8(p); |
| 522 | if (b->alg != alg) { | 524 | if (b->alg != alg) { |
| 523 | b->alg = 0; | 525 | b->alg = 0; |
| @@ -1436,7 +1438,7 @@ static struct ceph_pg_mapping *__decode_pg_temp(void **p, void *end, · 912 unmodified lines | |||
| 1436 | ceph_decode_32_safe(p, end, len, e_inval); | 1438 | ceph_decode_32_safe(p, end, len, e_inval); |
| 1437 | if (len == 0 && incremental) | 1439 | if (len == 0 && incremental) |
| 1438 | return NULL; /* new_pg_temp: [] to remove */ | 1440 | 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) |
| 1440 | return ERR_PTR(-EINVAL); | 1442 | return ERR_PTR(-EINVAL); |
| 1441 | 1443 | ||
| 1442 | ceph_decode_need(p, end, len * sizeof(u32), e_inval); | 1444 | 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 | |||
| 1617 | u32 len, i; | 1619 | u32 len, i; |
| 1618 | 1620 | ||
| 1619 | ceph_decode_32_safe(p, end, len, e_inval); | 1621 | 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) |
| 1621 | return ERR_PTR(-EINVAL); | 1623 | return ERR_PTR(-EINVAL); |
| 1622 | 1624 | ||
| 1623 | ceph_decode_need(p, end, 2 * len * sizeof(u32), e_inval); | 1625 | 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 | |||
| 1842 | void *new_up_client; | 1844 | void *new_up_client; |
| 1843 | void *new_state; | 1845 | void *new_state; |
| 1844 | void *new_weight_end; | 1846 | void *new_weight_end; |
| 1847 | const u32 new_state_item_size = | ||
| 1848 | sizeof(u32) + (struct_v >= 5 ? sizeof(u32) : sizeof(u8)); | ||
| 1845 | u32 len; | 1849 | u32 len; |
| 1846 | int ret; | 1850 | int ret; |
| 1847 | int i; | 1851 | int i; |
| @@ -1862,7 +1866,8 @@ static int decode_new_up_state_weight(void **p, void *end, u8 struct_v, · 14 unmodified lines | |||
| 1862 | 1866 | ||
| 1863 | new_state = *p; | 1867 | new_state = *p; |
| 1864 | ceph_decode_32_safe(p, end, len, e_inval); | 1868 | 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; | ||
| 1866 | ceph_decode_need(p, end, len, e_inval); | 1871 | ceph_decode_need(p, end, len, e_inval); |
| 1867 | *p += len; | 1872 | *p += len; |
| 1868 | 1873 | ||
| @@ -3055,8 +3060,11 @@ static int get_immediate_parent(struct crush_map *c, int id, · 1186 unmodified lines | |||
| 3055 | if (b->items[j] != id) | 3060 | if (b->items[j] != id) |
| 3056 | continue; | 3061 | continue; |
| 3057 | 3062 | ||
| 3058 | *parent_type_id = b->type; | ||
| 3059 | type_cn = lookup_crush_name(&c->type_names, b->type); | 3063 | 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; | ||
| 3060 | parent_loc->cl_type_name = type_cn->cn_name; | 3068 | parent_loc->cl_type_name = type_cn->cn_name; |
| 3061 | parent_loc->cl_name = cn->cn_name; | 3069 | parent_loc->cl_name = cn->cn_name; |
| 3062 | return b->id; | 3070 | return b->id; |