Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2567489lkm; Mon, 20 Sep 2021 18:55:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxecmV0+QgjOsrtY+a3WsNKghO4Y1I1TchPHRs82P/UagYNJrA8KlElQzSczZtn/B7E43oF X-Received: by 2002:a05:6e02:1beb:: with SMTP id y11mr19312338ilv.134.1632188866887; Mon, 20 Sep 2021 18:47:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188866; cv=none; d=google.com; s=arc-20160816; b=raq16V2Zl81GrIolGLYkts4OsOrTgcgCCaMyImgPLs/UHsVx1eywE75S9tTutR/myi UdIcVr1878IoK+FAtDTmJJE4miHeCqrI4T52wPvHfmRQIFHy60qdw4BRAD7Jz0HmZ8nZ qkXv4vP5MFPi9bS8NnvHmqx1j3bnSxfZ74e16tnw1qJK08SVNPotdtekCD3TRAQiducC 2onDJUc9EFd3edc0s7wFJGeP6HRyE6AJVlRHgG3w01BuPgRuotqoKgbLOvWWKhkZ6fYZ yR7xfLNhvlEDk0ZL1jff49jR6tJlHaOZKzrpCd+JV1tR3zldUIci/E7ocW02Towsw3Ik bitQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=n5J8+01Kfeio3FDicfCubJGg8xUkcHk+BGClSeqPQV8=; b=NbTlyyq03tSpsZ+AlFH8+KBZYrJnjOJ9lDusIzlcPHvdBQHPuns3OZwNYjzRmIqdj2 Y0EBxi4UmvYIeNxQq7pRd53GWbqU0uzI9b1/UaJ0+1qGn/9ZjAGsKyDtl/9sSLsGxiS1 6cNQ4yGwPKDgFlTLjNWgWyzpuVshnPnCq3DxQCoI4l/EVpO5+Md1+B9iO4nHBIBvFTbD izTFG+HjN0M91D4UAsrCeUTTzSl8q1gw/er8WcGgxTIIQZJ0hooxYLlxDD8S2PQ6TN4x l/oh2slcMpDwEe2/3Bjh0eDC8SSSutlNb5pKrXPE/1MgwbOpcfUY0aeJLNtiihRV/Pu7 T5/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="1/TZ+1jy"; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l20si584833jad.72.2021.09.20.18.47.32; Mon, 20 Sep 2021 18:47:46 -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=@linuxfoundation.org header.s=korg header.b="1/TZ+1jy"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344242AbhITR1a (ORCPT + 99 others); Mon, 20 Sep 2021 13:27:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:56974 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349845AbhITRY5 (ORCPT ); Mon, 20 Sep 2021 13:24:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 62D5B61A8A; Mon, 20 Sep 2021 17:02:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632157328; bh=9OsgcUcU6CeRPqG5bL4ROrMvmMSpM/tU+23LLjiTJOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1/TZ+1jywsmjZoi1/kKPZPodLEgBo2DPLgbnzI84a2EB45jowdeJ229vL3patsvfl I0pcfMFgj1fmgCbxUN1qL30i1m5897OVY0qersjeqTOHjR2CB1YlKPJXowA4iA/AXn fgEWdzQ5kkyfcs5IudjivShgkLTZzuYipE/foo1k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+66264bf2fd0476be7e6c@syzkaller.appspotmail.com, Desmond Cheong Zhi Xi , Marcel Holtmann , Sasha Levin Subject: [PATCH 4.14 158/217] Bluetooth: skip invalid hci_sync_conn_complete_evt Date: Mon, 20 Sep 2021 18:42:59 +0200 Message-Id: <20210920163929.999140462@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163924.591371269@linuxfoundation.org> References: <20210920163924.591371269@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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