From nobody Mon May 25 02:56:03 2026 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 686CD1E1E16 for ; Tue, 19 May 2026 04:20:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779164448; cv=none; b=boWjKdf22ezwxhcE5tcaCs0PY5R8LS36jz93sePnhtpTNnhePKykjtN+gNC+kQsM8YY6PDcQq+0LLoDoZRjxgjwujWimDhJ0lshSTTILNwAiXot8XnzQa79adOlU/87oFDs0q85PXOCAdWH2cEpTy9vwfDhiqSgyOwKayZzswpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779164448; c=relaxed/simple; bh=LiV0xUqYF1sDgcQ4JGiJk2vaMfz4EW5Z764wJBePVXg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=t7tb6awl3pDSuydToh/aIta0t6U+80Oc1gn1TkcJyHYNis5aiPot7Whl6w4p6df72v8vlPvxWZmrdagQ7kgDdg90KkFoBa3VsUVLTmGkSUy72zmwOqra16gfJINcG0a32rqfpuX3loRYTrOdpSPzCpyCu/kJa5Q6JBRlwprTYx8= 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=mN+9HMmP; arc=none smtp.client-ip=209.85.210.180 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="mN+9HMmP" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-83945063f70so1926664b3a.0 for ; Mon, 18 May 2026 21:20:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779164447; x=1779769247; 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; bh=YUFBQc52UJfk2XrsTn834tkvWEs3F4USHaB2v8AXGtk=; b=mN+9HMmPwfWflA/7V+bxot6Y4Hn438kqmFqWq2bw80NYUjYm/3J1Gxto+O/muGvWuo OxJUihMzIi5Alo3NMs2cw2VHEIbgU4Mi/dwFz2ycRazpYswheoQUQ1coLAFQ/ojOZNwr LCv+SSpzQIxl4ufz6zbZbaM3Jcgvds6sIgICsa/9OymWQUqZ4oZzM9DaVBp/9NjNW0wb WcDvOVCRbbsOApabXyUjWNfPAiOioOTj9rJbh2p1uA/XdO88/+LIpluveUIwOFNyHD2z ECaet5dPLoOKGWT/tSS17wzKjnTGjxxmNi+7oKIiMyUJnUYXIXzz7YnqshMxPSJTrNmW tPLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779164447; x=1779769247; 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; bh=YUFBQc52UJfk2XrsTn834tkvWEs3F4USHaB2v8AXGtk=; b=sGzDsa65ucckCWLx+2tBWFz14KB4DO8HZtzxiPm/xUXmtmcD6PgEK1fBm/0Qmg3hjJ 6iETwQQhGRht8xlYVlnJLUEn3xCp8D77QqbmsMvuNoogTJAAE+YgdqoYk0IwUCwX6Yam ZFASqTJpU4vp7sm1aLKRe6DX1B0wnLoiMq2x/0NKric3i0d+0NSDrPekTelPtR/udNiX jDVdeoU3GxxEMuQgH0WUSofjjKexmkNG4kLEfuNqtzuUluO61KcDlgYuYtslo7MzBD2d AobkLXPvhYPGqCxEmYzuviCbgeJOI5yiC9pxgRESi3w0MXKeRN3hkuW9C1ILt0T4SZrV b8Zw== X-Forwarded-Encrypted: i=1; AFNElJ8ivnhL+yAxGIiGOlxAO9G33c87dwF4OrBLqkEfNRTD9t8Yf9IyJviS3HWzsKXrAtgrp3GWm3QWPk6bFAE=@vger.kernel.org X-Gm-Message-State: AOJu0YxMPqukkZAufu8bwGC+vew5e9jPMSWmueFsZ0KEhIHnjGXs7om9 qEsMm7bc0GQjNmlNJwO2Geg9qJv11+Zy05dhHe63LjMjcyKYKb7XezqI X-Gm-Gg: Acq92OEQeUC+IBi/IffhEUUn+0rKECjaUV02V2O782LopsdPmjIjqIPJxVZe0+M6jub S5gaA3MoobYXHg6KVG28Tzg8M0Pnf5pfz33Kwqx/opY8yzJHtjtupQez2IMnTwJIYr8hnXRXDc0 fYttJ038SqBjbbXJFbdLfB3+vgpCq8nmRH9hjaYqrs9Vm9elj1cacelFWFtHRgdS45HdJfF0xpf c4bdrziBpN0+BYb2/5r6Is9olpzugzlaRsvXAuY25GfDw3PBror5rYLAb7ugKO8yOwp0kvwwOsu kVGKCMcnMrgiL4xpnZx6MUxlOZuEipqZVnuPMv3K0bggg6898iivMDL7eHRP0twVjfbWZMPFeSj xvdMaB3Av2zIIxJB4UmeSrpHPVFxDJuEiWM6wkVCtwDaMizz4w9J6eE9nKg04BZS/E06JiR3JVP dU2vQi9qGoLuJxk91nCE9MIt/7xgsSG2pudhR6b15yI54p5FxDXqfMh0HY5mpucfuCb4ojIAGmA A== X-Received: by 2002:a05:6a00:2394:b0:82c:7420:82bf with SMTP id d2e1a72fcca58-83f33c8a27amr13455006b3a.19.1779164446475; Mon, 18 May 2026 21:20:46 -0700 (PDT) Received: from node ([202.47.63.86]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83f19c5b4bfsm16929148b3a.28.2026.05.18.21.20.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 21:20:46 -0700 (PDT) From: Muhammad Bilal To: linux-bluetooth@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Marcel Holtmann , Luiz Augusto von Dentz , Kees Cook , Jakub Kicinski , Muhammad Bilal Subject: [PATCH] Bluetooth: RFCOMM: add minimum length check in rfcomm_recv_frame Date: Tue, 19 May 2026 00:20:17 -0400 Message-ID: <20260519042017.29564-1-meatuni001@gmail.com> X-Mailer: git-send-email 2.54.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" rfcomm_recv_frame() casts skb->data to struct rfcomm_hdr * and immediately dereferences hdr->addr and hdr->ctrl without first validating that skb->len is large enough to hold the header. A remote device can send a crafted short RFCOMM frame over L2CAP to trigger an out-of-bounds read before any session state is checked. The FCS trimming code that follows compounds the problem: skb->len--; skb->tail--; If skb->len is already zero the decrement wraps to UINT_MAX, causing skb_tail_pointer() to return a pointer far outside the skb and producing a second out-of-bounds read when the FCS byte is consumed. Add a minimum length check before the header pointer is assigned. A well-formed RFCOMM frame requires at least addr(1) + ctrl(1) + len(1) + fcs(1) =3D sizeof(struct rfcomm_hdr) + 1 bytes. This single guard prevents both the header out-of-bounds read and the skb->len integer underflow. Note: SeungJu Cheon posted a related patch that adds equivalent length checks inside the individual MCC sub-handlers (rfcomm_recv_pn, rfcomm_recv_rpn, rfcomm_recv_rls, rfcomm_recv_msc, rfcomm_recv_mcc). That fix and this one are complementary and independent; neither subsumes the other. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Muhammad Bilal --- net/bluetooth/rfcomm/core.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c index d11bd5337..6b300237c 100644 --- a/net/bluetooth/rfcomm/core.c +++ b/net/bluetooth/rfcomm/core.c @@ -1741,7 +1741,7 @@ static int rfcomm_recv_data(struct rfcomm_session *s,= u8 dlci, int pf, struct sk static struct rfcomm_session *rfcomm_recv_frame(struct rfcomm_session *s, struct sk_buff *skb) { - struct rfcomm_hdr *hdr =3D (void *) skb->data; + struct rfcomm_hdr *hdr; u8 type, dlci, fcs; =20 if (!s) { @@ -1750,10 +1750,17 @@ static struct rfcomm_session *rfcomm_recv_frame(str= uct rfcomm_session *s, return s; } =20 + /* Minimum valid frame: addr(1) + ctrl(1) + len(1) + fcs(1) */ + if (skb->len < sizeof(*hdr) + 1) { + kfree_skb(skb); + return s; + } + + hdr =3D (void *) skb->data; dlci =3D __get_dlci(hdr->addr); type =3D __get_type(hdr->ctrl); =20 - /* Trim FCS */ + /* Trim FCS - safe: skb->len >=3D sizeof(*hdr) + 1 >=3D 1 */ skb->len--; skb->tail--; fcs =3D *(u8 *)skb_tail_pointer(skb); =20 --=20 2.54.0