From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796540270; b=tvc9WhQo8dpbRi6Tv1qe5jDWnVAnEi6ItrvagXvLPx86yZ7RzorUVyMkm4x2LYXFMTWy Ga/cZfCe6urnWvCZ7SeJD65MyEHd7kna0Rl4hkU6r4yyw0G+avQb+YlNes2jcIPiofjM0 xBA5XtYZ6hn5LKYNgF2xQgjvytXvG7E8ms5JPd7B2gn9EVXsHFPdkkTYMnZneghiL/Y4k cQLCJUe0bEfKCXYIp4IQBmPcYqW53BizccLwNPRimitCRBFc8mzywn7Nfjex4pdbHZTlg jb6UUJbl21Y8qiDCr3MgGSMbY2vH1+T5NdX8vzOlPS8th7n4otbjimphZLtklGmAhQw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796540270; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=00vx4O9cskF0tw3/PyKR76ARTo9StArTHuLx9gsxwdY=; b=zuzY8E78f4iacKISWlyeURAGVZFYtLKXo2phMVnMf45d++6T/xt/XDOg4ERbGMYXv/zY DHgmbrbI2T366DmGokSoZQYqN7RyPZlW2hb/J5tZudEboIQBWt5VRgZG/5Xrs9eyQp0x/ HxHJ7h4/hjDNeR0DU6Tgx9cmRQLJOttlsyL4ue9wMIRYHv43m46vlyy1tcA9G20uKOcWH SawyAlgcw95W38FPkIBXnmw2gSiyiUklEjSRmcvpPlTdP68I67GfIiP+VQVZpFWExlU64 Pz0qhMJT/118YLWRamvQZ2Mygztlzn8L6Zkbg5ilqNv9WpI6giRTNam1sY4OKNrsQbg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=TR4Qwz5E; arc=none smtp.remote-ip=74.125.82.41 Received: from mail-dl1-f41.google.com (mail-dl1-f41.google.com [74.125.82.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5788B606A681 for ; Sun, 6 Dec 2026 06:57:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5788B606A681 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=TR4Qwz5E Received: by mail-dl1-f41.google.com with SMTP id a92af1059eb24-1aefd1bf74aso1504254c88.1 for ; Sat, 05 Dec 2026 22:57:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796540269; x=1797145069; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=00vx4O9cskF0tw3/PyKR76ARTo9StArTHuLx9gsxwdY=; b=TR4Qwz5Ek/QtoUIcQx4ovyx3ZyetzToNDPFIwPbpo4ScWXJIvfGzDK8Wb1xoYsVZTH Fq3YQ1LxEjygT0LC8WJy3qMUzPEExWHbOU6DUoMJfPSY/n4sQ81D0sNorVAApiVPYYYs Sz7XhJ0Fa0xus5JVDAFGVpD/XjGkzqGH3cG4xn0jhdmhHlTLVJ7qPFgQRWuEAsxflCHo lhVJEdRQo+4Mb76NORyITJhPVFtfYLvsBihq3ud0cr/meZjIiKgZlDZ+G1IbnMVgxkpy xnCixLqhM2bp6VLFD9PK3cwEyfUUJOz2DgqNLGfrusRQXpR61+lSNJFlGTidQ0ECNsq5 PPag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796540269; x=1797145069; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=00vx4O9cskF0tw3/PyKR76ARTo9StArTHuLx9gsxwdY=; b=VEdJHdXkdyVpFEsHUo1KY5mX4Ul25upxNJFCHqy0/Linj5G1FO0c/Gp4r9UKxZfX1m +GCiSLEINp+E5nU+R8KQ7suspWtX0zfYwf9IiIRAODo31vKSnD3DMMpCrNxDDRINGinR +G3O2V76iqlyJGYt/wZ3IBFMDQitKTElheO4UgAk4o+HNi3w3VXoZQisYrBCDFD+ja3T XtdIY8uDvENo4M0l5lNgrfICbMhPpgACB+prHH73zyApUBebv95hns61lPQec9clvPX0 o8Gyins6XML4XI73aB9ZsmpTg5818buY9r3+BOoJiwqQiqcn05yuULHsNktx4iQdgM4I fpzA== X-Forwarded-Encrypted: i=1; AL+hErG0OpD1vZI0o0JKXN0UYlO4TBHIJcVN3gQUgwNJO6rWHDizYxoPST+23M8d0bUOyGGsiBOzQPxhbVelnU4=@vger.kernel.org X-Gm-Message-State: APuU4Z8LLdsJLSiQxFuIpSyjvUfX/jwH0CBGU/zE2EKMxJzG/sd+MD9Z XlWBXtZDyUMk7FyolbjM5g8FGuC7DddwTfaPSRzc7MaBHv1fNoWqK+Sjef+F5BtorvgxLaZn X-Gm-Gg: AZFdTZfVnmoW2iYlECrZhiRUQ7o9nGtTpbn4ZUetdGwOQCB7gc4YvYVkEmB7dPVWTza c8HNuvc39it09O60jiAlNGNJr8l57EUMYZHp/JaTRWc5Mw2TmME4MRI0yRN3RgaoXfF0sW96x/C ygzGcYU7+n12etwZeOZZBsw+nfo+xzJbcYtoyB29sXcRssTQRjb/+aFPk0H8Xp+a4XQlBq2s6LN eHxGXdYztctpiV3+N+LopSeRfDYIpf6fQARCxVctyr9GoJMA0Y7038oc0RLOY8ef6zal455k+9M BuJgNlWCPZDkPbfXeQVQpon3xGRHS2a5eZxettD/DgrUq2aQ9TXBUyHvh1yI2ujdx4FyRgLzA6L lDMLAPc9oImDAFDXBZ1MHKy2y0n3AhcPnvmeVxJNU/pIRkbUBR6ULvSbPkuMFxT1vy39H0mQFuh fbXRgr2kxKdP4+bHOForSfsHCyafhBH7yKokPYfXbI+wpjUvjNzGk07ZaYssI4m9yOyRoLwrS97 iIo90TkzpkOnaGppxkJ3YCEFLQDleA1/XCNDLYL2NVBcRhjR8EBR2L+OJVhW2LBPwU5df+Ycu03 f8cwr6XWt+uFK+BPRo6WJXsfOu6BTNQruhHXoCrCtJtS9/7ApUOh5+aLzHgQyK8qobia+oqe+rQ IUKgc39m4X7NzOR0WZj/cA1IbiUvFQhjd5JLrAz5g+zereQkwJ26nPbopj2lQdHxbWz/oB5fwzs Vk+xRPj/9HahNZZ/8pxCk1zSTQalEdWtr+s9tO3eTZ9smSy0JA5Z3OVSsOutEoosy48o7tN8Tpi rTil/G5c7wQsrT9m5Cn/MsHfQnGluugIwOOyZWxmPs8QV58XsZg50M= X-Received: by 2002:a05:7023:e61:10b0:159:f192:5290 with SMTP id a92af1059eb24-1b5e237f909mr2964749c88.13.1796540269249; Sat, 05 Dec 2026 22:57:49 -0800 (PST) Received: from localhost.localdomain (14-201-175-51.tpgi.com.au. [14.201.175.51]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d6323d8esm24830242c88.0.2026.12.05.22.57.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 22:57:48 -0800 (PST) From: Daniel Wade To: Jason Gunthorpe , Leon Romanovsky Cc: Jeffin Philip , Shuangpeng Bai , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] RDMA/iwpm: reject a port-mapper reply meant for another request type Date: Sun, 6 Dec 2026 17:27:22 +1030 Message-Id: <20261206065723.147-3-danjwade95@gmail.com> X-Mailer: git-send-email 2.39.0.windows.2 In-Reply-To: <20261206065723.147-1-danjwade95@gmail.com> References: <20261206065723.147-1-danjwade95@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 520-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 --- Notes: v2: document the new @nl_op parameter, which kernel-doc warns about at W=1. Confirmed against a clean control with tools/docs/kernel-doc. 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. drivers/infiniband/core/iwpm_msg.c | 24 ++++++++++++++++++++++-- drivers/infiniband/core/iwpm_util.c | 4 +++- drivers/infiniband/core/iwpm_util.h | 5 ++++- 3 files changed, 29 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..007d232982c84 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; @@ -96,6 +97,7 @@ struct iwpm_admin_data { /** * iwpm_get_nlmsg_request - Allocate and initialize netlink message request * @nlmsg_seq: Sequence number of the netlink message + * @nl_op: The netlink op whose reply this request expects * @nl_client: The index of the netlink client * @gfp: Indicates how the memory for the request should be allocated * @@ -103,7 +105,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