Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1326610ybg; Thu, 4 Jun 2020 07:03:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZoTgDIk8cOunZmLTAw1aw9CM9D+pxPT/2S1oZ+SAT1Ej2HHbQ2dLs4dPEXJdnH2DrtEIX X-Received: by 2002:a17:906:1496:: with SMTP id x22mr3859139ejc.161.1591279381512; Thu, 04 Jun 2020 07:03:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591279381; cv=none; d=google.com; s=arc-20160816; b=zRg15uDgK5sMgTpFkCyJV4G7UyJFncsw5qJqgsEq0HC5auExJJxNejbs/6p3E/FZBz TEzvsZFENA90n9U49lDNHlCergaEz79yWhenHNFtCwq00TDyD8QD5ipx07bHtXCKi5mL bWL1zqMCqtXipsA6WGLb88kBNftX6bM6oCUiZUCsJROMgJ123rWoowDI+NmmtXdGIqek nblF/52WAlOvxaeIE/wMIhlTttJLwwOfschfJJEKP8jGafa/gkle1MTLa6VyKrGvNBc+ kyVTzLteXzRbtbD77EgXwn7Rz3sRSMuUHCY3E+yhqZwka+FSvlH6IYhFQiRCny5HVR07 cK+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=CjD6LulQyUUMIQ9WoTvi69SkULxq7DLLy9BrMvFjFlI=; b=oAIGGDjk6zWSLPJ3hkw1/7jzP8T5yhJuTgErhXHIdyNeCJy99/QvNlvJG/aJe9GdF7 SQVFA8XFJL3jM5g3zpBLx1NbX7YB2TYEGABfOx/zPU1pM/XRkxa8Qob2F/SRBMzjeLeW sFqc/HEcS80aU8/NAbaH/vsvL7XxDYYbNFvBcwP/WVusX3UoLUNx41/aCwSbAc1APk1N 8YGkLfudxfcgBILYVKbLWb4OO+EUtmS6gyE25ITCUE1PoDUhj2vGKplnL59F6LlfyAtg ygmPUjQmDpCXO5X5WGCaEtj3HtObJV1wGRWKT1pUZubkyrg+md8MmI2tbYRPx8yRgaxd Gofg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si1816247edi.230.2020.06.04.07.02.12; Thu, 04 Jun 2020 07:03:01 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728889AbgFDN7M (ORCPT + 99 others); Thu, 4 Jun 2020 09:59:12 -0400 Received: from alexa-out-blr-02.qualcomm.com ([103.229.18.198]:61597 "EHLO alexa-out-blr-02.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728337AbgFDN7M (ORCPT ); Thu, 4 Jun 2020 09:59:12 -0400 Received: from ironmsg02-blr.qualcomm.com ([10.86.208.131]) by alexa-out-blr-02.qualcomm.com with ESMTP/TLS/AES256-SHA; 04 Jun 2020 19:28:00 +0530 Received: from gubbaven-linux.qualcomm.com ([10.206.64.32]) by ironmsg02-blr.qualcomm.com with ESMTP; 04 Jun 2020 19:27:34 +0530 Received: by gubbaven-linux.qualcomm.com (Postfix, from userid 2365015) id EB4772186F; Thu, 4 Jun 2020 19:27:33 +0530 (IST) From: Venkata Lakshmi Narayana Gubba To: marcel@holtmann.org, johan.hedberg@gmail.com Cc: mka@chromium.org, linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, robh@kernel.org, hemantg@codeaurora.org, linux-arm-msm@vger.kernel.org, bgodavar@codeaurora.org, tientzu@chromium.org, seanpaul@chromium.org, rjliao@codeaurora.org, yshavit@google.com, Venkata Lakshmi Narayana Gubba Subject: [PATCH v1] Bluetooth: hci_qca: Fix double free during SSR timeout Date: Thu, 4 Jun 2020 19:27:12 +0530 Message-Id: <1591279032-7527-1-git-send-email-gubbaven@codeaurora.org> X-Mailer: git-send-email 2.7.4 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Due to race conditions between qca_hw_error and qca_controller_memdump during SSR timeout,the same pointer is freed twice. Which results to double free error. Now a lock is acquired while SSR state moved to timeout. Signed-off-by: Venkata Lakshmi Narayana Gubba --- drivers/bluetooth/hci_qca.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c index 836949d..9110775 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -983,8 +983,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; } @@ -1485,7 +1488,7 @@ 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; + struct qca_memdump_data *qca_memdump = NULL; char *memdump_buf = NULL; set_bit(QCA_HW_ERROR_EVENT, &qca->flags); @@ -1509,9 +1512,10 @@ 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); + qca_memdump = qca->qca_memdump; if (qca_memdump) memdump_buf = qca_memdump->memdump_buf_head; vfree(memdump_buf); @@ -1520,8 +1524,13 @@ static void qca_hw_error(struct hci_dev *hdev, u8 code) 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); -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation