Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4339970pxj; Tue, 8 Jun 2021 11:55:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0QKXQsg3eltHX2oHX8mMiE+Ypqb7qul+0CuBuCjIgWyxFSld5COJyKvy6ZLk2vrDyJrma X-Received: by 2002:a17:906:1f90:: with SMTP id t16mr24480682ejr.297.1623178515124; Tue, 08 Jun 2021 11:55:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623178515; cv=none; d=google.com; s=arc-20160816; b=j5b7k3oqwJ5OPUqcgP1WBOgYtZ0agQEBJJ1THr727fzKaX+YetWErycrM7hkzZIo6E 3syhB6+EpqPBtHdZCrJes4BsPNDY/8TIDBRE5IAVHEmAi9wURDiGhbPadjsLbkhbBTvk YpvNa3pmCAL2cWKxLbb5rPCQ3LLPb5/bV2B4sNCDj09I0O2mLmjm4+J2oUfSnVF2Rhy9 eSTUC8U59U5W32fifE657d/XO6539U/bTHHmQk/KMDZOfjgT4pGN4r9PcJyTtsyRpRqH FNsTKjlyMkniCUXGBaMW9pPNzGVWaqfq1/Mhn2eoDqhTuWfp3M/XJBnWOXD0qSTMk6fP 5Wmg== 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=OVa7RLv32Bu5lG3VwYYoQzfhYDSb3kIIjmi4iRc1O6Y=; b=owxTeWmEb8UoVWNdkecGFbS6cQD/3U/MqMxI83kmUGTzq47jtJRzv1SGapbhfikCHe gJYGBUETHp/wfKUTgve7nkrdYULlUeJ66g13cIU/Vie+FnrLU0HYtP24uEdZi3l0Wn6m 53e/0q24PfUVZ1H7D0ovBIzHKs1WhYCNjk7bWulIf0oLJKg67vK9qNKTW9OxI4VFlZNW whNwRqMnzKEYejsqOH+JI1WyYSwbKRSxz6kvf7QorZCeGpe62XwJQGck4VqSsv1mXspk ZboiXil1+OlvlCMh0tb3sPbGygSPsZUv51vovxosJ11BR2O+vllxC0hETIZdOiVnvHI6 Id8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C5VS7pzV; 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 e16si438962ejm.5.2021.06.08.11.54.51; Tue, 08 Jun 2021 11:55:15 -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=C5VS7pzV; 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 S236501AbhFHSyY (ORCPT + 99 others); Tue, 8 Jun 2021 14:54:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:43250 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235211AbhFHSsI (ORCPT ); Tue, 8 Jun 2021 14:48:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B5ACF61410; Tue, 8 Jun 2021 18:38:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177495; bh=l2cEH5Bj5wuVRTFmKyahQA9mQ7wLXXDEffvEB2gHcwg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C5VS7pzVReDvn+eQoMIATwhcKXvJkCf+GgVwyw4kEmgICeKrR//dClZLUPFXcZte2 eOwsR0G7bESEd+TPxG4UoG+fa8jDUIRbxGpgPB8DhzOsw4hMhK0AROAlDxXeS3DmmM l4fnZMZw4HqNk4v6C+nuH5qT7ZBM89XL0+tjq01E= 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 5.4 38/78] Bluetooth: fix the erroneous flush_work() order Date: Tue, 8 Jun 2021 20:27:07 +0200 Message-Id: <20210608175936.544923591@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175935.254388043@linuxfoundation.org> References: <20210608175935.254388043@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 @@ -1561,8 +1561,13 @@ setup_failed: } 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);