Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2565166lkm; Mon, 20 Sep 2021 18:51:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMxAlnQnG96MguIwT7hyQ6pECDqkzcktj0c8NBt35KJzmxo0dlHDdK8M9oMhP6hJew14RY X-Received: by 2002:a6b:6704:: with SMTP id b4mr1265938ioc.121.1632188983855; Mon, 20 Sep 2021 18:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188983; cv=none; d=google.com; s=arc-20160816; b=G9kne4rAcKQZ9LhPCrVzD0CI4V1wEN0jYhbe0gRcV7ztZ27YWkmkmqGrxZX16Ab7M8 rl/jySeCh+OY6CbZoa+A+1Ocd186nYeyt/L9pAoX0U+7cIRYuchDo2O7/COgVhez16Zt dygwIot97grHWEBKQd6BEGkKrZSQ1WaW0qaGthH8un3yHGGCOrudHSpo6+s10GkPEUKy gpzBNnrj6HC8HVULTii7tLthvwy8ihTlJRA9CTGczIpw2q2ZveHo5ggsmKb1udTxM0Mb SVqRWEfv+/UNzezQIJhMJEUGhdL8vxM+G3UtBKd3EeLb2IbI3EW0ihVvYaX2jDcK1jq8 YDHA== 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=c0pYbqxxNKHj49hSxC0XsyN3V6jBrqwaMOjYUEzb0BQ=; b=LZJkNtH/Ky/Zzf0DnAg5/r3PL/jpwLpklDVBIp2hW5iE0FpWAI8HzG5q9Z56EMO1cM 41EdwhDqOLYd68qOIe4iJzbYy3hi6hHa7CQv/AAyC/CyZSAiQ21pX8yNzqm3L2gPO8tU lXempnVCKXIfXoMtWrnQcDcARw4jkUK+myVcW0fsu9TjJI2NKt8rb9PNHVeUrmpVzJBb 2dzJaCdRFGWrCM0EKoOz1FzMuOZpHq8W8+QWKNvnnzrlEXQk5+guxIRVDzHADMeoPgL0 J+JCSAXUJFGq8fKop8mU65Tz1UPrI5OaRXHmTklb9Vy0RmZ+RmoxZrHAy396JqnhGu/4 l6aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JVHdw89E; 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 d2si17232667ilg.24.2021.09.20.18.49.32; Mon, 20 Sep 2021 18:49:43 -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=JVHdw89E; 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 S1355645AbhITRzk (ORCPT + 99 others); Mon, 20 Sep 2021 13:55:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:53632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354395AbhITRtu (ORCPT ); Mon, 20 Sep 2021 13:49:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CFE5861872; Mon, 20 Sep 2021 17:11:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632157903; bh=jiKXfvgkyuHxQ+RIYMyD+/R8H8NZHouqkWZGnTRv5wg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JVHdw89E9iZ1Er4WHu3EIw5Z2DaVtX8bJtE4s6VLXftbovKQn7kpGU41Gfo076s+B iQA1qNz6KGoYijbNPbjK29HrmIyk+CtdOjYha5DzsUcvcdwurH1a8smNYRND4L5VZk xm4bgvBOMhUClJwaJsT3v3mj+EpRTyTr5vn9toOs= 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.19 203/293] Bluetooth: skip invalid hci_sync_conn_complete_evt Date: Mon, 20 Sep 2021 18:42:45 +0200 Message-Id: <20210920163940.215186991@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@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 45cc864cf2b3..714a45355610 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -4083,6 +4083,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