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 6/8] RDMA/irdma: Validate iWARP TCP header lengths
Date: Mon, 30 Nov 2026 01:33:05 +0000 [thread overview]
Message-ID: <20261130013307.2848330-7-jmoroni@google.com> (raw)
In-Reply-To: <20261130013307.2848330-1-jmoroni@google.com>
For iWARP, raw TCP segments are delivered to the driver via the ILQ
and IEQ. These segments never go through the kernel TCP stack so the
driver must perform its own validation. The issue is that the TCP
header length (data offset) is used without any validation.
If the data offset is below 5, the computed options size ends up
negative and irdma_process_options() walks past the end of the
segment and if the header length is larger than what was actually
received, buf->datalen wraps and the MPA parser is handed a bogus
length. This can be hit without an established connection.
Fix this by dropping segments where the TCP header is too short or
does not fit the packet.
Previously, header parsing could only fail on GEN1, so the error path
in irdma_puda_poll_cmpl() needed fixing as well now that it can fail
on GEN2.
Tested on an Intel E830 in iWARP mode by sending crafted SYN segments
with a data offset below 5 and with a data offset past the end of the
packet. Both are dropped, and a well-formed SYN is still accepted.
Fixes: 915cc7ac0f8e ("RDMA/irdma: Add miscellaneous utility definitions")
Fixes: a3a06db504d3 ("RDMA/irdma: Add privileged UDA queue implementation")
Signed-off-by: Jacob Moroni <jmoroni@google.com>
---
drivers/infiniband/hw/irdma/puda.c | 4 ++++
drivers/infiniband/hw/irdma/utils.c | 7 +++++++
2 files changed, 11 insertions(+)
diff --git a/drivers/infiniband/hw/irdma/puda.c b/drivers/infiniband/hw/irdma/puda.c
index 4f1a8c97faf1..46eb10d6c9dc 100644
--- a/drivers/infiniband/hw/irdma/puda.c
+++ b/drivers/infiniband/hw/irdma/puda.c
@@ -373,9 +373,13 @@ int irdma_puda_poll_cmpl(struct irdma_sc_dev *dev, struct irdma_sc_cq *cq,
irdma_ilq_putback_rcvbuf(&rsrc->qp, buf,
info.wqe_idx);
} else {
+ if (!rsrc->rxq_invalid_cnt)
+ rsrc->rx_wqe_idx = info.wqe_idx;
+ rsrc->rxq_invalid_cnt++;
irdma_puda_ret_bufpool(rsrc, buf);
irdma_puda_replenish_rq(rsrc, false);
}
+ ret = 0;
goto done;
}
diff --git a/drivers/infiniband/hw/irdma/utils.c b/drivers/infiniband/hw/irdma/utils.c
index f4bc08ae0553..c2b89e166ffe 100644
--- a/drivers/infiniband/hw/irdma/utils.c
+++ b/drivers/infiniband/hw/irdma/utils.c
@@ -1598,6 +1598,9 @@ static int irdma_gen1_puda_get_tcpip_info(struct irdma_puda_cmpl_info *info,
}
buf->tcphlen = tcph->doff << 2;
+ if (buf->tcphlen < sizeof(*tcph) || pkt_len < iphlen + buf->tcphlen)
+ return -EINVAL;
+
buf->datalen = pkt_len - iphlen - buf->tcphlen;
buf->data = buf->datalen ? buf->tcph + buf->tcphlen : NULL;
buf->hdrlen = buf->maclen + iphlen + buf->tcphlen;
@@ -1637,6 +1640,10 @@ int irdma_puda_get_tcpip_info(struct irdma_puda_cmpl_info *info,
pkt_len = info->payload_len;
buf->totallen = pkt_len;
buf->tcphlen = tcph->doff << 2;
+ if (buf->tcphlen < sizeof(*tcph) ||
+ pkt_len < IRDMA_TCP_OFFSET + buf->tcphlen)
+ return -EINVAL;
+
buf->datalen = pkt_len - IRDMA_TCP_OFFSET - buf->tcphlen;
buf->data = buf->datalen ? buf->tcph + buf->tcphlen : NULL;
buf->hdrlen = IRDMA_TCP_OFFSET + buf->tcphlen;
--
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 ` Jacob Moroni [this message]
2026-11-30 1:33 ` [PATCH rdma-next 7/8] RDMA/irdma: Validate iWARP TCP option lengths Jacob Moroni
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-7-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