RDMA/iwcm: Require CAP_NET_ADMIN for iWARP port mapper netlink messages
PATCH 1/1 RDMA/iwcm: Require CAP_NET_ADMIN for iWARP port mapper netlink messages
From: Suyuan Wang <[email protected]>
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.
---
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/[email protected]/
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(-)
drivers/infiniband/core/iwcm.c +32 -8
@@ -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;
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 15 lines
From: Suyuan Wang <[email protected]>
The
RDMA_NL_IWCMcallbacks process replies and notifications from the port mapper daemon, iwpmd, but none of them setsRDMA_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 ininit_net.
iwpm_hello_cb()andiwpm_mapping_info_cb()setiwpm_user_pidto the sender's port ID and mark the clientIWPM_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
Quoted 6 lines
[ ... ]Fixes b493d91d333e ("iwcm: common code for port mapper")Co-developed-by Kaixuan Li <[email protected]>Signed-off-by Kaixuan Li <[email protected]>Signed-off-by Suyuan Wang <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Leon Romanovsky
AppliedQuoted 8 lines · Suyuan Wang
The
RDMA_NL_IWCMcallbacks process replies and notifications from the port mapper daemon, iwpmd, but none of them setsRDMA_NL_ADMIN_PERM:[RDMA_NL_IWPM_REG_PID] = {.dump = iwpm_register_pid_cb}, [RDMA_NL_IWPM_ADD_MAPPING] = {.dump = iwpm_add_mapping_cb}, ...[...]
Applied, thanks!
[1/1] RDMA/iwcm: Require CAP_NET_ADMIN for iWARP port mapper netlink messages
https://git.kernel.org/rdma/rdma/c/13fe248d139ace
Best regards,
Signature · 1 line
Leon Romanovsky <[email protected]>