rds_rdma_init() calls rds_ib_init(), which registers rds_ib_transport, and only then creates the RDMA CM listener. If the listener setup fails, rds_ib_exit() unregisters the transport again. Between the two calls the transport is visible to rds_trans_get_preferred() while the module is still being initialized, and try_module_get() succeeds for a module in MODULE_STATE_COMING. A bind() that races with a failed initialization can then run ->laddr_check() after do_init_module() freed the module. Register the transport only once the listener is up, so that it is never reachable from a module that can still fail to initialize, and unregister it in rds_rdma_exit() before the transport is torn down. Signed-off-by: Aibing Chen <chen…@cmss.chinamobile.com> --- net/rds/ib.c | 3 --- net/rds/rdma_transport.c | 7 ++++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/net/rds/ib.c b/net/rds/ib.c index 4ea9838d0..784d358fe 100644 --- a/net/rds/ib.c +++ b/net/rds/ib.c @@ -541,7 +541,6 @@ void rds_ib_exit(void) rds_ib_destroy_nodev_conns(); rds_ib_sysctl_exit(); rds_ib_recv_exit(); - rds_trans_unregister(&rds_ib_transport); rds_ib_mr_exit(); } @@ -605,8 +604,6 @@ int rds_ib_init(void) if (ret) goto out_sysctl; - rds_trans_register(&rds_ib_transport); - rds_info_register_func(RDS_INFO_IB_CONNECTIONS, rds_ib_ic_info); #if IS_ENABLED(CONFIG_IPV6) rds_info_register_func(RDS6_INFO_IB_CONNECTIONS, rds6_ib_ic_info); diff --git a/net/rds/rdma_transport.c b/net/rds/rdma_transport.c index 75532734c..690b8a211 100644 --- a/net/rds/rdma_transport.c +++ b/net/rds/rdma_transport.c @@ -344,8 +344,12 @@ static int __init rds_rdma_init(void) goto out; ret = rds_rdma_listen_init(); - if (ret) + if (ret) { rds_ib_exit(); + goto out; + } + + rds_trans_register(&rds_ib_transport); out: return ret; } @@ -355,6 +359,7 @@ static void __exit rds_rdma_exit(void) { /* stop listening first to ensure no new connections are attempted */ rds_rdma_listen_stop(); + rds_trans_unregister(&rds_ib_transport); rds_ib_exit(); } module_exit(rds_rdma_exit);