• Wen Gu's avatar
    net/smc: Reset conn->lgr when link group registration fails · 36595d8a
    Wen Gu authored
    SMC connections might fail to be registered in a link group due to
    unable to find a usable link during its creation. As a result,
    smc_conn_create() will return a failure and most resources related
    to the connection won't be applied or initialized, such as
    conn->abort_work or conn->lnk.
    
    If smc_conn_free() is invoked later, it will try to access the
    uninitialized resources related to the connection, thus causing
    a warning or crash.
    
    This patch tries to fix this by resetting conn->lgr to NULL if an
    abnormal exit occurs in smc_lgr_register_conn(), thus avoiding the
    access to uninitialized resources in smc_conn_free().
    
    Meanwhile, the new created link group should be terminated if smc
    connections can't be registered in it. So smc_lgr_cleanup_early() is
    modified to take care of link group only and invoked to terminate
    unusable link group by smc_conn_create(). The call to smc_conn_free()
    is moved out from smc_lgr_cleanup_early() to smc_conn_abort().
    
    Fixes: 56bc3b20 ("net/smc: assign link to a new connection")
    Suggested-by: default avatarKarsten Graul <kgraul@linux.ibm.com>
    Signed-off-by: default avatarWen Gu <guwen@linux.alibaba.com>
    Acked-by: default avatarKarsten Graul <kgraul@linux.ibm.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    36595d8a
af_smc.c 73.8 KB