From: Suyuan Wang via B4 Relay <devnull+shyckless.gmail.com@kernel.org>
To: jgg@ziepe.ca, leon@kernel.org
Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] RDMA/iwcm: Require CAP_NET_ADMIN for iWARP port mapper netlink messages
Date: Tue, 17 Nov 2026 14:11:13 +0000 [thread overview]
Message-ID: <20261117-iwpm-perm-v1-1-11f1b87d6fb3@gmail.com> (raw)
From: Suyuan Wang <stevewong@hust.edu.cn>
The RDMA_NL_IWCM callbacks process replies and notifications from the
port mapper daemon, iwpmd, but none of them sets RDMA_NL_ADMIN_PERM:
[RDMA_NL_IWPM_REG_PID] = {.dump = iwpm_register_pid_cb},
[RDMA_NL_IWPM_ADD_MAPPING] = {.dump = iwpm_add_mapping_cb},
...
so rdma_nl_rcv_msg() accepts them from any process in init_net.
iwpm_hello_cb() and iwpm_mapping_info_cb() set iwpm_user_pid to the
sender's port ID and mark the client IWPM_REG_INCOMPL, without matching
any pending kernel request. An unprivileged process can thus make
itself the daemon that the kernel sends port mapper requests to. The
mapping replies are matched against the request they answer, but
nothing checks that the sender is the port mapper, and the address a
matching reply carries is the one iw_cm_map() uses.
Set RDMA_NL_ADMIN_PERM on all iwcm callbacks, so the RDMA netlink
dispatcher requires CAP_NET_ADMIN before invoking them. This matches
the RDMA_NL_LS response handlers, which already require it, and iwpmd
runs as root.
Found with a static analysis tool and checked by hand.
Fixes: b493d91d333e ("iwcm: common code for port mapper")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Tested under QEMU (x86_64, CONFIG_INFINIBAND=y): before this patch a
process in a child user namespace, with no CAP_NET_ADMIN over
init_user_ns, can send an RDMA_NL_IWCM message that reaches the
port-mapper callbacks; after it the dispatcher returns -EPERM. A
privileged sender still reaches them. W=1 and sparse show no new
warnings. I don't have iWARP hardware. The upstream iwpmd systemd
service runs as root without a capability bounding set, so it keeps
CAP_NET_ADMIN.
Related discussion of unprivileged access to this interface:
https://lore.kernel.org/linux-rdma/20261109200330.2361828-1-graypanda.inzag@gmail.com/
That patch fixes a REMOTE_INFO allocation leak; this one adds the
missing privilege check for all the IWCM port-mapper callbacks.
---
drivers/infiniband/core/iwcm.c | 40 ++++++++++++++++++++++++++++++++--------
1 file changed, 32 insertions(+), 8 deletions(-)
diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
index 4b05867dad89..94a92434063a 100644
--- a/drivers/infiniband/core/iwcm.c
+++ b/drivers/infiniband/core/iwcm.c
@@ -81,14 +81,38 @@ const char *__attribute_const__ iwcm_reject_msg(int reason)
EXPORT_SYMBOL(iwcm_reject_msg);
static struct rdma_nl_cbs iwcm_nl_cb_table[RDMA_NL_IWPM_NUM_OPS] = {
- [RDMA_NL_IWPM_REG_PID] = {.dump = iwpm_register_pid_cb},
- [RDMA_NL_IWPM_ADD_MAPPING] = {.dump = iwpm_add_mapping_cb},
- [RDMA_NL_IWPM_QUERY_MAPPING] = {.dump = iwpm_add_and_query_mapping_cb},
- [RDMA_NL_IWPM_REMOTE_INFO] = {.dump = iwpm_remote_info_cb},
- [RDMA_NL_IWPM_HANDLE_ERR] = {.dump = iwpm_mapping_error_cb},
- [RDMA_NL_IWPM_MAPINFO] = {.dump = iwpm_mapping_info_cb},
- [RDMA_NL_IWPM_MAPINFO_NUM] = {.dump = iwpm_ack_mapping_info_cb},
- [RDMA_NL_IWPM_HELLO] = {.dump = iwpm_hello_cb}
+ [RDMA_NL_IWPM_REG_PID] = {
+ .dump = iwpm_register_pid_cb,
+ .flags = RDMA_NL_ADMIN_PERM,
+ },
+ [RDMA_NL_IWPM_ADD_MAPPING] = {
+ .dump = iwpm_add_mapping_cb,
+ .flags = RDMA_NL_ADMIN_PERM,
+ },
+ [RDMA_NL_IWPM_QUERY_MAPPING] = {
+ .dump = iwpm_add_and_query_mapping_cb,
+ .flags = RDMA_NL_ADMIN_PERM,
+ },
+ [RDMA_NL_IWPM_REMOTE_INFO] = {
+ .dump = iwpm_remote_info_cb,
+ .flags = RDMA_NL_ADMIN_PERM,
+ },
+ [RDMA_NL_IWPM_HANDLE_ERR] = {
+ .dump = iwpm_mapping_error_cb,
+ .flags = RDMA_NL_ADMIN_PERM,
+ },
+ [RDMA_NL_IWPM_MAPINFO] = {
+ .dump = iwpm_mapping_info_cb,
+ .flags = RDMA_NL_ADMIN_PERM,
+ },
+ [RDMA_NL_IWPM_MAPINFO_NUM] = {
+ .dump = iwpm_ack_mapping_info_cb,
+ .flags = RDMA_NL_ADMIN_PERM,
+ },
+ [RDMA_NL_IWPM_HELLO] = {
+ .dump = iwpm_hello_cb,
+ .flags = RDMA_NL_ADMIN_PERM,
+ },
};
static struct workqueue_struct *iwcm_wq;
reply other threads:[~2026-11-17 14:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261117-iwpm-perm-v1-1-11f1b87d6fb3@gmail.com \
--to=devnull+shyckless.gmail.com@kernel.org \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=shyckless@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
all inboxes | Powered by JetHome®