Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp517490pxb; Thu, 9 Sep 2021 06:17:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhEwWpUKzTUSnIn6KMAHKmjAZUzqty8XmJmQXZEqmJq7zI5YbkbRndboTw/vfTq5mCGfeV X-Received: by 2002:a92:cb04:: with SMTP id s4mr2301753ilo.130.1631193437017; Thu, 09 Sep 2021 06:17:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631193437; cv=none; d=google.com; s=arc-20160816; b=W0tli7QrPoVgr8+6pop2EpC45JUptfXvZuuMzgnlANa83XUjHHU79siSfeNUGSCCMH nGvhTuo9r8ZPbKxmYyVOyJQw0m+eqwsOCD/ubnJ4fppwk1vV2WwNzlefGQb4JzafIzdR yhzrfZQMCT+twdR27n0mTYNOEqY/8maeC0U4TZoUY21bAGmZzTgAOuoMMy6dAyO3W4PR yFlgP/oH5WcJtVulu9JpcVPL/XjuO4bQTSdpSYk0N9/cJ7S6yQogDGd22/Y5P7NonaWU 0pJpd87fZJU9Yqh3jZ4klF+McGtyv06N6PtejoE2miqeb2Bd+VKmPGVh6xFeYy+slRI7 m8wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=n5J8+01Kfeio3FDicfCubJGg8xUkcHk+BGClSeqPQV8=; b=Td5Gl0XIduZqWG4BuFsClCa5PdCMr+v3GN2DbqEo5nlvh9krbrHMLdCZAu7ZVA6ime GZlwRmIz0/1cmNW+Ttk105gPRUeCSXc6GN3PHDSkTuGWwDmnf4nBZmHlsgEDtzB0RP// tilC80PFQOA11UPRnzlS2FU7/x78Uw6VkCsw78S0MnjBx4ouNhyYXBPdND6cElboDbqr NWp2b0VUVae4SxD0mHo/3dWmQ29TSIx+dj28bAjok+NyTRCTjEBHeghAFB7+YLu5AFcE zHxzEB4m0IGyXGByCBfV/+hg3bUz6u+afADphh2rNZ7N2lrX4Zu+XSUyVZtRTXWCxvqL Xn5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZkBXYNET; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l24si1762296jaf.107.2021.09.09.06.16.59; Thu, 09 Sep 2021 06:17:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZkBXYNET; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359086AbhIINQL (ORCPT + 99 others); Thu, 9 Sep 2021 09:16:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:46262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357662AbhIINDP (ORCPT ); Thu, 9 Sep 2021 09:03:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5AB366328F; Thu, 9 Sep 2021 11:59:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631188777; bh=9OsgcUcU6CeRPqG5bL4ROrMvmMSpM/tU+23LLjiTJOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZkBXYNETYj8+hg7I7mX6cXyf43EOz21NxHrPD84BiAjWM8lVjDw94M8JJHu9PUu4o AxR3ewMiYKmqvXjeoQ8c6wxAyhxcVsvbHxpOgZ1G23FDTHQMKwj/hnpU75Dr0CE9gd 9xepuKLqM37Rv7Hxc/0/688+MV/PhreVOTn45O4bWBTimHiG8UXFvTHCa2NssqXj6L 28NtfnqLO+QJuvwJ/saGnzEz8/gKmM0olygZzNNXLtIc0GCJqTIzuQWWnFxTbu2Rsz zmmUajN4Jnhtyx+oGnqctSvIZMhFF87VNunRlUkcuRB9dEKIhlXL/aIi57il9p3qsH tMWCjMnri1wVg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Desmond Cheong Zhi Xi , syzbot+66264bf2fd0476be7e6c@syzkaller.appspotmail.com, Marcel Holtmann , Sasha Levin , linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 29/59] Bluetooth: skip invalid hci_sync_conn_complete_evt Date: Thu, 9 Sep 2021 07:58:30 -0400 Message-Id: <20210909115900.149795-29-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909115900.149795-1-sashal@kernel.org> References: <20210909115900.149795-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Desmond Cheong Zhi Xi [ Upstream commit 92fe24a7db751b80925214ede43f8d2be792ea7b ] Syzbot reported a corrupted list in kobject_add_internal [1]. This happens when multiple HCI_EV_SYNC_CONN_COMPLETE event packets with status 0 are sent for the same HCI connection. This causes us to register the device more than once which corrupts the kset list. As this is forbidden behavior, we add a check for whether we're trying to process the same HCI_EV_SYNC_CONN_COMPLETE event multiple times for one connection. If that's the case, the event is invalid, so we report an error that the device is misbehaving, and ignore the packet. Link: https://syzkaller.appspot.com/bug?extid=66264bf2fd0476be7e6c [1] Reported-by: syzbot+66264bf2fd0476be7e6c@syzkaller.appspotmail.com Tested-by: syzbot+66264bf2fd0476be7e6c@syzkaller.appspotmail.com Signed-off-by: Desmond Cheong Zhi Xi Signed-off-by: Marcel Holtmann Signed-off-by: Sasha Levin --- net/bluetooth/hci_event.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index b3253f2e11af..5186f199d892 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -3761,6 +3761,21 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev, switch (ev->status) { case 0x00: + /* The synchronous connection complete event should only be + * sent once per new connection. Receiving a successful + * complete event when the connection status is already + * BT_CONNECTED means that the device is misbehaving and sent + * multiple complete event packets for the same new connection. + * + * Registering the device more than once can corrupt kernel + * memory, hence upon detecting this invalid event, we report + * an error and ignore the packet. + */ + if (conn->state == BT_CONNECTED) { + bt_dev_err(hdev, "Ignoring connect complete event for existing connection"); + goto unlock; + } + conn->handle = __le16_to_cpu(ev->handle); conn->state = BT_CONNECTED; conn->type = ev->link_type; -- 2.30.2