Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2560593lkm; Mon, 20 Sep 2021 18:44:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQjLKzGrZMJFDpOE3gaxojGw1VjeRRBflMFnWIwR2j7S2KkBORKR7OJ6CiTKWTmT75dUh3 X-Received: by 2002:a17:906:c20d:: with SMTP id d13mr32148753ejz.259.1632188691364; Mon, 20 Sep 2021 18:44:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188691; cv=none; d=google.com; s=arc-20160816; b=v2vj/q5SJywqEYSxPup93Bt4DKLk/Iyun5Hs9iS/8O8rw9UVikiO/093sbp+I6ispY SaIjuNP8mIokrR7GwJvNsc2eGxEGUd6ArCIUM/voG/n4lvfjSk2+pWpX+jEKgpUGO9E7 p+qAe9r9w+gHECe7BDIESTrQ34kCWOahtBuyHSqLX2QpcoMRU5y++NIhUsIuTNhvOVqW 94ZW2MP9HCe+T6fXy+j/IeH6IXifdkFGEbvxHYiYdhTnLJTvB5FY8/pylbsmAIS9jrgI tXF+37MqlGXK+79cprS5vA2As88NZWE+vV8GDS4HmwzB71sN38/cRKPDQnpKVD2Tdm0J YpOw== 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=pWKl8zs0q7RwRxuVD5Lz6SiphbcFFRI5xuzIcNr1p48=; b=tJYZv9UQz+jofskRYq28YsL+e3N83ubsUdByQu4CVjye+l1V0CSEJykubB9Q38VFHg Q9yaCLW9B9J99ezrjoh7yHSYAUIiKW3R32H7rRLn8TvG8MUq95Miv+5hE+1BnrGkZbkt xXX+v3IXDS1dHhqfVQjjdHuugH2kJFCb7kblqN/UspX7ra1/r3gRtnM+GmRusAEoAGaQ 8QyJeu+BZ+1dxQrQxuqHhOItcbcegImsYyHEg/54WlSVQwEo1caz4jYJ1aaFNwfrVAmO uTdFCG/Yr/7NeiDqWnCCoEj56joOxENm/RypBTFu+CH2t45l4FEvIB2vfhCg1zu+KO3i alNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Zk8SX9T2; 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 q14si17473837edr.585.2021.09.20.18.44.27; Mon, 20 Sep 2021 18:44:51 -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=Zk8SX9T2; 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 S242078AbhITQxy (ORCPT + 99 others); Mon, 20 Sep 2021 12:53:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:39722 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244474AbhITQuY (ORCPT ); Mon, 20 Sep 2021 12:50:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 902E96124A; Mon, 20 Sep 2021 16:48:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632156537; bh=P1VZTvoePBSG6pc+gLrIfstQ0Cg98NTAGUfibfgaOLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zk8SX9T2i5JpQ/DQsBQ6kiXk9Pe4OTWthEhRJCcTZB7D/7b9yHWMz/ZGJs3phQ1gT fvmnmA5ox/OrGAt6Qwmnh9h5zE20BhG0r4rqhn5Nn5zF3R9U+GrtVn25+nGfITMT4F 1Um7cYyLEkWDoR3OzPfqeg9cSf1XeW9EedTAjlJk= 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.4 105/133] Bluetooth: skip invalid hci_sync_conn_complete_evt Date: Mon, 20 Sep 2021 18:43:03 +0200 Message-Id: <20210920163916.063064065@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163912.603434365@linuxfoundation.org> References: <20210920163912.603434365@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 7ed3c7df271a..6528ecc3a3bc 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -3747,6 +3747,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