Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2658910pxa; Mon, 17 Aug 2020 15:46:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwESs8jsUf6xZ3tiktxHeXGWbhGILTRwaADcyzkZt3jJGgjQALLkkhD4g9CPSNHfJm0ZNOZ X-Received: by 2002:a17:906:8286:: with SMTP id h6mr16881710ejx.341.1597704370744; Mon, 17 Aug 2020 15:46:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704370; cv=none; d=google.com; s=arc-20160816; b=E1PcgXhCQSPR1UFi9VMU4psPP8UwFgA6wrkL/bZvFfTq+FTJsE27OH0Wq48xZ2r+Y5 pKnOImjEawMTlcoZhxLCeA9FZ0tfZhBDKazTyw7yO+KS7vYPxoG9txgsynDc3KS+e/6C 7npCW884/mv7WbD4fya9jgOmbaIfEQxz9wZuEHIVN6BTkKg8fB33D8g7yDsJY4LLBw8X I4dXAiMDwunrema24TZA5hbTuAgm1YuFlMeWIMFMFfkepm6+IvFzCA07tZceZdZGpsYN Y+yg2AmwB35evcwYX1vLrSN2eM9fuc2qLsFVfEll2oKuWwu7I7Mv8aY3WAbeXXFPT48o tWtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YbNVykYGKjzfxhS0KQ13Y7lnymD/2QfFnxDsYBAAih0=; b=T/RPVFboM7fcsG/rbSR00HbCgZDm43JC6X5Y1M/LXfv+y22Cpcfg8oaWp4Ixt0Yp0C knH7DYve+h+2ZdAR6UjSyd6E3mfo82fFPv8Q3SBjz6e6Vp6qEIWQ8H080SHF5XFKorI2 SKC/AtyCplcJT9JFbDhefpmscWLJUo94xoEFWEaVMHkz5X0Sq8wdoFLZsOZ0KBmMof6v 930rvXiJoNMSQ9KJhTXnUD4q8Rjs6WtwbfRj+YHugRtzjTYXV6Zs/GjKdmweUzy3Rwcw +tbLub74g8Tj5Bwr9THwa1FUVrSmkUreCOCVLHFtpb2e2E37UnspWOJfevtpiVf2G43K NMfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1TgzNS5y; 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=fail (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 j11si11846269edq.584.2020.08.17.15.45.46; Mon, 17 Aug 2020 15:46:10 -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=@kernel.org header.s=default header.b=1TgzNS5y; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391885AbgHQTDG (ORCPT + 99 others); Mon, 17 Aug 2020 15:03:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:59026 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730810AbgHQPrD (ORCPT ); Mon, 17 Aug 2020 11:47:03 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8D43020789; Mon, 17 Aug 2020 15:47:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597679222; bh=FhSwidwZ9FMKss9Vtyczk5OhFwu3nyShbS4ZmaGdGqI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1TgzNS5y+CP0MpTvRfjiCvfX2LAhnYWwUe2IznkVMlgP9pBoQMzCo6YzNGwI0NwIC agXQ8sqBK2BBk9zFXjd7xCFWbktwsVcdzlU40r6RYImgyh3RwtEg5Lk9eXLtQ0UEL9 1DjiRiI1ZuL9qcY9iZjK6OQfHBSOfI0ZAX7Wyiu8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Venkata Lakshmi Narayana Gubba , Abhishek Pandit-Subedi , Marcel Holtmann , Sasha Levin Subject: [PATCH 5.7 138/393] Bluetooth: hci_qca: Bug fix during SSR timeout Date: Mon, 17 Aug 2020 17:13:08 +0200 Message-Id: <20200817143826.305358765@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143819.579311991@linuxfoundation.org> References: <20200817143819.579311991@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Venkata Lakshmi Narayana Gubba [ Upstream commit f98aa80ff78c34fe328eb9cd3e2cc3058e42bcfd ] Due to race conditions between qca_hw_error and qca_controller_memdump during SSR timeout,the same pointer is freed twice. This results in a double free. Now a lock is acquired before checking the stauts of SSR state. Fixes: d841502c79e3 ("Bluetooth: hci_qca: Collect controller memory dump during SSR") Signed-off-by: Venkata Lakshmi Narayana Gubba Reviewed-by: Abhishek Pandit-Subedi Signed-off-by: Marcel Holtmann Signed-off-by: Sasha Levin --- drivers/bluetooth/hci_qca.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c index dc949592c4ed5..a6dd13a2975a8 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -981,8 +981,11 @@ static void qca_controller_memdump(struct work_struct *work) while ((skb = skb_dequeue(&qca->rx_memdump_q))) { mutex_lock(&qca->hci_memdump_lock); - /* Skip processing the received packets if timeout detected. */ - if (qca->memdump_state == QCA_MEMDUMP_TIMEOUT) { + /* Skip processing the received packets if timeout detected + * or memdump collection completed. + */ + if (qca->memdump_state == QCA_MEMDUMP_TIMEOUT || + qca->memdump_state == QCA_MEMDUMP_COLLECTED) { mutex_unlock(&qca->hci_memdump_lock); return; } @@ -1451,8 +1454,6 @@ static void qca_hw_error(struct hci_dev *hdev, u8 code) { struct hci_uart *hu = hci_get_drvdata(hdev); struct qca_data *qca = hu->priv; - struct qca_memdump_data *qca_memdump = qca->qca_memdump; - char *memdump_buf = NULL; set_bit(QCA_SSR_TRIGGERED, &qca->flags); set_bit(QCA_HW_ERROR_EVENT, &qca->flags); @@ -1476,19 +1477,23 @@ static void qca_hw_error(struct hci_dev *hdev, u8 code) qca_wait_for_dump_collection(hdev); } + mutex_lock(&qca->hci_memdump_lock); if (qca->memdump_state != QCA_MEMDUMP_COLLECTED) { bt_dev_err(hu->hdev, "clearing allocated memory due to memdump timeout"); - mutex_lock(&qca->hci_memdump_lock); - if (qca_memdump) - memdump_buf = qca_memdump->memdump_buf_head; - vfree(memdump_buf); - kfree(qca_memdump); - qca->qca_memdump = NULL; + if (qca->qca_memdump) { + vfree(qca->qca_memdump->memdump_buf_head); + kfree(qca->qca_memdump); + qca->qca_memdump = NULL; + } qca->memdump_state = QCA_MEMDUMP_TIMEOUT; cancel_delayed_work(&qca->ctrl_memdump_timeout); - skb_queue_purge(&qca->rx_memdump_q); - mutex_unlock(&qca->hci_memdump_lock); + } + mutex_unlock(&qca->hci_memdump_lock); + + if (qca->memdump_state == QCA_MEMDUMP_TIMEOUT || + qca->memdump_state == QCA_MEMDUMP_COLLECTED) { cancel_work_sync(&qca->ctrl_memdump_evt); + skb_queue_purge(&qca->rx_memdump_q); } clear_bit(QCA_HW_ERROR_EVENT, &qca->flags); -- 2.25.1