From nobody Sat Jul 25 19:27:03 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 2F17747278B for ; Tue, 14 Jul 2026 13:03:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784034237; cv=none; b=oZFbkLb9HMfmzgdBSBb5q+4Wej2+3rR52ekiBLxyy6HjONBkS9IwQOHIo2PZ+0EbBC91SD4kAR8lxp0izd8O+4XuzCZKf7hX5yxPGy8YfimJO82c8phklcbUbANrX8lu07kR5S1FvqmVHlQCEcP+rS+PyEaTGI8gC24FwSr1hEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784034237; c=relaxed/simple; bh=+9LSkEaOqHP5J+gwKCY481xJEYJYJF7buSxUcCGkD+Y=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Cg0m/cSKYsil6lNUe7UjUYXVpHwlBj7eMZOoaG+AIAt8FKqd6OcjXjSilFK4XOVY+jRMKhlFUrqhcUiKeruacmjdtZheSD1ZPh6l29BbWI6grU4tC/lSYf4vIK+o6kPzjeuvAuZcnbCvtrcN/NqTIhdtiz9KhReFqfIT3BSrEfI= 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=oXNuM1us; arc=none smtp.client-ip=209.85.128.44 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="oXNuM1us" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-493ae59eca6so5469555e9.1 for ; Tue, 14 Jul 2026 06:03:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=0sec.ai; s=google; t=1784034232; x=1784639032; 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=QcF0L770TQKMQqDorbzgjGu6vJT+Lw4syVjdxxXe8x0=; b=oXNuM1us0X+T1LlQf5qFfxZTFuukMAx5HuDd/w/MKIKoGVq19fqeVU3x57f0cm8Cah LIhWDgLE8aH+KyAq2iKrCHVUP8hLN7eG/c9N2/X0qEMEoGTa6oaY3G9kBDghZwaXY0U5 fshcOKovEIbIjcshNdzTP0yfbO0Oc40zUPcLsasVvjivAQ9V4AX3BVGEEnq7+QAuNEiB FNgyo7sjQHVfrgdOKSJrVLBaqjuSgJ6kq1SmD+CqD9XT7BlFIOvp1M3LYbP49chPEjvz XFSIwbZmL9aDC5MqfwuleqLiHR783CX9QfW1fnOs/XLsHIiHEwyLnlGqJj9ZkGjeTaDT kzQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784034232; x=1784639032; 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=QcF0L770TQKMQqDorbzgjGu6vJT+Lw4syVjdxxXe8x0=; b=fBfwnt208cSA/Fi7IAyVOjkcU/j9EsI8/sM7E6QIunjTIgJeGR/sNz79ebW0LrYZMb Jpw6n9FfXXT9oqK4tIRhmVYeL07dfn2LRO5BfEbW12qEiaIQ6zSXAvYDcNNQY/EiHkmd 0sWtRJ558q6WxWWWHcEDOFi3Ko3fC8DhNVeLPv3LMkm7yvDsRaYoo+oC6a+xhxAaz7HG Fz+7m/CZPoymSeA7bYoa80abRID0eG3+l6uWJdwMv7z3tZJ+haGbSi+ywiYfe/Q8Vjoi FAcK0+rqwinC2Rq4eKImZeBdaDZG5dpbFjFwYw6bgP0ck6buJ1fDZRg7K4rzjOFQ4psV sM8w== X-Forwarded-Encrypted: i=1; AHgh+RrZ7qOh0/50YZupY/b4CRPxpzCo9AoDICgtGaDPa3DF1v7udMnt0oHmeXWhrEkJ3kxLgGURW5UFcLWO/9M=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6k2ntQzX7jnUfQuMQn/s+Ko3C1lcVDz1zPyvKjTjlViRw9SoN nSYMaUpLtwywD4gBJMhW7t76tJA8ov846LxJHVr8bU+9eE15zYiWRP1Al6lkN3FU/u6k X-Gm-Gg: AfdE7cm6OlEjrVBw8dGVY8UuP8kEnrFrMezkqqKv4RohW1jPtrCWYAaOKbEizXkEat4 6GigSiQJ4//5IauTZY68srsgt7mRnhNdo44EItpvWNK+zs6OsgbUNALZziCoyGmrVT4IODmOIjf cQRKGPJZAogpZ+nd4pWpCtx1thfuIizJ9OSOuoilDistTz0HhGTFQlmVr+FJChKzSk9fB5CXjnl H1jgcvHSaR24HTADTz9cvs6WRjAPGtGfuAOLDJHOQL4/EjTdEQ3pw1/K2kEvxEYSstY+9ZatD7O ippt36oyJs9JZhmIUEosb9HhTuYZNBrvfTYefdnuRpkGFN/2o4mdi92pKzSj59eiUsonXJsSpWT G693rYqpkfLavcKhqIaBJVvZR3rnyHcWqsxo18RmNq9M3Lq5gEyTQesRFizbyEpZinCYzTqQxCL poQFHFvd2hpDhTZhkUGt2hkEJiZxC+iLiaqxqWJ5c10T8dxJ0+hHdxRsMXxNspSm+GArK1XLVlc C5PP573waL91OQ51wXVDAEHFbIFTMxvUcg= X-Received: by 2002:a05:600c:e54a:20b0:493:a573:179b with SMTP id 5b1f17b1804b1-493f8829b05mr88159195e9.30.1784034231418; Tue, 14 Jul 2026 06:03:51 -0700 (PDT) Received: from PeakBook-Mini.tail8e484.ts.net ([178.197.218.188]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4950a2f951asm79484005e9.14.2026.07.14.06.03.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Jul 2026 06:03:51 -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] mctp: serial: reject zero-length frames to prevent rx buffer overflow Date: Tue, 14 Jul 2026 15:03:48 +0200 Message-ID: <20260714130348.72716-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. Reject a zero-length frame in the header parser, matching the existing upper-bound rejection. KASAN, on a frame of 0x7e 0x01 0x00 followed by data bytes: 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 Found by 0sec (https://0sec.ai). Fixes: a0c2ccd9b5ad ("mctp: Add MCTP-over-serial transport binding") Cc: stable@vger.kernel.org Assisted-by: 0sec Signed-off-by: Doruk Tan Ozturk --- 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..1e3d285c0500 100644 --- a/drivers/net/mctp/mctp-serial.c +++ b/drivers/net/mctp/mctp-serial.c @@ -313,7 +313,7 @@ static void mctp_serial_push_header(struct mctp_serial = *dev, u8 c) } break; case 2: - if (c > MCTP_SERIAL_FRAME_MTU) { + if (c =3D=3D 0 || c > MCTP_SERIAL_FRAME_MTU) { dev->rxstate =3D STATE_ERR; } else { dev->rxlen =3D c; --=20 2.43.0