From 1ad68a07c00898b33c2c546f670e97bd937ad3eb Mon Sep 17 00:00:00 2001 From: Ian Ziemba Date: Wed, 6 Nov 2024 15:09:25 -0600 Subject: [PATCH 1/2] prov/cxi: Fix broken client key check Clients could provide an RKEY greater than 4 bytes and the provider would not return -FI_EKEYREJECTED. Signed-off-by: Ian Ziemba --- prov/cxi/src/cxip_mr.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/prov/cxi/src/cxip_mr.c b/prov/cxi/src/cxip_mr.c index 6a53ea87af5..b52e6d22d1a 100644 --- a/prov/cxi/src/cxip_mr.c +++ b/prov/cxi/src/cxip_mr.c @@ -758,6 +758,14 @@ static void cxip_mr_domain_remove(struct cxip_mr *mr) ofi_spin_unlock(&mr->domain->mr_domain.lock); } +static bool cxip_is_valid_mr_key(uint64_t key) +{ + if (key & ~CXIP_MR_KEY_MASK) + return false; + + return true; +} + /* * cxip_mr_domain_insert() - Validate uniqueness and insert * client key in the domain hash table. @@ -777,7 +785,7 @@ static int cxip_mr_domain_insert(struct cxip_mr *mr) mr->key = mr->attr.requested_key; - if (!cxip_generic_is_valid_mr_key(mr->key)) + if (!cxip_is_valid_mr_key(mr->key)) return -FI_EKEYREJECTED; bucket = fasthash64(&mr->key, sizeof(mr->key), 0) % @@ -851,14 +859,6 @@ static int cxip_prov_cache_init_mr_key(struct cxip_mr *mr, return FI_SUCCESS; } -static bool cxip_is_valid_mr_key(uint64_t key) -{ - if (key & ~CXIP_MR_KEY_MASK) - return false; - - return true; -} - static bool cxip_is_valid_prov_mr_key(uint64_t key) { struct cxip_mr_key cxip_key = { From 73c6da12a533efb550d011daf4206046c93c26fe Mon Sep 17 00:00:00 2001 From: Ian Ziemba Date: Wed, 6 Nov 2024 15:20:54 -0600 Subject: [PATCH 2/2] prov/cxi: Add test for invalid client RKEY Signed-off-by: Ian Ziemba --- prov/cxi/test/mr.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/prov/cxi/test/mr.c b/prov/cxi/test/mr.c index 0c21f1e3c5d..3699506c20c 100644 --- a/prov/cxi/test/mr.c +++ b/prov/cxi/test/mr.c @@ -51,6 +51,25 @@ Test(mr, invalid_fi_directed_recv_flag) cr_assert_eq(ret, -FI_EINVAL, "fi_mr_regattr failed: %d", ret); } +Test(mr, invalid_client_rkey) +{ + int ret; + struct fi_mr_attr attr = {}; + struct iovec iov = {}; + struct fid_mr *mr; + + iov.iov_len = sizeof(ret); + iov.iov_base = (void *)&ret; + + attr.mr_iov = &iov; + attr.iov_count = 1; + attr.access = FI_REMOTE_READ | FI_REMOTE_WRITE; + attr.requested_key = ~1; + + ret = fi_mr_regattr(cxit_domain, &attr, 0, &mr); + cr_assert_eq(ret, -FI_EKEYREJECTED, "fi_mr_regattr failed: %d", ret); +} + Test(mr, std_mrs, .timeout = 600, .disabled = true) { int std_mr_cnt = 16*1024;