Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net/sched: taprio: fix use-after-free in advance_sched() on schedule switch

In advance_sched(), when should_change_schedules() returns true,
switch_schedules() is called to promote the admin schedule to oper.
switch_schedules() queues the old oper schedule for RCU freeing via
call_rcu(), but 'next' still points into an entry of the old oper
schedule. The subsequent 'next->end_time = end_time' and
rcu_assign_pointer(q->current_entry, next) are use-after-free.

Fix this by selecting 'next' from the new oper schedule immediately
after switch_schedules(), and using its pre-calculated end_time.
setup_first_end_time() sets the first entry's end_time to
base_time + interval when the schedule is installed, so the value
is already correct.

The deleted 'end_time = sched_base_time(admin)' assignment was also
harmful independently: it would overwrite the new first entry's
pre-calculated end_time with just base_time.

Fixes: a3d43c0d56f1 ("taprio: Add support adding an admin schedule")
Reported-by: Junxi Qian <qjx1298677004@gmail.com>
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Vinicius Costa Gomes and committed by
Jakub Kicinski
105425b1 1e9e7fd8

+5 -4
+5 -4
net/sched/sch_taprio.c
··· 972 972 } 973 973 974 974 if (should_change_schedules(admin, oper, end_time)) { 975 - /* Set things so the next time this runs, the new 976 - * schedule runs. 977 - */ 978 - end_time = sched_base_time(admin); 979 975 switch_schedules(q, &admin, &oper); 976 + /* After changing schedules, the next entry is the first one 977 + * in the new schedule, with a pre-calculated end_time. 978 + */ 979 + next = list_first_entry(&oper->entries, struct sched_entry, list); 980 + end_time = next->end_time; 980 981 } 981 982 982 983 next->end_time = end_time;