From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E9DA4D98E3 for ; Wed, 13 May 2026 17:53:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778694814; cv=none; b=bFrx+7GvsMwVHS3Usk2zQcvTL2AB3eIPha44Fnf4kHyA0lFX0831miFd6pNCveuxmLkXrb8vxTfNv/HtNvsC4Eu0Id2pRb4JlVoRoUtTUi3Ri13vQyrprjqc5ROI9U6wkEE5ix34msQoIwxJ3WnIGHVkgSJQUF8I2nyRihnVY24= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778694814; c=relaxed/simple; bh=EQ4MYxskE0lYtC8XPV/NocVxlYCWxw9+uUFSKNZhNpM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nPl6PP4EqLWAQDQwr4tJ+1gkVUqkFoHJ8lJjGGyW+Ps2XGEBPnBxM9dJ4DnYbLo1hdEvdKbluXhcCZ9YTcF7SmknsByjGk3YjryZmpk2qInukYu6H8+1S3gNQrmNppaN12oqO2nDbjo0IzN2yQd7oaFQnmjHGPVRDaGsynOs5Ko= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MudqVIS4; arc=none smtp.client-ip=209.85.219.54 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.b="MudqVIS4" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-8b81586dff3so81621276d6.1 for ; Wed, 13 May 2026 10:53:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778694809; x=1779299609; 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; bh=5ayiddnyLyvk5j8vikm+y7Z1odGVhjZ1CBk7OhZOJKg=; b=MudqVIS4/mF7LlQ/QH1Zw0rLQ8X4SLJ3djO/+ryidarHfdiNuuRSlJ5TeMmiY1Y7qa T+libQKQ+ApHnrM/KCRb8bkVeb271DV1eCup3DtLnHmqmtqeDeLU42EGS7B8YjABIkKD FxgOLe2mHevjXaLaabOXp0BtuatAF3jkffzoJE83OLq7CKvVU5gxZX+tXoty8Zdlyf/y XGDdg8Rb4OxCq5tI3gfZlZ6tjfPZ6LuztsdHqgwf33MItmyKW7kenhBEYfO8yDRNP6TJ qrATCDxhtCuxi+tMg7TocEUO/BgpmjNaJ6tfBIqjc8TsSgcC2QPFbujxOhgOLpC/Q7ui w0cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778694809; x=1779299609; 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; bh=5ayiddnyLyvk5j8vikm+y7Z1odGVhjZ1CBk7OhZOJKg=; b=ZmA4rm4NrvOnFDcjKCcMv46Exr1v8vNGzkrHHHvlmiRtA2rW2B3AngeYLz38qUCc1p Y1mzomnsTBRorkwR/HYbtn4kdqRcgoerXgOF3l6KvtI175SBBKsOO+l1ebKhI+kMMA8S +FqvPT4RQGPc/YFq6JXBfgFD2YkkuA0Cot84z5KBlXjNCd510lZJ4Fnq5Uh49FejyYNU HtLUKLocoB3i/hr/tNUh5E+tXHOO+MuHsWRR+BzAeQ0Scw0qPUEHWO5hpoATPrS1GeSL L6jgkKKlx6XDZRsjSPd+Aa8ecm+GtzmhBBEopMQj1BwmTaguZnwfppY0eWlI+S6DiyUQ 6F/Q== X-Gm-Message-State: AOJu0YwTVF6TCXLn8dJ7OZsZAJIepzS/000+2iwUTzTFUEyovgMlE0sC 937jx3zJhC1vRCdduFDKwidO0l/+3sShz1DtVGvkHu8NFffAiSsmo5q4 X-Gm-Gg: Acq92OEKw2cfOO/iIBGcCzpBtg7Nbl7lirJMCttyxrG32zlu3ntxvoA96k56Bc/iG4S h28/rIL9JCqxeez2V8XokRwm1d6elcfHHdP/jfHnv7LOXTz9AysLkdzSR7KhHU4u7511dwHP8ca A3xw2kpIsFrbpjcKGXzPDtbUWv/7jq9Ogt2fn8HevXBhfB26Apmp97cwIkSd/gEw1kOJR4IyZ+K ld/7dCsMwOcRDaV3BhCek2EQyJiOXTspuWVu41VqeebJpyuSP8vgC7MMmV8LjKj2tQAllYyyBbl ZaDInEjE1JdHp6rXZH1w1O2uA4xtjQgKLlFe6BolcVMF7xqPxwokqmOCEZsGyiEY6BeVFi/jwP0 Kjlv5czo9nRjqG0SCGBYsztVj0Vh/zHzWsKI4NU/C5cea/ADlWYMI2xmhQi6/qDbM1RrpxrFWmC DD/0t3O1VGOKzKnG0qc+BZcbCkKyqcbeelBLqK/bst7eXIAMgQqeKU2RhYY7iSFKGdi0/HduOvV ye/xBgMiuae3CGB+UdIxhBgm8fqVrZo6n8DXBGXiXJs2yKJi2FpVQ== X-Received: by 2002:a0c:f119:0:b0:8ac:a689:34ce with SMTP id 6a1803df08f44-8c7bdc83746mr54170006d6.45.1778694809391; Wed, 13 May 2026 10:53:29 -0700 (PDT) Received: from server0.tail6e7dd.ts.net (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8c90bf6720asm2036946d6.39.2026.05.13.10.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2026 10:53:28 -0700 (PDT) From: Michael Bommarito To: Bernard Metzler , Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/2] RDMA/siw: reject MPA FPDU length underflow before signed receive math Date: Wed, 13 May 2026 13:53:24 -0400 Message-ID: <20260513175325.2042630-2-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260513175325.2042630-1-michael.bommarito@gmail.com> References: <20260513175325.2042630-1-michael.bommarito@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A malicious connected siw peer can send an iWARP FPDU whose MPA length field (c_hdr->mpa_len, 16 bit big-endian, peer-controlled) is smaller than the fixed DDP/RDMAP header for the announced opcode. Soft-iWARP parses the full header in siw_get_hdr() based on iwarp_pktinfo[opcode] .hdr_len, but never compares mpa_len against that header length. siw_tcp_rx_data() then derives srx->fpdu_part_rem = be16_to_cpu(mpa_len) - fpdu_part_rcvd + MPA_HDR_SIZE; where fpdu_part_rcvd equals iwarp_pktinfo[opcode].hdr_len at this point. For a tagged WRITE (hdr_len 16, MPA_HDR_SIZE 2) the smallest on-wire mpa_len of 0 yields fpdu_part_rem = -14, and any mpa_len below hdr_len - MPA_HDR_SIZE underflows to a negative int. The signed value then flows into siw_proc_write()/siw_proc_rresp() as bytes = min(srx->fpdu_part_rem, srx->skb_new); is handed to siw_check_mem() as an int len (whose interval check addr + len > mem->va + mem->len is satisfied for a valid base when len is negative), and reaches siw_rx_data() -> siw_rx_kva() / siw_rx_umem() -> skb_copy_bits() as a signed copy length. The header copy branch in skb_copy_bits() promotes that to size_t, producing a multi-gigabyte read. KASAN under a KUnit harness that drives the real kernel TCP receive path -- a loopback AF_INET socketpair, the malformed FPDU written via kernel_sendmsg, sk_data_ready firing in softirq, tcp_read_sock dispatching to siw_tcp_rx_data -- reports: BUG: KASAN: use-after-free in skb_copy_bits+0x284/0x480 Read of size 4294967295 at addr ffff888... Call Trace: skb_copy_bits siw_rx_kva siw_rx_data siw_check_mem siw_proc_write siw_tcp_rx_data __tcp_read_sock siw_qp_llp_data_ready tcp_data_ready tcp_data_queue Add the missing invariant at the earliest point where the peer header is fully assembled. iwarp_pktinfo[*].hdr_len - MPA_HDR_SIZE is exactly the value the siw transmitter uses as the minimum mpa_len for each opcode (drivers/infiniband/sw/siw/siw_qp.c:33), so this matches the protocol contract. Out-of-range FPDUs terminate the connection with TERM_ERROR_LAYER_LLP / LLP_ETYPE_MPA / LLP_ECODE_FPDU_START -- which is RFC 5044 Section 8 error code 3 ("Marker and ULPDU Length fields do not agree on the start of an FPDU"), the correct framing-error class for this inconsistency. Fixes: 8b6a361b8c48 ("rdma/siw: receive path") Cc: stable@vger.kernel.org Signed-off-by: Michael Bommarito Assisted-by: Claude:claude-opus-4-7 --- See cover letter for full root cause, series rationale, and test summary. [2/2] adds the KUnit regression harness used to validate this fix. drivers/infiniband/sw/siw/siw_qp_rx.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/infiniband/sw/siw/siw_qp_rx.c b/drivers/infiniband/sw/siw/siw_qp_rx.c index e8a88b378d51..34d03584160c 100644 --- a/drivers/infiniband/sw/siw/siw_qp_rx.c +++ b/drivers/infiniband/sw/siw/siw_qp_rx.c @@ -1081,6 +1081,21 @@ static int siw_get_hdr(struct siw_rx_stream *srx) return -EAGAIN; } + /* + * Peer-controlled mpa_len must not underflow srx->fpdu_part_rem + * in siw_tcp_rx_data(); a negative value flows as a signed copy + * length into siw_check_mem() and skb_copy_bits(). + */ + if (unlikely(be16_to_cpu(c_hdr->mpa_len) + MPA_HDR_SIZE < + iwarp_pktinfo[opcode].hdr_len)) { + pr_warn_ratelimited("siw: short mpa_len %u for opcode %u (hdr_len %u)\n", + be16_to_cpu(c_hdr->mpa_len), opcode, + iwarp_pktinfo[opcode].hdr_len); + siw_init_terminate(rx_qp(srx), TERM_ERROR_LAYER_LLP, + LLP_ETYPE_MPA, LLP_ECODE_FPDU_START, 0); + return -EINVAL; + } + /* * DDP/RDMAP header receive completed. Check if the current * DDP segment starts a new RDMAP message or continues a previously -- 2.53.0