• Shakeel Butt's avatar
    mm, oom: fix use-after-free in oom_kill_process · 98ea95b8
    Shakeel Butt authored
    commit cefc7ef3 upstream.
    
    Syzbot instance running on upstream kernel found a use-after-free bug in
    oom_kill_process.  On further inspection it seems like the process
    selected to be oom-killed has exited even before reaching
    read_lock(&tasklist_lock) in oom_kill_process().  More specifically the
    tsk->usage is 1 which is due to get_task_struct() in oom_evaluate_task()
    and the put_task_struct within for_each_thread() frees the tsk and
    for_each_thread() tries to access the tsk.  The easiest fix is to do
    get/put across the for_each_thread() on the selected task.
    
    Now the next question is should we continue with the oom-kill as the
    previously selected task has exited? However before adding more
    complexity and heuristics, let's answer why we even look at the children
    of oom-kill selected task? The select_bad_process() has already selected
    the worst process in the system/memcg.  Due to race, the selected
    process might not be the wors...
    98ea95b8
oom_kill.c 20.3 KB