• Nayuta Yanagisawa's avatar
    MDEV-28352 Spider: heap-use-after-free in ha_spider::lock_tables(), heap freed by spider_commit() · a26700cc
    Nayuta Yanagisawa authored
    The heap-use-after-free is caused by the following mechanism:
    
      * In the execution of FLUSH TABLE WITH READ LOCK, the function
        spider_free_trx_conn() is called and the connections held by
        SPIDER_TRX::trx_conn_hash are freed.
    
      * Then, an instance of ha_spider maintains the freed connections
        because they are also referenced from ha_spider::conns.
        The ha_spider instance is kept in a lock structure until the
        corresponding table is unlocked.
    
      * Spider accesses ha_spider::conns on the implicit UNLOCK TABLE
        issued by BEGIN.
    
    In the first place, when the connections have been freed, it means
    that there are really no remote table locked by Spider.
    Thus, there is no need for Spider to access ha_spider::cons on the
    implicit UNLOCK TABLE.
    
    We can fix the bug by removing the above mentioned access to
    ha_spider::conns. We also modified spider_free_trx_conn() so that it
    frees the connections only when no table is locked to reduce the
    chance of another heap-use-after-free on ha_spider::conns.
    a26700cc
spd_trx.cc 137 KB