Changeset 07d4271 in mainline for kernel/generic/include/proc/task.h


Ignore:
Timestamp:
2024-01-25T16:22:55Z (16 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
f8b69a1e
Parents:
1a1e124
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-25 15:56:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-25 16:22:55)
Message:

Fix some unsound task reference manipulation and locking

In some operations that take task ID as an argument,
there's a possibility of the task being destroyed mid-operation
and a subsequent use-after-free situation.
As a general solution, task_find_by_id() is reimplemented to
check for this situation and always return a valid strong reference.
The callers then only need to handle the reference itself, and
don't need to concern themselves with tasks_lock.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/proc/task.h

    r1a1e124 r07d4271  
    8888
    8989        /** Number of references (i.e. threads). */
    90         atomic_size_t refcount;
     90        atomic_refcount_t refcount;
    9191        /** Number of threads that haven't exited yet. */
    9292        // TODO: remove
     
    144144extern void task_done(void);
    145145extern task_t *task_create(as_t *, const char *);
    146 extern void task_destroy(task_t *);
    147146extern void task_hold(task_t *);
    148147extern void task_release(task_t *);
Note: See TracChangeset for help on using the changeset viewer.