[COMMIT seastar master] reactor: destroy_scheduling_group: make sure scheduling_group is valid

Skip to first unread message

Commit Bot

Oct 6, 2022, 10:17:01 AM10/6/22
to seastar-dev@googlegroups.com, Benny Halevy
From: Benny Halevy <bha...@scylladb.com>
Committer: Avi Kivity <a...@scylladb.com>
Branch: master

reactor: destroy_scheduling_group: make sure scheduling_group is valid

When called with an invalid sg (e.g. a previously destroyed one)
with_scheduling_group segfaults when dereferencing _task_queues[sg._id]
which is nullified by destroy_scheduling_group.

To prevent that, verify first the the sg is valid, and
abort if it isn't.

While at it, also mark the method noexcept.

Signed-off-by: Benny Halevy <bha...@scylladb.com>

diff --git a/include/seastar/core/reactor.hh b/include/seastar/core/reactor.hh
--- a/include/seastar/core/reactor.hh
+++ b/include/seastar/core/reactor.hh
@@ -431,7 +431,7 @@ private:
void allocate_scheduling_group_specific_data(scheduling_group sg, scheduling_group_key key);
future<> init_scheduling_group(scheduling_group sg, sstring name, float shares);
future<> init_new_scheduling_group_key(scheduling_group_key key, scheduling_group_key_config cfg);
- future<> destroy_scheduling_group(scheduling_group sg);
+ future<> destroy_scheduling_group(scheduling_group sg) noexcept;
uint64_t tasks_processed() const;
uint64_t min_vruntime() const;
void request_preemption();
diff --git a/src/core/reactor.cc b/src/core/reactor.cc
--- a/src/core/reactor.cc
+++ b/src/core/reactor.cc
@@ -4444,7 +4444,10 @@ reactor::init_new_scheduling_group_key(scheduling_group_key key, scheduling_grou

-reactor::destroy_scheduling_group(scheduling_group sg) {
+reactor::destroy_scheduling_group(scheduling_group sg) noexcept {
+ if (sg._id >= max_scheduling_groups()) {
+ on_fatal_internal_error(seastar_logger, format("Invalid scheduling_group {}", sg._id));
+ }
return with_scheduling_group(sg, [this, sg] () {
auto& sg_data = _scheduling_group_specific_data;
auto& this_sg = sg_data.per_scheduling_group_data[sg._id];
Reply all
Reply to author
0 new messages