linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: rose: fix UAF bug caused by rose_t0timer_expiry
@ 2022-06-30 14:38 Duoming Zhou
  2022-06-30 14:44 ` Eric Dumazet
  0 siblings, 1 reply; 7+ messages in thread
From: Duoming Zhou @ 2022-06-30 14:38 UTC (permalink / raw)
  To: linux-hams
  Cc: netdev, linux-kernel, pabeni, kuba, edumazet, davem, ralf, Duoming Zhou

There are UAF bugs caused by rose_t0timer_expiry(). The
root cause is that del_timer() could not stop the timer
handler that is running and there is no synchronization.
One of the race conditions is shown below:

    (thread 1)             |        (thread 2)
                           | rose_device_event
                           |   rose_rt_device_down
                           |     rose_remove_neigh
rose_t0timer_expiry        |       rose_stop_t0timer(rose_neigh)
  ...                      |         del_timer(&neigh->t0timer)
                           |         kfree(rose_neigh) //[1]FREE
  neigh->dce_mode //[2]USE |

The rose_neigh is deallocated in position [1] and use in
position [2].

The crash trace triggered by POC is like below:

BUG: KASAN: use-after-free in expire_timers+0x144/0x320
Write of size 8 at addr ffff888009b19658 by task swapper/0/0
...
Call Trace:
 <IRQ>
 dump_stack_lvl+0xbf/0xee
 print_address_description+0x7b/0x440
 print_report+0x101/0x230
 ? expire_timers+0x144/0x320
 kasan_report+0xed/0x120
 ? expire_timers+0x144/0x320
 expire_timers+0x144/0x320
 __run_timers+0x3ff/0x4d0
 run_timer_softirq+0x41/0x80
 __do_softirq+0x233/0x544
 ...

This patch changes del_timer() in rose_stop_t0timer() and
rose_stop_ftimer() to del_timer_sync() in order that the
timer handler could be finished before the resources such as
rose_neigh and so on are deallocated. As a result, the UAF
bugs could be mitigated.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
---
 net/rose/rose_link.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/rose/rose_link.c b/net/rose/rose_link.c
index 8b96a56d3a4..9734d1264de 100644
--- a/net/rose/rose_link.c
+++ b/net/rose/rose_link.c
@@ -54,12 +54,12 @@ static void rose_start_t0timer(struct rose_neigh *neigh)
 
 void rose_stop_ftimer(struct rose_neigh *neigh)
 {
-	del_timer(&neigh->ftimer);
+	del_timer_sync(&neigh->ftimer);
 }
 
 void rose_stop_t0timer(struct rose_neigh *neigh)
 {
-	del_timer(&neigh->t0timer);
+	del_timer_sync(&neigh->t0timer);
 }
 
 int rose_ftimer_running(struct rose_neigh *neigh)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-07-01  5:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30 14:38 [PATCH net] net: rose: fix UAF bug caused by rose_t0timer_expiry Duoming Zhou
2022-06-30 14:44 ` Eric Dumazet
2022-06-30 15:08   ` duoming
2022-06-30 15:17     ` Eric Dumazet
2022-06-30 15:51       ` duoming
2022-06-30 16:07         ` Eric Dumazet
2022-07-01  5:14           ` duoming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).