From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796540270; b=gFpkhNESktqmMVaXV5wgJ6k8zDAM2fXmBxS+iWiZ/5SabY98Z1FmgQcI7T9bPon4gHS7 3CHvkoZ3+LimD4ApNvH1xHLxukJvN+2yaKMSEuVYLeAHA0W1iG9guWRpJLnqNQEfHHf6v ypfbs6T5p2RLpcY+IQqyxqld+gusC/nKYeP5d+8dWJnpbczJzTrw9JjHxWeVHrZF5LjZz E90G6e4DNkCQyA5sYa3TkKXEiOseGWIirO+eVID+Kckqj/XnDRPE60/I57x/DJLkR3sXR K18ev+nTGIrWByWCMZ7Uvu6UxY0FBYMnn74nPovv1JW69GqtZDakQepqIUrA/AIQyrA== 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=RqQY4Q13OGX7H2VInu+wlpD0RhWkJ23WOOvGb+IasnQNdM0gyyVWgPPPG4jhhImcX+OK yyNZRK/TMvOfOEId/OxJXVXRN3Mss7PqnidY9jwZOURgCOg+1CLWwz9tz7tmgypoBYsp3 czsBAv2iuQeegHTInYd84TI37hNfq3IoMIG148Y370/yn3glu1GboMor22Te0JYdcYY4m AeaUw6oI7v9HoO1576HuUgeZh6WC5PiKMoiTSANBrSK22OmNNnqnzUosWUvOFoC91bJS8 vX7jE+v7e1O7o6qRjZFdH7mIzwBt4J9jQuhHrpkSLNES2EtRd9E+jFwABKt9rO7VyOw== 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.54 Received: from mail-dl1-f54.google.com (mail-dl1-f54.google.com [74.125.82.54]) (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 55002606A33B for ; Sun, 6 Dec 2026 06:57:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 55002606A33B 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-f54.google.com with SMTP id a92af1059eb24-1aefd1bf74aso1504255c88.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=Lcs4yeFkNQNzD9aYnSXX8qvKCj+q3ItLSXReUVVacfM0RAEtlifSBUcBmWSkE+4fsk Jpz5o/ae0bGhuM0lFJH364afFJt2qOeDot+YyG11hNTl87c+gYc6VCSlYFDyqNb3PFd6 aiGOOB61aj+U5mXGHRvQ2C1/Gj8rWOhvypGSFAF4B2ai+h8BYQmYglDR2yNfTXccIMc6 mBi8IgMi2OYW5lZBW3v95pU0SJkPSdPio+ne3iAqcx+fSRjKG8RKdmgpYZ9kFM98Vlgl 9EyRj+MFfcZolkUay1HwXH4JqyLAdIA9bA8Pg0llHPjg8pZuSyMZtefEto+d3qxwpFlv srQQ== X-Forwarded-Encrypted: i=1; AL+hErGh6fMD3Gq87hCJPiTg1ahMTiuD5S//elzIA8sDPEYnQPGF5D51VQLLDvK28Bg/LFrx7eg46ZpZi5fm@vger.kernel.org X-Gm-Message-State: APuU4Z8RvCxwlhEiMqBSurPt6KtJRCpJnr7VgQchVJJRhvQTPlZE/y+0 R2xR7eboF64tTSL3JjRRTIaoRAPpJkg+eZTYRmBW9ZYRh5n+ZAnn0mGR X-Gm-Gg: AZFdTZfPc86kR7+sVgC+wNJJHMZX9XeApvum6g72jw6HD05qmEkNL7SxauP/9TZ1OjF xEtMyMQOqZ81rulz7IMem10JCE8XcZdaReEmnAJXm12VNOOiBqO9hbMsHcSqhKFeNwpGXDrgXtA agohScwaPHpuRgeV3wohtnALEUIC9oAi4GCOR3+wyOC8VeEVoxMGCDeC8TN9sUIP8CFfA+lx2MA JvKQpjTh3U0COiBgoMgHhtvZDe1KjmqoEpFJmlYMhaYDL+uwXuDT1m7UFvX6aeRyJtFQoN2HqLu h4F6zbPkhCx81yBRRcxnMq4ifkPYJInAYCW2fAiUrYG90UTJmGpCQfj9lkaQDGwnZhdeGfgPutW Wl+L8D8bMjS7h33yoSyghC4i5Wp+Ygslhu0kJS4Uonwrl7L3HTyT89SA+9BqKYD2IlJxNmTYfgf zxs71Evtf6Y5CpdzxB26VepEd0MDmUvHeoInf2HToqg50q5sHQQFaLyvKsKxZVdKDN560e9SksV 1Ct4cu2e42j8abfeSdFiJxRI7u3E4hZS6qSwSTAWhGP9GU21aTDlRMVYsDVTlC7S45z10k5pmnc s4tirX41L/uWQGlMSYPSBk44KfiaqxRzvbkMCtYZnLIcrq1ysJUrtTljSW6lxySdAUU87iTXMEv DPTkjCWBgJ+C735h7qTCNOoyMlSzx5PhR7KycG3G5rvQWcAf4XipOOoSvHJsLyr/yIodj/bB7x4 jTI54dklpfdqYgbAuPOgQ3d32OuT2Kpa/AErIfDqpZSBr1KMuMtWCtUOeWJepH4drtJbLUsB1W+ dAf23Vo/NcQPZ3XWYdGIeVBCKc+pVuAomGXUz4/BIywQ8Y0egNQCiQ= 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-rdma@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