diff options
author | Xiubo Li <xiubli@redhat.com> | 2023-10-13 13:55:44 +0800 |
---|---|---|
committer | Ilya Dryomov <idryomov@gmail.com> | 2024-02-07 14:43:29 +0100 |
commit | cd7d469c25704d414d71bf3644f163fb74e7996b (patch) | |
tree | 3a5e04cf308920fb9c8fd90c49183e9c1fad4545 /net/ceph | |
parent | 54be6c6c5ae8e0d93a6c4641cb7528eb0b6ba478 (diff) | |
download | linux-cd7d469c25704d414d71bf3644f163fb74e7996b.tar.gz linux-cd7d469c25704d414d71bf3644f163fb74e7996b.tar.bz2 linux-cd7d469c25704d414d71bf3644f163fb74e7996b.zip |
libceph: fail sparse-read if the data length doesn't match
Once this happens that means there have bugs.
Signed-off-by: Xiubo Li <xiubli@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Diffstat (limited to 'net/ceph')
-rw-r--r-- | net/ceph/osd_client.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c index 625622016f57..2cea35e4ff8e 100644 --- a/net/ceph/osd_client.c +++ b/net/ceph/osd_client.c @@ -5857,8 +5857,8 @@ static int osd_sparse_read(struct ceph_connection *con, struct ceph_osd *o = con->private; struct ceph_sparse_read *sr = &o->o_sparse_read; u32 count = sr->sr_count; - u64 eoff, elen; - int ret; + u64 eoff, elen, len = 0; + int i, ret; switch (sr->sr_state) { case CEPH_SPARSE_READ_HDR: @@ -5903,8 +5903,20 @@ next_op: convert_extent_map(sr); ret = sizeof(sr->sr_datalen); *pbuf = (char *)&sr->sr_datalen; - sr->sr_state = CEPH_SPARSE_READ_DATA; + sr->sr_state = CEPH_SPARSE_READ_DATA_PRE; break; + case CEPH_SPARSE_READ_DATA_PRE: + /* Convert sr_datalen to host-endian */ + sr->sr_datalen = le32_to_cpu((__force __le32)sr->sr_datalen); + for (i = 0; i < count; i++) + len += sr->sr_extent[i].len; + if (sr->sr_datalen != len) { + pr_warn_ratelimited("data len %u != extent len %llu\n", + sr->sr_datalen, len); + return -EREMOTEIO; + } + sr->sr_state = CEPH_SPARSE_READ_DATA; + fallthrough; case CEPH_SPARSE_READ_DATA: if (sr->sr_index >= count) { sr->sr_state = CEPH_SPARSE_READ_HDR; |