Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2631334pxa; Mon, 17 Aug 2020 14:57:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTsiPg5gwiCTn0wzfOe8r5XtFLW2m8K6GMwV0yue2cMaALUO9psrxBzTkiPmzTBgZ7Hc4E X-Received: by 2002:a05:6402:c0a:: with SMTP id co10mr17451409edb.342.1597701467163; Mon, 17 Aug 2020 14:57:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597701467; cv=none; d=google.com; s=arc-20160816; b=AAigFytU3m/q50LZeQDHmAoXqRLZSpXDB71iphLSix/kbzAqBjUwXTEn4RDc62GrZu Tz6wWUOe7cke4CURcwbvh8eBTwchq5QgbbBrAAkW6NWStHkOpncSfKwPPi4JKDD+YR+P 3dd7k5ntfkErdXZ9RCtYdKXmp/b6/vnaHzkAJiU0+x+0CbpJLrd7lDENSZm16S3ibcrt gNNDR4kV+GUv51A2Hd9oHxHQbT9CTFoA65ggmoTcM/I1IC3jW2+qo2mHAKEqjktK3Mvt yAP0kwdypoz+OhcCwDZYslrcjWWkP/3DIOrPOxPhMYlfLPbd6T+LJbV+KgFvrjOix71/ G/Uw== 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=OWs4r8KVaYyCX5QkjtfolxY1f9noT3t8PDjVZ+Jp7Yo=; b=KzHA1eL4t8BkdxRFM8nw1mGFSZFxD0IVDCom9Ge02E66gH15NFGY1zXC5hvONKG5TD vWCk7R6dYr0WiB9DItyMUVlVGsqz/YQb/ibxuhHZbFe4igmdX36Z17YwfCWUo8PxHXYf d7L76d6b+KOfpuKkNltKzMQoMZQynGTz2rN5h0dmNyZ17jLd+nNrez+FLBpO7S6Zishm F9HkwMTbd9197foEs//SsBwCHAD1GCq8Wzm9NcjC2ONs38kIo24gCitNDUhI9j+0SRmM 7ZACgIw2/3giQ4JEtwZdjnnj/9VvcXP8cZC/lW7/gU3KPFOerSpQL2spAQh6MuZ80u6y r3fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aJp+dwgq; 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 lr26si12286250ejb.47.2020.08.17.14.57.23; Mon, 17 Aug 2020 14:57:47 -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=aJp+dwgq; 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 S1730058AbgHQP3D (ORCPT + 99 others); Mon, 17 Aug 2020 11:29:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:36368 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729841AbgHQP0u (ORCPT ); Mon, 17 Aug 2020 11:26:50 -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 F1B9623AC0; Mon, 17 Aug 2020 15:26:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597678009; bh=SZwoex5LQAzkkk+vKspmwpjdMUbJieW9yzVGmipuZuE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aJp+dwgqsGGhFOO8yhUY7EsXJYDgpfuc5Of7IA+3RpQcbCmJwuSbxTatNV8ptziN9 sD3aXeC3lsJtNfc/dbbE7yRCTd2Ru8BqBksRMD6t3VpxwqrwiFdLDwduXN86TN6Obw nkT0EbXBYEhgA1fpyR8OqGGluonhXbdqVS2gEGcY= 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.8 157/464] Bluetooth: hci_qca: Bug fix during SSR timeout Date: Mon, 17 Aug 2020 17:11:50 +0200 Message-Id: <20200817143841.328293948@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@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 328919b79f7b9..74245f20a309e 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -991,8 +991,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; } @@ -1494,8 +1497,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); @@ -1519,19 +1520,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