Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796002418; b=ewp5kLPDc33ttQbpLW/L7EwfVCaeaTK22yuxMA2M5vWfafSJC24vkw1KL4xDSJa0CKhT xJdBNHuJStqVvX9dfrEpyQSGS2tuS6ZHoH0nqDsgbj5UeTONDD4JF9lnyGDsLPNl6Ociv m2Ft64kuqQWa954r4eBUej12FY2RGMxQPtPjkcRrjorN50t9eZ4fpVp5YUgLuTaEy2YSL kszToC9IkwIsFbMuisciGG7eFGO88thgl8pR2/nO0WZ97XLjeTA57huXTQ8ymLLIAZNpg LW+JAJoblXthMrM+c9tc9BDSTq0ZvUo/9nTioIVtHhIHYWBiVp8yKFEuUy4Bobo14tA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796002418; 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=T6IC5BzZGHUiMS5wFKo/7XDiKZDCOwbfORWVD4gvrPM=; b=z2lpWaIOJxQYdy9wY/+DjmddosHPs/hdQvtkstWJhI4ybgWXflY7o166PNe1DsKCItrj lmUw1uwARQl/AezyiUmIXtC20Vt+nKLCfNovdxWwaOOi3IZcwS3TjeaQ2IA+Ji+/GvUhH dzxPiYV1mz4GvjTdqhew57/Xjb85FL6u72ZCxKIerft8aoSnnrw8Ddn5RgmrXpXuFM7XZ xBOGEfwogmXDSa0IfgnRFdiVJsVob/yZoRT2bwI68Wiylt5JVsuPH8N1wouF3tpqA0Zlv 1d72PoEShLpjz+s3qQCNEOLwV5B5Ukpp+AmQJdTa6xmWB2XJKDVYh1WL3izqqBqA7Cw== 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=CyANglgS; arc=none smtp.remote-ip=209.85.219.70 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (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 EF44D606A32D for ; Mon, 30 Nov 2026 01:33:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EF44D606A32D 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=CyANglgS Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-9210ec7cb34so105485746d6.0 for ; Sun, 29 Nov 2026 17:33:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796002417; x=1796607217; 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=T6IC5BzZGHUiMS5wFKo/7XDiKZDCOwbfORWVD4gvrPM=; b=CyANglgSaTG988rNXKT3pMNwlUQhCZZoAZh0M+w+5nDGbynmvZJvtj+7bub3I2yjkG NxzudH7I6fKITBoJzNkAEULoDgfyzT2Vyc46+5dLPKrNP7SyFbWYsfVS17NOoZnjZlAC 34wFt+pXIaewjvxEET79PDD7FeuQPbiLiMsEaHyPDN3gzocYOnD/d4NXBkvK78Q5gm6D Cx3c8uPIEmdDHTUkMuWMhw8TnblKjgFbqDWAZS0CE6bQT5PXe9GXTURm8G3TH6kygrBR rscQlOpltnnzPk4/N3H+1TEabSQZbxYnbMT6cblZf0UhzWpDxymJ45Qf4WqZp50Lm+24 73/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796002417; x=1796607217; 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=T6IC5BzZGHUiMS5wFKo/7XDiKZDCOwbfORWVD4gvrPM=; b=1yE5iukZUhpOrBeGsO2c3VGU7v/a911CMty416GrgoAlNpOIR0L5rQh59weN/5Qlz9 QDhJfAlR2eozrN5QsKTpfssb3unEHmH90jQCu+x5DYIaU/uHAidZyH0H3RD7ewneq1vl 7/XnXRx/m857qWbhix/vQg0VvD5X+Ia/bNjhUlbgenfrxO3xn1DUsO0UNlGBtRxfduEC ZGcLoeBJ1TN0TNDhJhYdCmbmVZTtOKbyMrHAhnX07OAaq3YF4Kw+nUYfAJe2iNVZ8/RC SgAQDAYl3LcdBoDzo2MKwe6G1YJqoFaXrYUd5YT5rjmvPPHTTbPfTYrRifC4aPhr9WHS ZchQ== X-Gm-Message-State: APuU4Z+/wmc8FIXvcsQGgNd15CHoefbsg47sgwyax/5gQJ8uGEN58iiU Lf/xkHJzYYr0iewW0nyJeOl37fNj2sbGd6N688qYd3BTnsVKL6Vc0ynzA0ovYmxOpWMrYFjfWG/ 2g31ee8Y26Q== X-Received: from qvbfe14.prod.google.com ([2002:a05:6214:b8e:b0:921:2c6b:6931]) (user=jmoroni job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6214:528a:b0:921:122b:80f0 with SMTP id 6a1803df08f44-92134b27629mr614559986d6.46.1796002416714; Sun, 29 Nov 2026 17:33:36 -0800 (PST) Date: Mon, 30 Nov 2026 01:33:06 +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-8-jmoroni@google.com> Subject: [PATCH rdma-next 7/8] RDMA/irdma: Validate iWARP TCP option 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" 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 --- 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