Skip to content

Commit ab03778

Browse files
schspadavem330
authored andcommitted
mrp: introduce active flags to prevent UAF when applicant uninit
The caller of del_timer_sync must prevent restarting of the timer, If we have no this synchronization, there is a small probability that the cancellation will not be successful. And syzbot report the fellowing crash: ================================================================== BUG: KASAN: use-after-free in hlist_add_head include/linux/list.h:929 [inline] BUG: KASAN: use-after-free in enqueue_timer+0x18/0xa4 kernel/time/timer.c:605 Write at addr f9ff000024df6058 by task syz-fuzzer/2256 Pointer tag: [f9], memory tag: [fe] CPU: 1 PID: 2256 Comm: syz-fuzzer Not tainted 6.1.0-rc5-syzkaller-00008- ge01d50cbd6ee #0 Hardware name: linux,dummy-virt (DT) Call trace: dump_backtrace.part.0+0xe0/0xf0 arch/arm64/kernel/stacktrace.c:156 dump_backtrace arch/arm64/kernel/stacktrace.c:162 [inline] show_stack+0x18/0x40 arch/arm64/kernel/stacktrace.c:163 __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x68/0x84 lib/dump_stack.c:106 print_address_description mm/kasan/report.c:284 [inline] print_report+0x1a8/0x4a0 mm/kasan/report.c:395 kasan_report+0x94/0xb4 mm/kasan/report.c:495 __do_kernel_fault+0x164/0x1e0 arch/arm64/mm/fault.c:320 do_bad_area arch/arm64/mm/fault.c:473 [inline] do_tag_check_fault+0x78/0x8c arch/arm64/mm/fault.c:749 do_mem_abort+0x44/0x94 arch/arm64/mm/fault.c:825 el1_abort+0x40/0x60 arch/arm64/kernel/entry-common.c:367 el1h_64_sync_handler+0xd8/0xe4 arch/arm64/kernel/entry-common.c:427 el1h_64_sync+0x64/0x68 arch/arm64/kernel/entry.S:576 hlist_add_head include/linux/list.h:929 [inline] enqueue_timer+0x18/0xa4 kernel/time/timer.c:605 mod_timer+0x14/0x20 kernel/time/timer.c:1161 mrp_periodic_timer_arm net/802/mrp.c:614 [inline] mrp_periodic_timer+0xa0/0xc0 net/802/mrp.c:627 call_timer_fn.constprop.0+0x24/0x80 kernel/time/timer.c:1474 expire_timers+0x98/0xc4 kernel/time/timer.c:1519 To fix it, we can introduce a new active flags to make sure the timer will not restart. Reported-by: [email protected] Signed-off-by: Schspa Shi <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8cf4f8c commit ab03778

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

include/net/mrp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ struct mrp_applicant {
124124
struct sk_buff *pdu;
125125
struct rb_root mad;
126126
struct rcu_head rcu;
127+
bool active;
127128
};
128129

129130
struct mrp_port {

net/802/mrp.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,10 @@ static void mrp_join_timer(struct timer_list *t)
606606
spin_unlock(&app->lock);
607607

608608
mrp_queue_xmit(app);
609-
mrp_join_timer_arm(app);
609+
spin_lock(&app->lock);
610+
if (likely(app->active))
611+
mrp_join_timer_arm(app);
612+
spin_unlock(&app->lock);
610613
}
611614

612615
static void mrp_periodic_timer_arm(struct mrp_applicant *app)
@@ -620,11 +623,12 @@ static void mrp_periodic_timer(struct timer_list *t)
620623
struct mrp_applicant *app = from_timer(app, t, periodic_timer);
621624

622625
spin_lock(&app->lock);
623-
mrp_mad_event(app, MRP_EVENT_PERIODIC);
624-
mrp_pdu_queue(app);
626+
if (likely(app->active)) {
627+
mrp_mad_event(app, MRP_EVENT_PERIODIC);
628+
mrp_pdu_queue(app);
629+
mrp_periodic_timer_arm(app);
630+
}
625631
spin_unlock(&app->lock);
626-
627-
mrp_periodic_timer_arm(app);
628632
}
629633

630634
static int mrp_pdu_parse_end_mark(struct sk_buff *skb, int *offset)
@@ -872,6 +876,7 @@ int mrp_init_applicant(struct net_device *dev, struct mrp_application *appl)
872876
app->dev = dev;
873877
app->app = appl;
874878
app->mad = RB_ROOT;
879+
app->active = true;
875880
spin_lock_init(&app->lock);
876881
skb_queue_head_init(&app->queue);
877882
rcu_assign_pointer(dev->mrp_port->applicants[appl->type], app);
@@ -900,6 +905,9 @@ void mrp_uninit_applicant(struct net_device *dev, struct mrp_application *appl)
900905

901906
RCU_INIT_POINTER(port->applicants[appl->type], NULL);
902907

908+
spin_lock_bh(&app->lock);
909+
app->active = false;
910+
spin_unlock_bh(&app->lock);
903911
/* Delete timer and generate a final TX event to flush out
904912
* all pending messages before the applicant is gone.
905913
*/

0 commit comments

Comments
 (0)