Skip to content

Commit c6f81f3

Browse files
Md Haris Iqbalgregkh
authored andcommitted
RDMA/rtrs: Only allow addition of path to an already established session
[ Upstream commit 03e9b33 ] 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/20210212134525.103456-3-jinpu.wang@cloud.ionos.com Signed-off-by: Md Haris Iqbal <haris.iqbal@cloud.ionos.com> Reviewed-by: Lutz Pogrell <lutz.pogrell@cloud.ionos.com> Signed-off-by: Jack Wang <jinpu.wang@cloud.ionos.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 51ea7da commit c6f81f3

4 files changed

Lines changed: 26 additions & 7 deletions

File tree

‎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

@@ -1674,6 +1676,7 @@ static int rtrs_rdma_route_resolved(struct rtrs_clt_con *con)
16741676
.cid_num = cpu_to_le16(sess->s.con_num),
16751677
.recon_cnt = cpu_to_le16(sess->s.recon_cnt),
16761678
};
1679+
msg.first_conn = sess->for_new_clt ? FIRST_CONN : 0;
16771680
uuid_copy(&msg.sess_uuid, &sess->s.uuid);
16781681
uuid_copy(&msg.paths_uuid, &clt->paths_uuid);
16791682

@@ -1759,6 +1762,8 @@ static int rtrs_rdma_conn_established(struct rtrs_clt_con *con,
17591762
scnprintf(sess->hca_name, sizeof(sess->hca_name),
17601763
sess->s.dev->ib_dev->name);
17611764
sess->s.src_addr = con->c.cm_id->route.addr.src_addr;
1765+
/* set for_new_clt, to allow future reconnect on any path */
1766+
sess->for_new_clt = 1;
17621767
}
17631768

17641769
return 0;
@@ -2682,6 +2687,8 @@ struct rtrs_clt *rtrs_clt_open(struct rtrs_clt_ops *ops,
26822687
err = PTR_ERR(sess);
26832688
goto close_all_sess;
26842689
}
2690+
if (!i)
2691+
sess->for_new_clt = 1;
26852692
list_add_tail_rcu(&sess->s.entry, &clt->paths_list);
26862693

26872694
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
@@ -142,6 +142,7 @@ struct rtrs_clt_sess {
142142
int max_send_sge;
143143
u32 flags;
144144
struct kobject kobj;
145+
u8 for_new_clt;
145146
struct rtrs_clt_stats *stats;
146147
/* cache hca_port and hca_name to display in sysfs */
147148
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
@@ -1350,7 +1350,8 @@ static void free_srv(struct rtrs_srv *srv)
13501350
}
13511351

13521352
static struct rtrs_srv *get_or_create_srv(struct rtrs_srv_ctx *ctx,
1353-
const uuid_t *paths_uuid)
1353+
const uuid_t *paths_uuid,
1354+
bool first_conn)
13541355
{
13551356
struct rtrs_srv *srv;
13561357
int i;
@@ -1363,12 +1364,20 @@ static struct rtrs_srv *get_or_create_srv(struct rtrs_srv_ctx *ctx,
13631364
return srv;
13641365
}
13651366
}
1367+
/*
1368+
* If this request is not the first connection request from the
1369+
* client for this session then fail and return error.
1370+
*/
1371+
if (!first_conn) {
1372+
mutex_unlock(&ctx->srv_mutex);
1373+
return ERR_PTR(-ENXIO);
1374+
}
13661375

13671376
/* need to allocate a new srv */
13681377
srv = kzalloc(sizeof(*srv), GFP_KERNEL);
13691378
if (!srv) {
13701379
mutex_unlock(&ctx->srv_mutex);
1371-
return NULL;
1380+
return ERR_PTR(-ENOMEM);
13721381
}
13731382

13741383
INIT_LIST_HEAD(&srv->paths_list);
@@ -1403,7 +1412,7 @@ static struct rtrs_srv *get_or_create_srv(struct rtrs_srv_ctx *ctx,
14031412

14041413
err_free_srv:
14051414
kfree(srv);
1406-
return NULL;
1415+
return ERR_PTR(-ENOMEM);
14071416
}
14081417

14091418
static void put_srv(struct rtrs_srv *srv)
@@ -1804,13 +1813,13 @@ static int rtrs_rdma_connect(struct rdma_cm_id *cm_id,
18041813
goto reject_w_econnreset;
18051814
}
18061815
recon_cnt = le16_to_cpu(msg->recon_cnt);
1807-
srv = get_or_create_srv(ctx, &msg->paths_uuid);
1816+
srv = get_or_create_srv(ctx, &msg->paths_uuid, msg->first_conn);
18081817
/*
18091818
* "refcount == 0" happens if a previous thread calls get_or_create_srv
18101819
* allocate srv, but chunks of srv are not allocated yet.
18111820
*/
1812-
if (!srv || refcount_read(&srv->refcount) == 0) {
1813-
err = -ENOMEM;
1821+
if (IS_ERR(srv) || refcount_read(&srv->refcount) == 0) {
1822+
err = PTR_ERR(srv);
18141823
goto reject_w_err;
18151824
}
18161825
mutex_lock(&srv->paths_mutex);

0 commit comments

Comments
 (0)