From: Jacob Moroni <jmoroni@google.com>
To: tatyana.e.nikolova@intel.com, jgg@ziepe.ca, leon@kernel.org
Cc: linux-rdma@vger.kernel.org, jdz@google.com,
Jacob Moroni <jmoroni@google.com>
Subject: [PATCH rdma-next 7/8] RDMA/irdma: Validate iWARP TCP option lengths
Date: Mon, 30 Nov 2026 01:33:06 +0000 [thread overview]
Message-ID: <20261130013307.2848330-8-jmoroni@google.com> (raw)
In-Reply-To: <20261130013307.2848330-1-jmoroni@google.com>
irdma_process_options() walks the TCP options using the length byte of
each option, but only the MSS option has its length checked. The issue
is that an option with a length of zero never advances the offset, so
the loop never terminates and the CPU is stuck in the CEQ tasklet. A
length that runs past the end of the options results in an out of
bounds read. This can be hit with a single SYN to a listening port.
Fix this by checking that each option length is at least 2 and fits in
what is left of the options. Also reject a negative options size,
require the window scale option to be 3 bytes, and clamp the shift
count to 14 as per RFC 7323.
When a SYN has bad options, irdma_handle_tcp_options() no longer calls
irdma_passive_open_err() since irdma_handle_syn_pkt() already does.
Calling it twice underflows the cm_node refcount on GEN1.
Tested on an Intel E830 in iWARP mode by sending crafted SYNs with a
zero-length option, an option length past the end, and an oversized
window scale. The first two are dropped, the scale is clamped, and a
well-formed SYN is still accepted.
Fixes: 146b9756f14c ("RDMA/irdma: Add connection manager")
Signed-off-by: Jacob Moroni <jmoroni@google.com>
---
drivers/infiniband/hw/irdma/cm.c | 58 ++++++++++++++++++++++----------
1 file changed, 40 insertions(+), 18 deletions(-)
diff --git a/drivers/infiniband/hw/irdma/cm.c b/drivers/infiniband/hw/irdma/cm.c
index bc30e465c670..b3394f084098 100644
--- a/drivers/infiniband/hw/irdma/cm.c
+++ b/drivers/infiniband/hw/irdma/cm.c
@@ -693,22 +693,35 @@ static int irdma_process_options(struct irdma_cm_node *cm_node, u8 *optionsloc,
u32 offset = 0;
union all_known_options *all_options;
char got_mss_option = 0;
+ u8 optlen;
while (offset < optionsize) {
all_options = (union all_known_options *)(optionsloc + offset);
- switch (all_options->base.optionnum) {
- case OPTION_NUM_EOL:
- offset = optionsize;
+ if (all_options->base.optionnum == OPTION_NUM_EOL)
break;
- case OPTION_NUM_NONE:
+
+ if (all_options->base.optionnum == OPTION_NUM_NONE) {
offset += 1;
continue;
+ }
+
+ /* Every other option has a length, which counts the kind and
+ * length bytes as well and has to fit in what is left.
+ */
+ if (optionsize - offset < 2)
+ return -EINVAL;
+
+ optlen = all_options->base.len;
+ if (optlen < 2 || optlen > optionsize - offset)
+ return -EINVAL;
+
+ switch (all_options->base.optionnum) {
case OPTION_NUM_MSS:
ibdev_dbg(&cm_node->iwdev->ibdev,
"CM: MSS Length: %d Offset: %d Size: %d\n",
- all_options->mss.len, offset, optionsize);
+ optlen, offset, optionsize);
got_mss_option = 1;
- if (all_options->mss.len != 4)
+ if (optlen != 4)
return -EINVAL;
tmp = ntohs(all_options->mss.mss);
if ((cm_node->ipv4 &&
@@ -720,8 +733,14 @@ static int irdma_process_options(struct irdma_cm_node *cm_node, u8 *optionsloc,
cm_node->tcp_cntxt.mss = tmp;
break;
case OPTION_NUM_WINDOW_SCALE:
+ if (optlen != 3)
+ return -EINVAL;
+ /* A larger shift count is treated as the largest one,
+ * as per RFC 7323.
+ */
cm_node->tcp_cntxt.snd_wscale =
- all_options->windowscale.shiftcount;
+ min_t(u8, all_options->windowscale.shiftcount,
+ TCP_MAX_WSCALE);
break;
default:
ibdev_dbg(&cm_node->iwdev->ibdev,
@@ -729,7 +748,7 @@ static int irdma_process_options(struct irdma_cm_node *cm_node, u8 *optionsloc,
all_options->base.optionnum);
break;
}
- offset += all_options->base.len;
+ offset += optlen;
}
if (!got_mss_option && syn_pkt)
cm_node->tcp_cntxt.mss = IRDMA_CM_DEFAULT_MSS;
@@ -749,20 +768,23 @@ static int irdma_handle_tcp_options(struct irdma_cm_node *cm_node,
int passive)
{
u8 *optionsloc = (u8 *)&tcph[1];
- int ret;
+ int ret = 0;
- if (optionsize) {
+ if (optionsize < 0)
+ ret = -EINVAL;
+ else if (optionsize)
ret = irdma_process_options(cm_node, optionsloc, optionsize,
(u32)tcph->syn);
- if (ret) {
- ibdev_dbg(&cm_node->iwdev->ibdev,
- "CM: Node %p, Sending Reset\n", cm_node);
- if (passive)
- irdma_passive_open_err(cm_node, true);
- else
- irdma_active_open_err(cm_node, true);
+ if (ret) {
+ /* The caller drops a bad SYN on a listening node itself */
+ if (cm_node->state == IRDMA_CM_STATE_LISTENING)
return ret;
- }
+
+ if (passive)
+ irdma_passive_open_err(cm_node, true);
+ else
+ irdma_active_open_err(cm_node, true);
+ return ret;
}
cm_node->tcp_cntxt.snd_wnd = ntohs(tcph->window)
--
2.56.1.839.g22a8290db9-goog
next prev parent reply other threads:[~2026-11-30 1:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 1:32 [PATCH rdma-next 0/8] RDMA/irdma: Fix validation of user and iWARP input Jacob Moroni
2026-11-30 1:33 ` [PATCH rdma-next 1/8] RDMA/irdma: Fix QP ID leak when QP creation fails early Jacob Moroni
2026-11-30 1:33 ` [PATCH rdma-next 2/8] RDMA/irdma: Fix SRQ ID leak when the SRQ depth is rejected Jacob Moroni
2026-11-30 1:33 ` [PATCH rdma-next 3/8] RDMA/irdma: Reject a PBL backed CQ shadow area Jacob Moroni
2026-11-30 1:33 ` [PATCH rdma-next 4/8] RDMA/irdma: Validate legacy user QP sizes Jacob Moroni
2026-11-30 1:33 ` [PATCH rdma-next 5/8] RDMA/irdma: Check user queue buffers against the queue size Jacob Moroni
2026-11-30 1:33 ` [PATCH rdma-next 6/8] RDMA/irdma: Validate iWARP TCP header lengths Jacob Moroni
2026-11-30 1:33 ` Jacob Moroni [this message]
2026-11-30 1:33 ` [PATCH rdma-next 8/8] RDMA/irdma: Fix MPA v2 private data length handling Jacob Moroni
2026-11-30 1:44 ` [PATCH rdma-next 0/8] RDMA/irdma: Fix validation of user and iWARP input 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=20261130013307.2848330-8-jmoroni@google.com \
--to=jmoroni@google.com \
--cc=jdz@google.com \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=tatyana.e.nikolova@intel.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