From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.69 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796002416; b=3gE3ArhXFmEvjIK9srgCbsKeL6hOjzz/ArN1o/oDuW7/XG351yWoTcsTRehurJPyDU2e PLQtmfsH0rHorscLqzUCNGqb2rkiaUeyajA+IByw/hJSfOkEiTrCDH8UbQK+lM6luX53b lBeZ+hTgYDSukOsstRLO4EgxUHFOy3nJ3yNbITWmFPzEbbIt6xq32/0cnd8Fz5qjPuEHA UN3Ztj5V4XlaFZQtmWwjmJJsvJaGxI6Br/D+sbpTzPjmdA5SH9cll0AKn+wsvTEdUP5T6 U7py9/uLXO3tBp2FyszcagvnjiY6QSATy/7s2I0hDd56AbENLj9RWA20Dmr8JpPt+UA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796002416; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:In-Reply-To:Mime-Version: References:X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=7PT4e7lPV0EfpBXqL031W3htjii5S342AIlUXIkCe18=; b=azNOnhpTAiLaUYbSz2+9kAiwaj8Wf/+04792LkVgYuFI+kb5mKDz+C4TdQPe/+pCe/UN sQils0VA+iCU7BPGBn05/TLodEn5gpXGypIsbQFQwMS6yEhzvs8PlKTT07ocJ8mN4hv4y PiFNxwfiSA0TS7AGd9ST7N0rDPxsWFWdBm3NlWVLrpFoJ4mmKhR8ftFZkhgPtjeK8GZzL OhUiIMGNp8bI5df14tfQR+erpw0Hml630Kggk2fVFe2V3iY9/xibJcNT2TqGIxU9D1rbq 5PbhUyLTLViOBBEBsITsIFtrdw9xX5irpIEDJVASMfnILTasBOQH9B8/e9pvA7966hg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--jmoroni.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=nWfUxWXx; arc=none smtp.remote-ip=209.85.219.69 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (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 A394C606A31C for ; Mon, 30 Nov 2026 01:33:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A394C606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jmoroni.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=nWfUxWXx Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-9213237a52eso157188446d6.1 for ; Sun, 29 Nov 2026 17:33:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796002414; x=1796607214; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=7PT4e7lPV0EfpBXqL031W3htjii5S342AIlUXIkCe18=; b=nWfUxWXxtBuL4FE2qw5a6styYl1XrB1f6cugOkvNo9TV41UhFMaX1DfcuKNS6lK59N qRzB+u+A7qDBzWOWVXO6+4p72LYNjapwxAuuXyVz9Lv7NXlFqTpH2fPcGSh/sz1E7f31 2ivY/CLSOls3Xf0P/bY/4/tg5+giJOEBnAImoH/W78V0V94MmbDWYvB62MFpeJJPlUdx jSbunCe6Tjst1ePro3NVH4v9N8aSHJgM0WUWgX6dnsWDPYSXjbX5CkEJimTAXrFn9oOi kcgppog1t9qPF8N0II+0DiexG5DkHZ1EiKRIDeGQ9Stem2XqCdkWsTW4RqbQIYr97+Vp kbZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796002414; x=1796607214; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7PT4e7lPV0EfpBXqL031W3htjii5S342AIlUXIkCe18=; b=bHyW9Vc+MU9jTpvEgPg7XTN6wSePSyVEaN9on+a69Ll3BUx3x/AO5aeqUUIVPElzDq y/HNuVYwiMjFcIhNEQ6ZiKWky+WcwTiz6S/9Aw8SzG46ga3V0aP3Kz4RmfKil33pa1h6 GQ9iajfnP0rrdMYTJ2y2/e0W6l6kVp6RHjRcT1Mwx4dNDBtAYsdHTWz0OfZw7iHKvVRh 7NmEtOTzhDY2wYs5CYqMTauZwjghEmEjksfqVH4Yv8XUWkvfZBojhCGjlSTpZ0rSHQ4S l23BjYEwpO38hmXicljvMHwjDCcv+oEEc9+hGd5X9d5xd/4f255PM9OJLXgUUg9G9l34 HNcg== X-Gm-Message-State: APuU4Z/ALSPaIqkPVKpYoI+EKS7Kr04mXuUJGWizDlxYEb4bKWIa4hEJ lvMuVnKGs+QXD8irMSmx7NVlzsoUNi4N2+u5aWQb5nmT//SC2O8mE7rvNtJ0+AtQiSP5MhQHy4W p2i/n4S7QsA== X-Received: from qvbfi7.prod.google.com ([2002:a05:6214:1a47:b0:921:6405:b9a0]) (user=jmoroni job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6214:29c8:b0:91e:a629:ff92 with SMTP id 6a1803df08f44-92134b6cf95mr592442216d6.42.1796002414254; Sun, 29 Nov 2026 17:33:34 -0800 (PST) Date: Mon, 30 Nov 2026 01:33:05 +0000 In-Reply-To: <20261130013307.2848330-1-jmoroni@google.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 References: <20261130013307.2848330-1-jmoroni@google.com> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261130013307.2848330-7-jmoroni@google.com> Subject: [PATCH rdma-next 6/8] RDMA/irdma: Validate iWARP TCP header lengths From: Jacob Moroni To: tatyana.e.nikolova@intel.com, jgg@ziepe.ca, leon@kernel.org Cc: linux-rdma@vger.kernel.org, jdz@google.com, Jacob Moroni Content-Type: text/plain; charset="UTF-8" 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 --- 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