Commit 49b3378
committed
sched_ext: Fix premature ops->priv publication in scx_alloc_and_add_sched()
scx_alloc_and_add_sched() publishes @sch through ops->priv before allocating
the cgroup path. If that allocation fails, the unwind path clears ops->priv
and frees @sch immediately. scx_prog_sched() callers can dereference
ops->priv from RCU context the moment it is set, so freeing without a grace
period can use-after-free a concurrent kfunc caller.
Move the publication below the cgroup path allocation so that every failure
path after publication frees @sch through kobject_put(), whose release path
defers the freeing by a grace period.
Fixes: 105dcd0 ("sched_ext: Introduce scx_prog_sched()")
Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Andrea Righi <arighi@nvidia.com>1 parent db4e9de commit 49b3378
1 file changed
Lines changed: 12 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6878 | 6878 | | |
6879 | 6879 | | |
6880 | 6880 | | |
6881 | | - | |
6882 | | - | |
6883 | | - | |
6884 | | - | |
6885 | | - | |
6886 | 6881 | | |
6887 | 6882 | | |
6888 | 6883 | | |
| |||
6900 | 6895 | | |
6901 | 6896 | | |
6902 | 6897 | | |
| 6898 | + | |
6903 | 6899 | | |
| 6900 | + | |
| 6901 | + | |
| 6902 | + | |
| 6903 | + | |
| 6904 | + | |
| 6905 | + | |
| 6906 | + | |
| 6907 | + | |
| 6908 | + | |
| 6909 | + | |
| 6910 | + | |
6904 | 6911 | | |
6905 | 6912 | | |
6906 | 6913 | | |
| |||
6955 | 6962 | | |
6956 | 6963 | | |
6957 | 6964 | | |
6958 | | - | |
6959 | 6965 | | |
6960 | 6966 | | |
6961 | 6967 | | |
| |||
0 commit comments