Skip to content

Commit 8c3b8dc

Browse files
liuyacandavem330
authored andcommitted
net/smc: fix listen processing for SMC-Rv2
In the process of checking whether RDMAv2 is available, the current implementation first sets ini->smcrv2.ib_dev_v2, and then allocates smc buf desc, but the latter may fail. Unfortunately, the caller will only check the former. In this case, a NULL pointer reference will occur in smc_clc_send_confirm_accept() when accessing conn->rmb_desc. This patch does two things: 1. Use the return code to determine whether V2 is available. 2. If the return code is NODEV, continue to check whether V1 is available. Fixes: e49300a ("net/smc: add listen processing for SMC-Rv2") Signed-off-by: liuyacan <liuyacan@corp.netease.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 75c1edf commit 8c3b8dc

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

net/smc/af_smc.c

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,13 +2093,13 @@ static int smc_listen_rdma_reg(struct smc_sock *new_smc, bool local_first)
20932093
return 0;
20942094
}
20952095

2096-
static void smc_find_rdma_v2_device_serv(struct smc_sock *new_smc,
2097-
struct smc_clc_msg_proposal *pclc,
2098-
struct smc_init_info *ini)
2096+
static int smc_find_rdma_v2_device_serv(struct smc_sock *new_smc,
2097+
struct smc_clc_msg_proposal *pclc,
2098+
struct smc_init_info *ini)
20992099
{
21002100
struct smc_clc_v2_extension *smc_v2_ext;
21012101
u8 smcr_version;
2102-
int rc;
2102+
int rc = 0;
21032103

21042104
if (!(ini->smcr_version & SMC_V2) || !smcr_indicated(ini->smc_type_v2))
21052105
goto not_found;
@@ -2117,26 +2117,31 @@ static void smc_find_rdma_v2_device_serv(struct smc_sock *new_smc,
21172117
ini->smcrv2.saddr = new_smc->clcsock->sk->sk_rcv_saddr;
21182118
ini->smcrv2.daddr = smc_ib_gid_to_ipv4(smc_v2_ext->roce);
21192119
rc = smc_find_rdma_device(new_smc, ini);
2120-
if (rc) {
2121-
smc_find_ism_store_rc(rc, ini);
2120+
if (rc)
21222121
goto not_found;
2123-
}
2122+
21242123
if (!ini->smcrv2.uses_gateway)
21252124
memcpy(ini->smcrv2.nexthop_mac, pclc->lcl.mac, ETH_ALEN);
21262125

21272126
smcr_version = ini->smcr_version;
21282127
ini->smcr_version = SMC_V2;
21292128
rc = smc_listen_rdma_init(new_smc, ini);
2130-
if (!rc)
2131-
rc = smc_listen_rdma_reg(new_smc, ini->first_contact_local);
2132-
if (!rc)
2133-
return;
2134-
ini->smcr_version = smcr_version;
2135-
smc_find_ism_store_rc(rc, ini);
2129+
if (rc) {
2130+
ini->smcr_version = smcr_version;
2131+
goto not_found;
2132+
}
2133+
rc = smc_listen_rdma_reg(new_smc, ini->first_contact_local);
2134+
if (rc) {
2135+
ini->smcr_version = smcr_version;
2136+
goto not_found;
2137+
}
2138+
return 0;
21362139

21372140
not_found:
2141+
rc = rc ?: SMC_CLC_DECL_NOSMCDEV;
21382142
ini->smcr_version &= ~SMC_V2;
21392143
ini->check_smcrv2 = false;
2144+
return rc;
21402145
}
21412146

21422147
static int smc_find_rdma_v1_device_serv(struct smc_sock *new_smc,
@@ -2169,6 +2174,7 @@ static int smc_listen_find_device(struct smc_sock *new_smc,
21692174
struct smc_init_info *ini)
21702175
{
21712176
int prfx_rc;
2177+
int rc;
21722178

21732179
/* check for ISM device matching V2 proposed device */
21742180
smc_find_ism_v2_device_serv(new_smc, pclc, ini);
@@ -2196,14 +2202,18 @@ static int smc_listen_find_device(struct smc_sock *new_smc,
21962202
return ini->rc ?: SMC_CLC_DECL_NOSMCDDEV;
21972203

21982204
/* check if RDMA V2 is available */
2199-
smc_find_rdma_v2_device_serv(new_smc, pclc, ini);
2200-
if (ini->smcrv2.ib_dev_v2)
2205+
rc = smc_find_rdma_v2_device_serv(new_smc, pclc, ini);
2206+
if (!rc)
22012207
return 0;
22022208

2209+
/* skip V1 check if V2 is unavailable for non-Device reason */
2210+
if (rc != SMC_CLC_DECL_NOSMCDEV &&
2211+
rc != SMC_CLC_DECL_NOSMCRDEV &&
2212+
rc != SMC_CLC_DECL_NOSMCDDEV)
2213+
return rc;
2214+
22032215
/* check if RDMA V1 is available */
22042216
if (!prfx_rc) {
2205-
int rc;
2206-
22072217
rc = smc_find_rdma_v1_device_serv(new_smc, pclc, ini);
22082218
smc_find_ism_store_rc(rc, ini);
22092219
return (!rc) ? 0 : ini->rc;

0 commit comments

Comments
 (0)