Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1950712pxb; Thu, 16 Sep 2021 21:18:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfIhsjOqpfejvhWpowwlPOLuJCzdREOGpTU59mEph2P2C7wCuy7ZMGtRr+/+N5UXWysa2W X-Received: by 2002:a05:6e02:cc5:: with SMTP id c5mr6404211ilj.110.1631852321176; Thu, 16 Sep 2021 21:18:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631852321; cv=none; d=google.com; s=arc-20160816; b=sWDXPEQgnR2NXen2pOa6WY64lV79NZf9Fy71LVDPqv9ZoIoo7saY9yquTcPfr9KLHh 66Bu6z5J9G7QLEkaaTfS2ZOFRu6pEDWOkLmk4sGgBsuesQs1s+3/gsB7QpGK46gFulo4 53/wWf+3qoD2p/8TUmtBr9B0gPqey7Aeswayfsp6lT3uQ9oD1H1Jf/m8BaWqpDDMeTnL T8IRipDKC4LTkjJ3cF8bNQ1ziyLClSfU4X4gcqoSZXMf+cZ1Jbsai4ujrmw7uxyo5ySj cAxQpD4Kn9/FnCPCkKKwXOm9h4Uy84KBIbNtf7XC6m+i5RPQjLbcl3QZ2WGLUbW9yrJn Gghw== 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=v3y4R+7+mY8rXrZhHA3bLhaoI0oC1/rWItI2mbPUBco=; b=rUsAHBGoy+LOie9FA4odHmiQVr2izWPEiKX7toK48l/iC6vS0shvGrgZd6P9soIqDb xnvU7zA3AJeWLwJelCXrGn4zkLOQkq36bgJ3cODA2zInEDTWlobTFAIszIO+elmf830h djeWqpQ8fQF2303BUpFROOTH1aK+XEudAQwtGO58gnLTGnpHKtepEsi79vqTTXbXQvJa tm5gTZrgs1IC5YiBGmuPmzUXLRzDUFn1xXWrPkdppTWvbxEYDIRUgCae+he9Qxnf/a/F 5XGUyBfZCwqaSkJdkruDvjXCsttUiFCXWxZzR7Tu3+5hdH7W9EEwl8a3HwUikAeUBQ8T flHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=omHmKDoV; 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 j11si4165637ile.34.2021.09.16.21.18.29; Thu, 16 Sep 2021 21:18:41 -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=omHmKDoV; 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 S244650AbhIPRgN (ORCPT + 99 others); Thu, 16 Sep 2021 13:36:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:47082 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352263AbhIPR04 (ORCPT ); Thu, 16 Sep 2021 13:26:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9880D613D5; Thu, 16 Sep 2021 16:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631810713; bh=wmAn7NASzO3JH9q1wnZ3WbFIdI3bcHKwprsxehcilEY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=omHmKDoV9/+M8L9i3Kcvq9hCtrr1xHZEj5RvXhTIL8O6hJYGusKJbxRGnDRVrlu6f tM5WvQExkEyTvfS1rZaC1YnCGfQO/tcSvF71lp4NhqPa0YXv5jMSfjCPMLhtShtYmV PiZNCGDtr73WTTsrxWOzJ7C7xFUGgL06p1kSJbjY= 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.14 241/432] Bluetooth: skip invalid hci_sync_conn_complete_evt Date: Thu, 16 Sep 2021 17:59:50 +0200 Message-Id: <20210916155819.001775369@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155810.813340753@linuxfoundation.org> References: <20210916155810.813340753@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 1c3018202564..ea7fc09478be 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -4382,6 +4382,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