Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4328052pxj; Tue, 25 May 2021 05:40:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrrKGdrARPaNI8D5eeO1pybuvA5P/S7hPN+HR6mgKiNUMiBZH94O2BDw3HHbc16QUkZNof X-Received: by 2002:a05:6e02:e42:: with SMTP id l2mr21026289ilk.189.1621946446501; Tue, 25 May 2021 05:40:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621946446; cv=none; d=google.com; s=arc-20160816; b=eniwdoUOr6ex44p87LaikxezkpyPW8/WfIy+tTOor18RU62zG9/o0vOi6XSIlOSksE w1cMoToHgWxyiaI4oE48d4fKwZqGcJYA5kKN96AFAeiwtyKS+hPcqDF4NnTWAk9HJbtu i8QuNzKWTxnpjCbLmUgsjwFiyV7twFB1I0VHQGL5Jaj3rYYMKGzSc41hlhhG29IYeI1D 1m0PWNTxf0k5kmGrjM1loEQCNLke7yrijcVCZji6xEeXRakcoMFUh70B6uGBxfJp1fR4 5gNSVyQ4jo8ZQ1E1TzmaOrGPaq+jW6C6mjwS1qFgHsXvYjWvPcm0CNAXl0W42uVb5NLj Flag== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=8t0Knn+pT8E4l2pWES3yC32JlH2HFXy/IJqkww03/ss=; b=tJJeADjmNm3UKCJF4z0kl76vyScqi0NMjnbtoZQnw0UFfLywCxomE4Jz3NXyrau7eX HK9yOQQ8f7PJAgVnzhH64SgBvREi2RQ62VNcq6dKPL0U1RGvrdbFmUS0hV19t/c6+qdp aMYZ7PTqS6QyixlyERmF/cbpAE9q5EO4XSsMrq0DrKxEUAbk/4AmydH5mcM3Mv3oAPuJ yQrfChPcYqLP9Zak/BKBBDoHu99NQmfS2JoI8P6n91ve3AJwzCr0MoGCNiUiCUGuUEJm gGb//MCj0QAF4u2bktAXZzW3q0s0sSAyMqka07btFzhC85UWbLE19dRgL39T8UDhs9yn GvEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gNLVIVut; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-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 u9si18859749jat.83.2021.05.25.05.40.16; Tue, 25 May 2021 05:40:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-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=gNLVIVut; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-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 S232633AbhEYMkg (ORCPT + 99 others); Tue, 25 May 2021 08:40:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:40224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232627AbhEYMkf (ORCPT ); Tue, 25 May 2021 08:40:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 89B276140E; Tue, 25 May 2021 12:39:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621946346; bh=/vZdsDJghPOhaskyihnVquOx0gtCUPIcL1HHuW88hFw=; h=From:To:Cc:Subject:Date:From; b=gNLVIVutCdom27ITDvkbnAvDdHFCcWeovKJxvbAx8OuZ50fbUPimBfRsfZU39D/18 IARkHgE25Kuvh+Q3irzMlVJaAfJURHqC7yYIMHQz6yVVg1R0bEksfBJqzlxUYV0v/B B2AiyTddBVSVzTIH2N1pF0ijGpZ0wBVyLHXtiflk= From: Greg Kroah-Hartman To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: linma , "David S. Miller" , Jakub Kicinski , linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Hao Xiong , stable , Greg Kroah-Hartman Subject: [PATCH v2] Bluetooth: fix the erroneous flush_work() order Date: Tue, 25 May 2021 14:39:02 +0200 Message-Id: <20210525123902.189012-1-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: linma 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: Greg Kroah-Hartman --- net/bluetooth/hci_core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) v2: use "network comment style" for block comment. diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index fd12f1652bdf..7d71d104fdfd 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1610,8 +1610,13 @@ static int hci_dev_do_open(struct hci_dev *hdev) } 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); -- 2.31.1