]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: fix FP error when calculating enteries per bi shard 53592/head
authorJ. Eric Ivancich <ivancich@redhat.com>
Thu, 5 Jan 2023 18:57:37 +0000 (13:57 -0500)
committerMykola Golub <mgolub@suse.com>
Fri, 22 Sep 2023 06:12:43 +0000 (09:12 +0300)
When calculating how many entries per shard to request during an
ordered bucket listing, we divide by the number of bucket index
shards. If this value is 0, then a floating point exception is
generated, crashing the RGW.

This addresses the proximate issue by detecting the situation and
returning an error rather than crashing.

Signed-off-by: J. Eric Ivancich <ivancich@redhat.com>
(cherry picked from commit bd6ee7e78d857bff31b0bb23f0ee8d8737ffef8e)

Conflicts:
src/rgw/rgw_rados.cc (trivial: __func__ vs __PRETTY_FUNCTION__)

src/rgw/rgw_rados.cc

index 958fe5d4538faec73da0bf44b8d04c92c4049471..2fbe0471d57b638ded8a443bc3c51914495024db 100644 (file)
@@ -8643,9 +8643,16 @@ int RGWRados::cls_obj_set_bucket_tag_timeout(const DoutPrefixProvider *dpp, RGWB
 }
 
 
+// returns 0 if there is an error in calculation
 uint32_t RGWRados::calc_ordered_bucket_list_per_shard(uint32_t num_entries,
                                                      uint32_t num_shards)
 {
+  if (num_shards == 0) {
+    // we'll get a floating point exception since we divide by
+    // num_shards
+    return 0;
+  }
+
   // We want to minimize the chances that when num_shards >>
   // num_entries that we return much fewer than num_entries to the
   // client. Given all the overhead of making a cls call to the osd,
@@ -8723,6 +8730,13 @@ int RGWRados::cls_bucket_list_ordered(const DoutPrefixProvider *dpp,
   }
 
   const uint32_t shard_count = shard_oids.size();
+  if (shard_count == 0) {
+    ldpp_dout(dpp, 0) << "ERROR: " << __func__ <<
+      ": the bucket index shard count appears to be 0, "
+      "which is an illegal value" << dendl;
+    return -ERR_INVALID_BUCKET_STATE;
+  }
+
   uint32_t num_entries_per_shard;
   if (expansion_factor == 0) {
     num_entries_per_shard =
@@ -8737,6 +8751,13 @@ int RGWRados::cls_bucket_list_ordered(const DoutPrefixProvider *dpp,
     num_entries_per_shard = num_entries;
   }
 
+  if (num_entries_per_shard == 0) {
+    ldpp_dout(dpp, 0) << "ERROR: " << __func__ <<
+      ": unable to calculate the number of entries to read from each "
+      "bucket index shard" << dendl;
+    return -ERR_INVALID_BUCKET_STATE;
+  }
+
   ldpp_dout(dpp, 10) << __PRETTY_FUNCTION__ <<
     ": request from each of " << shard_count <<
     " shard(s) for " << num_entries_per_shard << " entries to get " <<