Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4733262pxj; Wed, 9 Jun 2021 00:02:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5s7eOC03TYm9r6EZx84cqUmsfilMbCR/xURK0NTkse5jCNjCG6W5OqcwRJlHs1Z9QCDNY X-Received: by 2002:a17:906:394:: with SMTP id b20mr27140162eja.108.1623222128960; Wed, 09 Jun 2021 00:02:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623222128; cv=none; d=google.com; s=arc-20160816; b=zjhHeKyVUKVhYjrrzrDtipCIA1pHySZeK9UzRbbyF9jBfub2DzC8LvoV5nadYBg675 Ser4r/eQnj7QY1nCk5d8GhT5GrPdnGbSwU3jeZXIwMq6LMT+KvaeQFVEoNJmzrk/Kdi5 IK9zDqgl8Z/6NYKl3uvxOpAsLB189bYMnenAzN7Ib/I5gLdACd/hn7+h2TdKQl+Hr9BM 0CsAM3xc2MQ1MiIVKhjkqN6NNu/CTBHPW8QHqyd/3KmnAOS5/8mGy2yrX+Xk7zzSJV1j yEm1gz9AJXeeBcttX5TIaOc27A7dcgM2EN3m4HANNMST1+toYCLuxQdYyh9k+tj+K5fk EwtQ== 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=ju0A6jnol2yFE2p+mMgiz7ftJ5qJP8g7rigUGccXwmc=; b=cw1hXV2STAFS93QFLNhsv2ubPk04bJI+XAslbEE7aLO89GxPBAvqhEh2W+ecVn+ICS q/zeFR/rLe8zpCmmRYHO6UV+ts7ywo4+yn/zwXE+2Gs2z2WesQnYIteQnHCgHzwbE+Ns hvqw5jXQiVtInpWKpcj6lDLYZ7HMvzsjH4cnKQ3br6t6oemc5YpgoPMkoA/IpOVawc/N kRPz+h2jPSKWpVNOaj5rTyzfeyY0htsrXUYTuFm56YIufAhgkiRILABtVADTitXEpMBl lklNJI9vO4hQDOpPFEJFfmTcKhKzHuRAN585AOjpFlPNmkRc2IRiE5o+zB5IFPFjWSBg BZZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vk1h6wdd; 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 n16si1499891edq.422.2021.06.09.00.01.45; Wed, 09 Jun 2021 00:02:08 -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=vk1h6wdd; 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 S234872AbhFHSff (ORCPT + 99 others); Tue, 8 Jun 2021 14:35:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:56768 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234649AbhFHSdr (ORCPT ); Tue, 8 Jun 2021 14:33:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6A407613AE; Tue, 8 Jun 2021 18:31:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177095; bh=OyIcUR2R8BanA9DlHP9/ePstJ4qAecFtfjXxNMb7Gz4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vk1h6wddbpayADBeeLecja2C8jPpYjhtFZRGivG6ItwnFyQUnWoJOykmvqGLPpEU7 B1KQHvcFXnek1T2PFbfgew2uM6lRZpEO7jMA7o3JkZ5x2TQ4/lfzA1Hc+PanydCg0z ZEBn+uf0L/vhPq9ku+7TSKsbpX0dBs6CuJJfFPtk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , "David S. Miller" , Jakub Kicinski , linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, Lin Ma , Hao Xiong Subject: [PATCH 4.14 13/47] Bluetooth: fix the erroneous flush_work() order Date: Tue, 8 Jun 2021 20:26:56 +0200 Message-Id: <20210608175930.918559811@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175930.477274100@linuxfoundation.org> References: <20210608175930.477274100@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: Lin Ma commit 6a137caec23aeb9e036cdfd8a46dd8a366460e5d upstream. In the cleanup routine for failed initialization of HCI device, the flush_work(&hdev->rx_work) need to be finished before the flush_work(&hdev->cmd_work). Otherwise, the hci_rx_work() can possibly invoke new cmd_work and cause a bug, like double free, in late processings. This was assigned CVE-2021-3564. This patch reorder the flush_work() to fix this bug. Cc: Marcel Holtmann Cc: Johan Hedberg Cc: Luiz Augusto von Dentz Cc: "David S. Miller" Cc: Jakub Kicinski Cc: linux-bluetooth@vger.kernel.org Cc: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Lin Ma Signed-off-by: Hao Xiong Cc: stable Signed-off-by: Marcel Holtmann Signed-off-by: Greg Kroah-Hartman --- net/bluetooth/hci_core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1458,8 +1458,13 @@ static int hci_dev_do_open(struct hci_de } else { /* Init failed, cleanup */ flush_work(&hdev->tx_work); - flush_work(&hdev->cmd_work); + + /* Since hci_rx_work() is possible to awake new cmd_work + * it should be flushed first to avoid unexpected call of + * hci_cmd_work() + */ flush_work(&hdev->rx_work); + flush_work(&hdev->cmd_work); skb_queue_purge(&hdev->cmd_q); skb_queue_purge(&hdev->rx_q);