Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2565420lkm; Mon, 20 Sep 2021 18:51:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwr/lcM0f8Ah6bTqUEVoCP2TaH7156DBRi+XHGZ0OmrtNx+oHTsqRJgWOpSsYlBqZM9yNNw X-Received: by 2002:a05:6e02:12e1:: with SMTP id l1mr11019000iln.286.1632189099230; Mon, 20 Sep 2021 18:51:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189099; cv=none; d=google.com; s=arc-20160816; b=XexlAkRR5HbaJPzg99ASCRe7UeQRUe6G5voUwemje04IOy+9AiEfsbXIpcNU+8Q66q EQynYmGlk9MDSE3sYH3l3kKcA+d1I+4dh08PdYiPrgE5bydd0qPmd5xCkWL1vhEwpNsy WhXDGPabsebB7lSesexSKvulvEdkqx39MZosJL6U6kkI7Kx7Ajhd0yCYmkTf6niA9Ucb lq9YhAsa6AHHfe4ExhLaT0O8qT5jXQMgfzka2pAq8rseBehZK1XFaF4YW4+lJkjVMkO2 jxYKb++WRIk7A+vNtId7qNS6ERcdrHkZq0NGPji9bUvFqRru/P1NG2B6iNInXoQMNWvS cZ3g== 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=tjGOHx7MLK8NjgYYMMVrIjVn3AIBySt0W6g9q3vraJ4=; b=L44YQV0OP0Ju1opQlaniGMPavSsMB/ww1yHWy4cwRbyXwTMqODlsUQtbnpr7v/5flO A6aC+qIRQt6VbdmZrnK4A2E+F8CWE0kd1voTp2r5eqg8Ya/Xa0X9zDClHnWJ16u+xPHN tiuF4xkFipNOZBJ1ykbern4EuRoY3HIDqh9r8SoQ1dDmGUILLABghjaAYOLNOuwzpESq 3D27YvguTP51LdKRpCdpqaEVAcEdZeYFIgCeDuVBrJjWKvYQS+QQVnlIlVRRBGZK38w0 b95C5B8s+th4PpqGV/XOLBoZkec2aMxbD8jsqLfpxE0DBeFP3xm3ot3TS6OQ0UaxeUkF qXJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Utg2ABgq; 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 i3si16835214iom.99.2021.09.20.18.51.28; Mon, 20 Sep 2021 18:51:39 -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=Utg2ABgq; 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 S1352664AbhITSNR (ORCPT + 99 others); Mon, 20 Sep 2021 14:13:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:35752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359121AbhITSJQ (ORCPT ); Mon, 20 Sep 2021 14:09:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E599C61A2C; Mon, 20 Sep 2021 17:19:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158345; bh=9OHCdoC2zS+9x1XGxywbtw+tpN9NjKwHyk7WhAEKvX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Utg2ABgqApOhLRU+cvBx96zdLSa+04xA8Yz5B6JHidFPpSHRLzZprm2BIP78QyMYK QDxYvv+1XlytuC3X+eYyLeABaD+D9LLbge5L2HKkQ2jcKSHOKZBF1l8xUNyIuKpmvl aJORACtiV0EfD35SmEzEVQKwVoOCWCQ5gQ7NQoEE= 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 5.4 112/260] Bluetooth: skip invalid hci_sync_conn_complete_evt Date: Mon, 20 Sep 2021 18:42:10 +0200 Message-Id: <20210920163934.940572991@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@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 e8e7f108b016..82e42d8e2ea0 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -4202,6 +4202,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