From 028ff9323056d9336d18ced54fed1642b73d7fe2 Mon Sep 17 00:00:00 2001 From: F6BVP Date: Thu, 10 Sep 2026 15:35:58 +0200 Subject: [PATCH] rose: use timer_shutdown_sync() for t0timer teardown rose_t0timer_expiry() re-arms itself via rose_start_t0timer() at its own tail. rose_neigh_put() and rose_remove_neigh() stop it with timer_delete_sync() before freeing (or unlinking) the neighbour, but that only guarantees the callback is not running *at the moment the call returns* -- it does nothing to stop the very invocation that was just waited out from re-arming the timer on its way out. That re-arm races the kfree() in rose_neigh_put(): the timer can fire again on freed memory, and rose_t0timer_expiry() -> rose_transmit_restart_request() -> rose_send_frame() -> ax25_send_frame() dereferences the freed neigh->digipeat, use-after-free. This matches a syzbot report (KASAN slab-use-after-free read in ax25_find_cb()) that stayed open with both cause and fix bisection failing -- consistent with a hole that timer_delete_sync() alone cannot close for a self-rearming timer, a case documented in its own kerneldoc ("there is no way to get this correct with timer_delete_sync()"). Use timer_shutdown_sync() instead in both call sites. Unlike timer_delete_sync(), it also marks the timer so that any further add_timer()/mod_timer() on it is silently ignored, which closes the window regardless of how the self-rearm and the free are interleaved. ftimer's handler is a no-op and never re-arms, but it is switched the same way for consistency: both timers are being torn down for good in both of these call sites. Reported-by: syzbot+caa052a0958a9146870d@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=caa052a0958a9146870d Signed-off-by: Bernard Pidoux --- include/net/rose.h | 28 ++++++++++++++++++---------- net/rose/rose_route.c | 10 ++++++++-- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/include/net/rose.h b/include/net/rose.h index 95d1f9c..0d957b8 100644 --- a/include/net/rose.h +++ b/include/net/rose.h @@ -161,17 +161,25 @@ static inline void rose_neigh_put(struct rose_neigh *rose_neigh) { if (refcount_dec_and_test(&rose_neigh->use)) { /* We are dropping the last reference, so we are about to free the - * neighbour. Its timers may still be armed -- t0timer in particular - * re-arms itself in rose_t0timer_expiry(). rose_remove_neigh() - * cancels them before its own put, but callers that drop the final - * reference without first calling rose_remove_neigh() (the socket - * heartbeat reaping path) would otherwise kfree() a neighbour with a - * live timer -> use-after-free. timer_delete_sync() (not the async - * variant) is required: it waits out a concurrently running handler - * and loops until the self-rearming timer stays stopped. + * neighbour. t0timer is self-rearming: rose_t0timer_expiry() calls + * rose_start_t0timer() at its own tail, so a plain timer_delete_sync() + * is not enough here. It only guarantees that the callback is not + * running *at the moment it returns* -- it does nothing to stop the + * very invocation we just waited out from re-arming the timer on its + * way out, which races the kfree() below (syzbot: use-after-free read + * in ax25_find_cb(), reached via rose_t0timer_expiry() -> + * rose_transmit_restart_request() -> rose_send_frame() -> + * ax25_send_frame(), dereferencing the freed neigh->digipeat). + * timer_shutdown_sync() closes that hole: once it returns, any + * further add_timer()/mod_timer() on this timer is silently ignored, + * so a self-rearm racing the free can no longer bring the timer back + * to life on freed memory. ftimer's handler is a no-op and never + * re-arms, but it is shut down the same way here for consistency -- + * this is final teardown, neither timer has any business firing + * again. */ - timer_delete_sync(&rose_neigh->ftimer); - timer_delete_sync(&rose_neigh->t0timer); + timer_shutdown_sync(&rose_neigh->ftimer); + timer_shutdown_sync(&rose_neigh->t0timer); if (rose_neigh->ax25) ax25_cb_put(rose_neigh->ax25); kfree(rose_neigh->digipeat); diff --git a/net/rose/rose_route.c b/net/rose/rose_route.c index e31842e..73bbbc4 100644 --- a/net/rose/rose_route.c +++ b/net/rose/rose_route.c @@ -229,8 +229,14 @@ static void rose_remove_neigh(struct rose_neigh *rose_neigh) { struct rose_neigh *s; - timer_delete_sync(&rose_neigh->ftimer); - timer_delete_sync(&rose_neigh->t0timer); + /* Being removed from the list is final teardown for this neighbour: + * shut the timers down rather than just deleting them, so a t0timer + * self-rearm losing the race with this removal can't bring it back to + * life later. See the comment in rose_neigh_put() (include/net/rose.h) + * for the full story. + */ + timer_shutdown_sync(&rose_neigh->ftimer); + timer_shutdown_sync(&rose_neigh->t0timer); skb_queue_purge(&rose_neigh->queue);