Skip to content

Commit 03e9b33

Browse files
Md Haris Iqbaljgunthorpe
authored andcommitted
RDMA/rtrs: Only allow addition of path to an already established session
While adding a path from the client side to an already established session, it was possible to provide the destination IP to a different server. This is dangerous. This commit adds an extra member to the rtrs_msg_conn_req structure, named first_conn; which is supposed to notify if the connection request is the first for that session or not. On the server side, if a session does not exist but the first_conn received inside the rtrs_msg_conn_req structure is 1, the connection request is failed. This signifies that the connection request is for an already existing session, and since the server did not find one, it is an wrong connection request. Fixes: 6a98d71 ("RDMA/rtrs: client: main functionality") Fixes: 9cb8374 ("RDMA/rtrs: server: main functionality") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Md Haris Iqbal <[email protected]> Reviewed-by: Lutz Pogrell <[email protected]> Signed-off-by: Jack Wang <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent e6daa8f commit 03e9b33

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

drivers/infiniband/ulp/rtrs/rtrs-clt.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
*/
3232
#define RTRS_RECONNECT_SEED 8
3333

34+
#define FIRST_CONN 0x01
35+
3436
MODULE_DESCRIPTION("RDMA Transport Client");
3537
MODULE_LICENSE("GPL");
3638

@@ -1660,6 +1662,7 @@ static int rtrs_rdma_route_resolved(struct rtrs_clt_con *con)
16601662
.cid_num = cpu_to_le16(sess->s.con_num),
16611663
.recon_cnt = cpu_to_le16(sess->s.recon_cnt),
16621664
};
1665+
msg.first_conn = sess->for_new_clt ? FIRST_CONN : 0;
16631666
uuid_copy(&msg.sess_uuid, &sess->s.uuid);
16641667
uuid_copy(&msg.paths_uuid, &clt->paths_uuid);
16651668

@@ -1745,6 +1748,8 @@ static int rtrs_rdma_conn_established(struct rtrs_clt_con *con,
17451748
scnprintf(sess->hca_name, sizeof(sess->hca_name),
17461749
sess->s.dev->ib_dev->name);
17471750
sess->s.src_addr = con->c.cm_id->route.addr.src_addr;
1751+
/* set for_new_clt, to allow future reconnect on any path */
1752+
sess->for_new_clt = 1;
17481753
}
17491754

17501755
return 0;
@@ -2662,6 +2667,8 @@ struct rtrs_clt *rtrs_clt_open(struct rtrs_clt_ops *ops,
26622667
err = PTR_ERR(sess);
26632668
goto close_all_sess;
26642669
}
2670+
if (!i)
2671+
sess->for_new_clt = 1;
26652672
list_add_tail_rcu(&sess->s.entry, &clt->paths_list);
26662673

26672674
err = init_sess(sess);

drivers/infiniband/ulp/rtrs/rtrs-clt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ struct rtrs_clt_sess {
143143
int max_send_sge;
144144
u32 flags;
145145
struct kobject kobj;
146+
u8 for_new_clt;
146147
struct rtrs_clt_stats *stats;
147148
/* cache hca_port and hca_name to display in sysfs */
148149
u8 hca_port;

drivers/infiniband/ulp/rtrs/rtrs-pri.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ struct rtrs_msg_conn_req {
188188
__le16 recon_cnt;
189189
uuid_t sess_uuid;
190190
uuid_t paths_uuid;
191-
u8 reserved[12];
191+
u8 first_conn : 1;
192+
u8 reserved_bits : 7;
193+
u8 reserved[11];
192194
};
193195

194196
/**

drivers/infiniband/ulp/rtrs/rtrs-srv.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,8 @@ static void free_srv(struct rtrs_srv *srv)
13331333
}
13341334

13351335
static struct rtrs_srv *get_or_create_srv(struct rtrs_srv_ctx *ctx,
1336-
const uuid_t *paths_uuid)
1336+
const uuid_t *paths_uuid,
1337+
bool first_conn)
13371338
{
13381339
struct rtrs_srv *srv;
13391340
int i;
@@ -1346,12 +1347,20 @@ static struct rtrs_srv *get_or_create_srv(struct rtrs_srv_ctx *ctx,
13461347
return srv;
13471348
}
13481349
}
1350+
/*
1351+
* If this request is not the first connection request from the
1352+
* client for this session then fail and return error.
1353+
*/
1354+
if (!first_conn) {
1355+
mutex_unlock(&ctx->srv_mutex);
1356+
return ERR_PTR(-ENXIO);
1357+
}
13491358

13501359
/* need to allocate a new srv */
13511360
srv = kzalloc(sizeof(*srv), GFP_KERNEL);
13521361
if (!srv) {
13531362
mutex_unlock(&ctx->srv_mutex);
1354-
return NULL;
1363+
return ERR_PTR(-ENOMEM);
13551364
}
13561365

13571366
INIT_LIST_HEAD(&srv->paths_list);
@@ -1386,7 +1395,7 @@ static struct rtrs_srv *get_or_create_srv(struct rtrs_srv_ctx *ctx,
13861395

13871396
err_free_srv:
13881397
kfree(srv);
1389-
return NULL;
1398+
return ERR_PTR(-ENOMEM);
13901399
}
13911400

13921401
static void put_srv(struct rtrs_srv *srv)
@@ -1787,13 +1796,13 @@ static int rtrs_rdma_connect(struct rdma_cm_id *cm_id,
17871796
goto reject_w_econnreset;
17881797
}
17891798
recon_cnt = le16_to_cpu(msg->recon_cnt);
1790-
srv = get_or_create_srv(ctx, &msg->paths_uuid);
1799+
srv = get_or_create_srv(ctx, &msg->paths_uuid, msg->first_conn);
17911800
/*
17921801
* "refcount == 0" happens if a previous thread calls get_or_create_srv
17931802
* allocate srv, but chunks of srv are not allocated yet.
17941803
*/
1795-
if (!srv || refcount_read(&srv->refcount) == 0) {
1796-
err = -ENOMEM;
1804+
if (IS_ERR(srv) || refcount_read(&srv->refcount) == 0) {
1805+
err = PTR_ERR(srv);
17971806
goto reject_w_err;
17981807
}
17991808
mutex_lock(&srv->paths_mutex);

0 commit comments

Comments
 (0)