From: Daniel Wade <danjwade95@gmail.com>
To: Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>
Cc: Jeffin Philip <jeffinphilip14@gmail.com>,
Shuangpeng Bai <shuangpeng.kernel@gmail.com>,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] RDMA/iwpm: reject a port-mapper reply meant for another request type
Date: Sun, 6 Dec 2026 01:11:11 +1030 [thread overview]
Message-ID: <20261205144111.8366-2-danjwade95@gmail.com> (raw)
In-Reply-To: <20261205144111.8366-1-danjwade95@gmail.com>
Requests are looked up by sequence number only, and req_buffer is a
void * that the two producers point at different types: a 48-byte
struct iwpm_dev_data from iwpm_register_pid(), a 516-byte struct
iwpm_sa_data from iwpm_add_mapping().
So an ADD_MAPPING reply to a REG_PID request copies 128 bytes to offset
128 of the 48-byte object, over another local of iw_cm_map(). The copy
only happens if the sockaddr family matches first. That family is read
from dev_name[]. So it takes a device whose name begins with those two
bytes, which needs CAP_NET_ADMIN to create.
Record the op each request expects and refuse a reply that does not
match.
Fixes: 30dc5e63d6a5 ("RDMA/core: Add support for iWARP Port Mapper user space service")
Signed-off-by: Daniel Wade <danjwade95@gmail.com>
---
Notes:
Reproduced on the same kernel: an ADD_MAPPING reply to a REG_PID request is
refused with "Request does not expect this reply" and the request then times
out normally. The 1/2 test is unchanged by this patch.
drivers/infiniband/core/iwpm_msg.c | 24 ++++++++++++++++++++++--
drivers/infiniband/core/iwpm_util.c | 4 +++-
drivers/infiniband/core/iwpm_util.h | 4 +++-
3 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/drivers/infiniband/core/iwpm_msg.c b/drivers/infiniband/core/iwpm_msg.c
index d050aa0db30fb..1d77349db51e5 100644
--- a/drivers/infiniband/core/iwpm_msg.c
+++ b/drivers/infiniband/core/iwpm_msg.c
@@ -78,7 +78,9 @@ int iwpm_register_pid(struct iwpm_dev_data *pm_msg, u8 nl_client)
goto pid_query_error;
}
nlh->nlmsg_seq = iwpm_get_nlmsg_seq();
- nlmsg_request = iwpm_get_nlmsg_request(nlh->nlmsg_seq, nl_client, GFP_KERNEL);
+ nlmsg_request = iwpm_get_nlmsg_request(nlh->nlmsg_seq,
+ RDMA_NL_IWPM_REG_PID,
+ nl_client, GFP_KERNEL);
if (!nlmsg_request) {
err_str = "Unable to allocate netlink request";
goto pid_query_error;
@@ -161,7 +163,9 @@ int iwpm_add_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client)
goto add_mapping_error;
}
nlh->nlmsg_seq = iwpm_get_nlmsg_seq();
- nlmsg_request = iwpm_get_nlmsg_request(nlh->nlmsg_seq, nl_client, GFP_KERNEL);
+ nlmsg_request = iwpm_get_nlmsg_request(nlh->nlmsg_seq,
+ RDMA_NL_IWPM_ADD_MAPPING,
+ nl_client, GFP_KERNEL);
if (!nlmsg_request) {
err_str = "Unable to allocate netlink request";
goto add_mapping_error;
@@ -246,6 +250,7 @@ int iwpm_add_and_query_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client)
}
nlh->nlmsg_seq = iwpm_get_nlmsg_seq();
nlmsg_request = iwpm_get_nlmsg_request(nlh->nlmsg_seq,
+ RDMA_NL_IWPM_QUERY_MAPPING,
nl_client, GFP_KERNEL);
if (!nlmsg_request) {
err_str = "Unable to allocate netlink request";
@@ -404,6 +409,11 @@ int iwpm_register_pid_cb(struct sk_buff *skb, struct netlink_callback *cb)
__func__, msg_seq);
return -EINVAL;
}
+ if (nlmsg_request->nl_op != RDMA_NL_IWPM_REG_PID) {
+ pr_info("%s: Request does not expect this reply\n", __func__);
+ kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request);
+ return -EINVAL;
+ }
pm_msg = nlmsg_request->req_buffer;
nl_client = nlmsg_request->nl_client;
dev_name = (char *)nla_data(nltb[IWPM_NLA_RREG_IBDEV_NAME]);
@@ -478,6 +488,11 @@ int iwpm_add_mapping_cb(struct sk_buff *skb, struct netlink_callback *cb)
__func__, msg_seq);
return -EINVAL;
}
+ if (nlmsg_request->nl_op != RDMA_NL_IWPM_ADD_MAPPING) {
+ pr_info("%s: Request does not expect this reply\n", __func__);
+ kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request);
+ return -EINVAL;
+ }
pm_msg = nlmsg_request->req_buffer;
local_sockaddr = (struct sockaddr_storage *)
nla_data(nltb[IWPM_NLA_RMANAGE_ADDR]);
@@ -557,6 +572,11 @@ int iwpm_add_and_query_mapping_cb(struct sk_buff *skb,
__func__, msg_seq);
return -EINVAL;
}
+ if (nlmsg_request->nl_op != RDMA_NL_IWPM_QUERY_MAPPING) {
+ pr_info("%s: Request does not expect this reply\n", __func__);
+ kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request);
+ return -EINVAL;
+ }
pm_msg = nlmsg_request->req_buffer;
local_sockaddr = (struct sockaddr_storage *)
nla_data(nltb[IWPM_NLA_RQUERY_LOCAL_ADDR]);
diff --git a/drivers/infiniband/core/iwpm_util.c b/drivers/infiniband/core/iwpm_util.c
index 639ea80373ea6..2b336e1781b33 100644
--- a/drivers/infiniband/core/iwpm_util.c
+++ b/drivers/infiniband/core/iwpm_util.c
@@ -305,7 +305,8 @@ int iwpm_get_remote_info(struct sockaddr_storage *mapped_loc_addr,
}
struct iwpm_nlmsg_request *iwpm_get_nlmsg_request(__u32 nlmsg_seq,
- u8 nl_client, gfp_t gfp)
+ u16 nl_op, u8 nl_client,
+ gfp_t gfp)
{
struct iwpm_nlmsg_request *nlmsg_request;
unsigned long flags;
@@ -316,6 +317,7 @@ struct iwpm_nlmsg_request *iwpm_get_nlmsg_request(__u32 nlmsg_seq,
kref_init(&nlmsg_request->kref);
nlmsg_request->nlmsg_seq = nlmsg_seq;
+ nlmsg_request->nl_op = nl_op;
nlmsg_request->nl_client = nl_client;
nlmsg_request->request_done = 0;
nlmsg_request->err_code = 0;
diff --git a/drivers/infiniband/core/iwpm_util.h b/drivers/infiniband/core/iwpm_util.h
index d6fc8402158a3..d612d0fc2c173 100644
--- a/drivers/infiniband/core/iwpm_util.h
+++ b/drivers/infiniband/core/iwpm_util.h
@@ -65,6 +65,7 @@ struct iwpm_nlmsg_request {
struct list_head inprocess_list;
__u32 nlmsg_seq;
void *req_buffer;
+ u16 nl_op;
u8 nl_client;
u8 request_done;
u16 err_code;
@@ -103,7 +104,8 @@ struct iwpm_admin_data {
* otherwise returns NULL
*/
struct iwpm_nlmsg_request *iwpm_get_nlmsg_request(__u32 nlmsg_seq,
- u8 nl_client, gfp_t gfp);
+ u16 nl_op, u8 nl_client,
+ gfp_t gfp);
/**
* iwpm_free_nlmsg_request - Deallocate netlink message request
next prev parent reply other threads:[~2026-12-05 14:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 14:41 [PATCH 1/2] RDMA/iwpm: fix use-after-free of the netlink request object Daniel Wade
2026-12-05 14:41 ` Daniel Wade [this message]
2026-12-05 14:55 ` [PATCH 2/2] RDMA/iwpm: reject a port-mapper reply meant for another request type sashiko-bot
2026-12-05 14:55 ` [PATCH 1/2] RDMA/iwpm: fix use-after-free of the netlink request object sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205144111.8366-2-danjwade95@gmail.com \
--to=danjwade95@gmail.com \
--cc=jeffinphilip14@gmail.com \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=shuangpeng.kernel@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox