Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use after free in core. #12138

Merged
merged 1 commit into from Nov 13, 2018
Merged

Fix use after free in core. #12138

merged 1 commit into from Nov 13, 2018

Conversation

devnexen
Copy link
Contributor

The tasks are already freed by the reference counting.

@codecov-io
Copy link

Codecov Report

Merging #12138 into master will decrease coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #12138      +/-   ##
==========================================
- Coverage   37.16%   37.15%   -0.01%     
==========================================
  Files         902      902              
  Lines      288475   288475              
==========================================
- Hits       107210   107185      -25     
- Misses     181265   181290      +25
Impacted Files Coverage Δ
libr/core/core.c 39.24% <ø> (-0.03%) ⬇️
libr/core/task.c 36.12% <0%> (-3.3%) ⬇️
libr/util/thread_cond.c 26.31% <0%> (-21.06%) ⬇️
libr/util/thread_sem.c 0% <0%> (-12.5%) ⬇️
libr/util/thread.c 10.98% <0%> (-3.3%) ⬇️
libr/cons/cons.c 56.67% <0%> (-0.36%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a4ddb43...91a6041. Read the comment docs.

@radare radare closed this Nov 13, 2018
@radare radare reopened this Nov 13, 2018
@radare
Copy link
Collaborator

radare commented Nov 13, 2018

Cc @thestr4ng3r

libr/core/task.c Outdated
@@ -182,6 +182,7 @@ static void task_free (RCoreTask *task) {
r_th_lock_free (task->dispatch_lock);
r_cons_context_free (task->cons_context);
free (task);
task = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of setting the parameter to NULL?

libr/core/core.c Outdated
@@ -2450,7 +2450,6 @@ R_API RCore *r_core_fini(RCore *c) {
r_list_free (c->files);
r_list_free (c->watchers);
r_list_free (c->scriptstack);
r_list_free (c->tasks);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The free function saved in core->tasks is r_core_task_decref, freeing the list should just decrease the refcount for each task as you would expect. If this leads to a uaf in some case, the problem is somewhere else, maybe somewhere the refcount is not increased where it should. If you have a case where this happens, please elaborate.

Also, you still have to free the RList itself or it will leak.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you re right this was the wrong approach but there is genuinely an UAF case. With the other diff you can see why there is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are absolutely right. Thanks for noticing, the fix is now correct.

@radare radare merged commit 5783cf4 into radareorg:master Nov 13, 2018
@devnexen devnexen deleted the core_task_use_after_free_fix branch November 30, 2018 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants