• Duoming Zhou's avatar
    net: rose: fix UAF bugs caused by timer handler · 9cc02ede
    Duoming Zhou authored
    There are UAF bugs in rose_heartbeat_expiry(), rose_timer_expiry()
    and rose_idletimer_expiry(). The root cause is that del_timer()
    could not stop the timer handler that is running and the refcount
    of sock is not managed properly.
    
    One of the UAF bugs is shown below:
    
        (thread 1)          |        (thread 2)
                            |  rose_bind
                            |  rose_connect
                            |    rose_start_heartbeat
    rose_release            |    (wait a time)
      case ROSE_STATE_0     |
      rose_destroy_socket   |  rose_heartbeat_expiry
        rose_stop_heartbeat |
        sock_put(sk)        |    ...
      sock_put(sk) // FREE  |
                            |    bh_lock_sock(sk) // USE
    
    The sock is deallocated by sock_put() in rose_release() and
    then used by bh_lock_sock() in rose_heartbeat_expiry().
    
    Although rose_destroy_socket() calls rose_stop_heartbeat(),
    it could not stop the timer that is running.
    
    The KASAN report triggered by POC is shown below:
    
    BU...
    9cc02ede
rose_timer.c 4.81 KB