Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2519294lqp; Mon, 25 Mar 2024 00:51:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWLkWuaQs776Y78Zp9/kkXKbbZHZh0XuQugTnyoIBVQbeYN1R5rwiC660SU3A4V4EtzTjdmzSRGHzHzwhSE0kDOq9oj7A2LneSd8LmUiA== X-Google-Smtp-Source: AGHT+IE0xlKIyl3fm4t/BT+dNZ5fJTyZA7mU+AfoIuV8bRJfWD2UEgTwOMthtgW+Tzdkl+aP3Z0i X-Received: by 2002:a17:906:32ce:b0:a47:11c1:92d7 with SMTP id k14-20020a17090632ce00b00a4711c192d7mr4250614ejk.69.1711353109642; Mon, 25 Mar 2024 00:51:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711353109; cv=pass; d=google.com; s=arc-20160816; b=06071XAFFAsk3siTpSN4RQlFiW7FExWeqILa7pKjkO8jG3uyvvcjcPcHXA9rKVFEyR RquIGleUT0ezcpzyeoYp6yjxBkXVK8VhlTM8DqcaPYMc7kJZ9UCBx3KrYfQvvtDfbfrn rjf6sKBIUyXxOSjsgvuYAW5ZH7by0CtFx91J7MWWgrFLwwgB9nSnhAUsu443cXSCjLks +3eCgmoLqjQXeNCcMEx2G0dSXe4H75T/TClt8ZdTWYoEAToWqBYmCI3eO1bWvuMRR7Pz mRJFvjQWyBzZ02vEaO6pImNAgKPWlShsUtFdEh+HsGmwByJGl9DXK9kzC83lAB3RoMzs Qw9w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=AQP3EB/XvEOluPGGOc99vfXKuU14/0LU0Z75sBaNh5s=; fh=MFSlO3JLsy2abFeZVLjChbSEy3kj29RxDG8EQ6yb+nM=; b=NK++vWTUB+bqYkB3f5gDWgqIYQLPbkcvPy6bm8WbiPxr6zQtkz3Y2ZQbYGQy/zFBv0 gJRh8T2z+KVn+dRhxSVZKd212jfGjjxChKOhxYYJMmzAsUuIZ1YoknX1EDd8Hpn1emfs t4htX2E+15k14opTbYCNwnLofmV+EggVIQC8iMQ5UNnl06+HQKeGRG5wn/bL1k18TYim y9WVcocDOeT/tGlxHqu558kR4FP9AF0VOHS9w2sekJTSLw3jbLq9PDhMj8uU82evDaDd G70GOR3+BbCNMgewit7znqfXYjsroJdigK4qz6vBXoKNLRd4Nfa8htQO3KiSDf+WFVxr G4Ew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NHOBafGx; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115598-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115598-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m3-20020a170906720300b00a46b9fdb7a4si2337503ejk.296.2024.03.25.00.51.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 00:51:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115598-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NHOBafGx; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115598-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115598-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 578081F2F7E0 for ; Mon, 25 Mar 2024 07:51:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F24B43456E1; Mon, 25 Mar 2024 02:48:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NHOBafGx" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B93DE1FD114; Sun, 24 Mar 2024 23:02:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711321329; cv=none; b=pT7mARhiJV0Kw+50SR5UYOpwY0XnWoE9KF6eEdAnWcMlM+WaE/awW0pQmMr65QU8BEYh4JvaiKAWid2tg2KT1B62l7wo/YJ7sLlPJ37lquC074S2Pcv4kWMSmALiYhylzVCUseL9CELBeYsXNF7hXbIz24k3KOQtcLx6YUw9oCo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711321329; c=relaxed/simple; bh=rd9CTn5d36v+u366AsJVE1eQgwQIsnkSjg/Q6MfoA3Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AvQvUpICJWf8l9uu09+BKYkWtlIHXs6rUGm0WR3JzMibRkb050y+g+jR9srd/xDsQwKvifeJ9FvhX6yKCFfBcjG9e+1uPnInyrGMXhHUfB9VLuk/4GRDSygnGaHCRdQgYsgOhI9sEkw5gfmQTlynHZp0+op+dL2AjVMBiM9TVQQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NHOBafGx; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F41BAC433C7; Sun, 24 Mar 2024 23:02:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711321329; bh=rd9CTn5d36v+u366AsJVE1eQgwQIsnkSjg/Q6MfoA3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NHOBafGxoE1Gieh1NTYOr6CIJu0suovL3o0t8kE2GkDR7OkVYt/4bJMemYyIdqpx4 IIoO48zPA5BBYHtbjwotTkl5AfeYgLnLR6+4fvU3kcjccggxI3QhgO43LU2l7jk0OW UWDe1gHmwBZw4ivWQ7tlsdBtjnwmCc39dKnoaGKwfNLTi93xkj7dD6d3a9KOENYJta ecO6EnQpZ7XoPqjGUukglZ3sWCxVjj7FVd1NZVAbQoueqQLlfseSnk7TpHiN+RwEFU hNz/5TQQ4JTyoyFppQnroB+LXbXBQT685mfQESzrWiGESkJQdNyKHlSPa/DTryivub RhaMN6I0DoBhA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yuxuan Hu <20373622@buaa.edu.cn>, Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.6 053/638] Bluetooth: rfcomm: Fix null-ptr-deref in rfcomm_check_security Date: Sun, 24 Mar 2024 18:51:30 -0400 Message-ID: <20240324230116.1348576-54-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324230116.1348576-1-sashal@kernel.org> References: <20240324230116.1348576-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Yuxuan Hu <20373622@buaa.edu.cn> [ Upstream commit 2535b848fa0f42ddff3e5255cf5e742c9b77bb26 ] During our fuzz testing of the connection and disconnection process at the RFCOMM layer, we discovered this bug. By comparing the packets from a normal connection and disconnection process with the testcase that triggered a KASAN report. We analyzed the cause of this bug as follows: 1. In the packets captured during a normal connection, the host sends a `Read Encryption Key Size` type of `HCI_CMD` packet (Command Opcode: 0x1408) to the controller to inquire the length of encryption key.After receiving this packet, the controller immediately replies with a Command Completepacket (Event Code: 0x0e) to return the Encryption Key Size. 2. In our fuzz test case, the timing of the controller's response to this packet was delayed to an unexpected point: after the RFCOMM and L2CAP layers had disconnected but before the HCI layer had disconnected. 3. After receiving the Encryption Key Size Response at the time described in point 2, the host still called the rfcomm_check_security function. However, by this time `struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn;` had already been released, and when the function executed `return hci_conn_security(conn->hcon, d->sec_level, auth_type, d->out);`, specifically when accessing `conn->hcon`, a null-ptr-deref error occurred. To fix this bug, check if `sk->sk_state` is BT_CLOSED before calling rfcomm_recv_frame in rfcomm_process_rx. Signed-off-by: Yuxuan Hu <20373622@buaa.edu.cn> Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- net/bluetooth/rfcomm/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c index 053ef8f25fae4..1d34d84970332 100644 --- a/net/bluetooth/rfcomm/core.c +++ b/net/bluetooth/rfcomm/core.c @@ -1941,7 +1941,7 @@ static struct rfcomm_session *rfcomm_process_rx(struct rfcomm_session *s) /* Get data directly from socket receive queue without copying it. */ while ((skb = skb_dequeue(&sk->sk_receive_queue))) { skb_orphan(skb); - if (!skb_linearize(skb)) { + if (!skb_linearize(skb) && sk->sk_state != BT_CLOSED) { s = rfcomm_recv_frame(s, skb); if (!s) break; -- 2.43.0