From nobody Sat Jul 25 18:07:46 2026 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 D90932FFF9D for ; Wed, 15 Jul 2026 08:20:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784103629; cv=none; b=o0QEfPVmjfqebZSBJdmgGAswQARhYo1np60yDsNe66pB5SOdkkHRe4a16kYz2rZ/cEXqwKSZo7PlNzm4/llapRKmKQ/jWmwu9UNGPWZrxac5fH4ispCYmlu3CnFOZdf4VgDTWmQZyJSB3GkAExN9/CHWx1s8D6HIwd9hAT7ajxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784103629; c=relaxed/simple; bh=bvwwW4R0N6grdlPYNqdz9MLWc+DG/FhVQKqmEhPbqUk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dxJVTQYLNomzAUk4c9urMXk2gpvxkyuBcqirVDi9GHx7rJZchj5bpexwsZ2kVs30aV0CKU31jGoYVwtG8ONczuTO+nVdhw+gMd1LLE7250Ntir1jPicI/0WDmE/k/31UhCygDJ14OMgsPrlOl4oRmFHiXt9WJBPIWwyApcJ0aJc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=0sec.ai; spf=pass smtp.mailfrom=0sec.ai; dkim=temperror (0-bit key) header.d=0sec.ai header.i=@0sec.ai header.b=cl9vi/Cl; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=0sec.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0sec.ai Authentication-Results: smtp.subspace.kernel.org; dkim=temperror (0-bit key) header.d=0sec.ai header.i=@0sec.ai header.b="cl9vi/Cl" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-47dec32798aso5274908f8f.1 for ; Wed, 15 Jul 2026 01:20:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=0sec.ai; s=google; t=1784103625; x=1784708425; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=JeyNa5yOVyOyuTQrDgjtAmBz1VuJ3FD4iF0lMD/jV2Q=; b=cl9vi/ClfyCuMOKE3Jw6Kvyq29f+9yHOd8WOdO2r75f8OFRWrnZFMP5ESYzh21edb9 R8pYEPa+2r9ZbLnsCTKhVzXM6ljL3l9JQZ1H3Gi7LlbsxN9588RHyARxb6uQmhmcV1gr KHeVwIbggH2+R4dj6DH+47GDKb4yjqAicmTWXus16ShTospouJpshqkoychLuRgwvY/h 6pMv59sC92f6QCAnt0XekJSorrGX78FSjo2LOOD4/54ZxIaHIcSjYvcMZPJSi1scik1K Ef+loQkAcdk3h2gy6m8I7fC0fvqQwgEdurPOZLszE1E7OasSXiUS1qE+d/F8beIy22FK 0VQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784103625; x=1784708425; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=JeyNa5yOVyOyuTQrDgjtAmBz1VuJ3FD4iF0lMD/jV2Q=; b=aA54xnjqEZ+4toc650X4C0RYGgVKMFMuTAs0HzRSdNbykvG52dSVa7uiYhrbm74TuJ QveVZROfAeHvZ6ApOqK6LZwStyiVJ+7T7dSjxA3VZJD/k2Ov/lRaxaK64pYTcljkM3FR K6iHlLyFhVQPar0TWUYh0NrxOFvHDej9mt3AXjwnKQ49N1Xynvj07XLlKzodrVfwducv f4mbm48Hdcjl8Q2vvWlS17fxhQa6Ry/pOeqQdnmUQuQvO7oVy2jSK/1h/pSot/c5YTbQ yQbuDYNO8MXyyF0UCaZqt90x+Rs2VPCifX8zsOk0orcNqpjPcMfQOc4hHTj8wupR0PuB jUSQ== X-Forwarded-Encrypted: i=1; AHgh+RomzGvauBYscx0qLCxEB6omr2z9piA0LryFAF7z5qefhO7NpDV1P8TbDMlZzTlIGntNAuBneELCJD6+axE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0doXx+9w+o/xzpwh16fHWcEzsynEmCnSSzXh53c8t2bDZ6XyA YED0AX8kSbkatSAkE7RhMcgZMI0WsaDtWbkS/Kkz+MjH/6E29u6iFPP7r+TWp88FaATq X-Gm-Gg: AfdE7ckABTqQ/u/SELy9mgl6yryOfJ/hn2fGZdw1MSFwWOlzuvyfTMlXnmAIAQP+nWh 9Af/tjyv5n8zcKVh7eMwDO9UXO3AdkSLUs7+C8X0axhQPtLPWUiYV+Vyh36oqYq5Adbc0J2U0xu 7LT2rlo0czT0Y7iovcGCC0GvB4lIAt+h6FPyTBMwwU8qThAqZeoCs+oSeW5S9BDJ6aase/apdOF EY9gA2MWX1tXNbbzg9bM6BpCWiw5ePRyxYb21r/lmWxT9P9H8WjnG8joDcAucAIrgCXsI/vV/yA Eglp+JCofesRslTP8/Pltk0wHeCAoVKduu4b+jGzVIEJ8mivM65Mem4AzDH1bSycRfiJysAXlKI /5wJrTLcyl4mjtGICFxRkA//d1AkENAEq6K6Oy5ObJOf0wPiHFu4QyAOUw/6G5OJ33Ko1EcG2cb 784s8Q9MJBePZ0HKIT8xZkVFmrW8LOGM98GnCi5j/dlNGpcNY14XJHtPYL+iNaQieoZ7/1zyxzH TjZhkDMrrAyBiAY8q8CMFv46m3Gu5Wo+1w= X-Received: by 2002:a05:6000:4201:b0:478:65a8:6305 with SMTP id ffacd0b85a97d-47f488a9beemr6540145f8f.49.1784103624560; Wed, 15 Jul 2026 01:20:24 -0700 (PDT) Received: from PeakBook-Mini.tail8e484.ts.net ([178.197.218.188]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f464a974csm16390049f8f.18.2026.07.15.01.20.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 15 Jul 2026 01:20:24 -0700 (PDT) From: Doruk Tan Ozturk To: jk@codeconstruct.com.au, matt@codeconstruct.com.au, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH net v2] mctp: serial: handle zero-length frames to prevent rx buffer overflow Date: Wed, 15 Jul 2026 10:20:21 +0200 Message-ID: <20260715082021.46315-1-doruk@0sec.ai> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The MCTP serial receive state machine reads a frame length byte in mctp_serial_push_header() case 2 and validates it upper-bound-only: if (c > MCTP_SERIAL_FRAME_MTU) { dev->rxstate =3D STATE_ERR; } else { dev->rxlen =3D c; dev->rxpos =3D 0; dev->rxstate =3D STATE_DATA; ... } A length of zero passes this check, so rxlen is set to 0 and the state machine advances to STATE_DATA. In mctp_serial_push() STATE_DATA, the incoming byte is stored and rxpos incremented before the terminator is tested: dev->rxbuf[dev->rxpos] =3D c; dev->rxpos++; dev->rxstate =3D STATE_DATA; if (dev->rxpos =3D=3D dev->rxlen) { dev->rxpos =3D 0; dev->rxstate =3D STATE_TRAILER; } With rxlen =3D=3D 0 the "rxpos =3D=3D rxlen" terminator can never fire (rxp= os is already 1 on the first data byte), so subsequent bytes are written past the end of the fixed 74-byte rxbuf, which is the last member of the netdev private area. Every following data byte is an attacker-controlled 1-byte out-of-bounds heap write, and the overflow continues until a frame (0x7e) or escape byte resets the parser -- effectively unbounded. Reaching this requires CAP_NET_ADMIN to attach the N_MCTP line discipline and bring the resulting mctpserialN netdev up, after which the bytes arrive via the tty receive path. Route a zero-length frame straight to STATE_TRAILER instead of STATE_DATA. The trailer/framing bytes are still consumed, and the frame resolves to a zero-length skb that the MCTP core rejects; the parser never enters STATE_DATA with rxlen =3D=3D 0, so the out-of-bounds write can no longer occur. KASAN, on a frame of 0x7e 0x01 0x00 followed by data bytes (before this change): UBSAN: array-index-out-of-bounds in drivers/net/mctp/mctp-serial.c:370 index 74 is out of range for type 'u8 [74]' BUG: KASAN: slab-out-of-bounds in mctp_serial_tty_receive_buf Write of size 1 at addr ... by task kworker/u16:0 mctp_serial_tty_receive_buf tty_ldisc_receive_buf flush_to_ldisc Allocated by task 152: alloc_netdev_mqs mctp_serial_open v2: route zero-length frames to STATE_TRAILER instead of STATE_ERR so the trailer/framing bytes are still consumed (Jeremy Kerr). Found by 0sec automated security-research tooling (https://0sec.ai). Fixes: a0c2ccd9b5ad ("mctp: Add MCTP-over-serial transport binding") Cc: stable@vger.kernel.org Suggested-by: Jeremy Kerr Assisted-by: 0sec:multi-model Signed-off-by: Doruk Tan Ozturk Reviewed-by: Simon Horman --- drivers/net/mctp/mctp-serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/mctp/mctp-serial.c b/drivers/net/mctp/mctp-serial.c index 26c9a33fd636..a5070ffa9a95 100644 --- a/drivers/net/mctp/mctp-serial.c +++ b/drivers/net/mctp/mctp-serial.c @@ -318,7 +318,7 @@ static void mctp_serial_push_header(struct mctp_serial = *dev, u8 c) } else { dev->rxlen =3D c; dev->rxpos =3D 0; - dev->rxstate =3D STATE_DATA; + dev->rxstate =3D c > 0 ? STATE_DATA : STATE_TRAILER; dev->rxfcs =3D crc_ccitt_byte(dev->rxfcs, c); } break; --=20 2.43.0