Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1700607pxb; Thu, 16 Sep 2021 13:20:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWctaLuwfEzB0qigypHV1OG86WIhIeGTA/vNzGKZ6HMlW+ARpQnnlETjxAcmQtbgLoUC6f X-Received: by 2002:a05:6402:401:: with SMTP id q1mr8687553edv.154.1631823641199; Thu, 16 Sep 2021 13:20:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631823641; cv=none; d=google.com; s=arc-20160816; b=JCOOoTXe5IM0/OJ8jRZI0UIXc80Khy5pcDlpfZCOlKuftXrB+UKx4HfgIeRv/u7YzA tGf3+9wpi2O6y+/BC3aiRgpUnKmuJ4K+UR+JBKNz/zzUK4lKyXMVg7Pi4ioFZtwW+g7Y TjuByE2s8nGPognOITEO+iwENQHpeC2SwX+S5kIWQXowbfphwaLsLsIclyCVp9zPK9CD GpogQhozwv/H2cBSjlXc9otB8Lwbwo4h++9/1PFVtESMBkNlwATw0tAlB0Mi8N1/ABOn zGPB+axpjkCru1I68xbr+XeP3umsqNS1MqmROiJZFsZPYYxDFVPf5pxAIbXHitZ5EG+Y Si2g== 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=zPmyKb3K3A4SGb5SHBioN1xIYjn2/fU5pNBqDrXAeq4=; b=Ch6yY+1iaQkF+5LX2nF/v7rxKHWmqlOqzlv2EKdlBYTqfmCE9FDx6ndTNBxoMC9yl7 EIDSqfGqB0Hkme3cVH8QBXnLtyO+ZJgmsFoq3pbgJIsHkOrlE+ozSucO1qclax5H0dkz 5aNyGjTi9DRUatZi7l7J8o0Sb9Tq45Nyt9KlQEgDBdC1h8MTq9OruKrop23vwrHmH5EI N/Jr+vJ/OSrNKmmQx7bl8GEd3NwrNebntijiMAvDzAtkvFtlkzoq2fLsgMYj097nyANO CxOIfbQ81JKs0jySR9qbZiHjhmV9HTHt4xbm9/QuqDybgyD2qVkWOat6mLxIgWFHXPu+ DTew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cA5uts9d; 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 p21si4494167ejn.785.2021.09.16.13.20.16; Thu, 16 Sep 2021 13:20: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=cA5uts9d; 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 S241030AbhIPQXK (ORCPT + 99 others); Thu, 16 Sep 2021 12:23:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:54068 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240907AbhIPQOh (ORCPT ); Thu, 16 Sep 2021 12:14:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 941DF613A3; Thu, 16 Sep 2021 16:10:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808648; bh=klejh/9wfTb9XMMgayDstx9flj94xl3OvGfJIaG0G7Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cA5uts9dUq1RgMCIOqvWbFt/wnCnTyzvq6m1/WYJJ/ujMf7fMwGaMevDlPJ4gUmZU Gvxt84SOTVciRhT0mDk2KghES0Ua6tBj4WcboE/FrfTHtlAKT1Zkp6C3DapBkx1HPH 8pd+iRpdYEMi2d98sqYt4v23/bGj2+KsvyTyO0I0= 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.10 169/306] Bluetooth: skip invalid hci_sync_conn_complete_evt Date: Thu, 16 Sep 2021 17:58:34 +0200 Message-Id: <20210916155759.844579681@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@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 e59ae24a8f17..45de2d8b9a9d 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -4329,6 +4329,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