Repository navigation
mruby-task: compare names in C when Task.get walks the queues - #7834
Conversation
Task.get compared each task's name with mrb_equal(), which calls the name's Ruby == for anything but a plain String. Task#name= takes any object, so that == ran in the middle of the queue walk and could close the task under it; the loop then read t->next from the freed mrb_task. Compare with mrb_str_equal() and skip a task whose name is not a String, so no Ruby runs during the walk.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Task.get(mrb_task_s_get) compares each queued task's name withmrb_equal(), which calls the name's Ruby==for anything but a plain String.Task#name=stores any object, so that==runs mid-walk and canclosethe task being looked at;mrb_close_task()frees themrb_taskand the loop then readst->nextfrom freed memory.t = Task.new {}; o = Object.new; def o.==(x) = ($t.close; false); $t = t; t.name = o; Task.get("x"). ASan: heap-use-after-free READ inmrb_task_s_get(task.c:1275), freed bymrb_task_freeviaTask#closefrommrb_equal. A plain full-core build segfaults once Strings allocated in the callback reuse the freed chunk.mrb_str_equal(), skipping a task whose name is not a String, so no Ruby runs during the walk.Task.getonly takes a String, so lookups of String-named tasks are unchanged. The other queue walks intask.c/task_queue.ccall no Ruby.Added a regression test to
mrbgems/mruby-task/test/task.rb: it aborts the clang ASan mrbtest on master and passes with the fix. All seven ci/gcc-clang mrbtest targets and full-debug with-sare KO 0; the one crash in each (test/t/class.rb:536) is pre-existing on master.Summary by CodeRabbit