Linux-mediatek Archive mirror
 help / color / mirror / Atom feed
From: sean.wang@kernel.org
To: luiz.dentz@gmail.com, marcel@holtmann.org, johan.hedberg@gmail.com
Cc: sean.wang@mediatek.com, chris.lu@mediatek.com,
	Deren.Wu@mediatek.com, jsiuda@google.com, frankgor@google.com,
	abhishekpandit@google.com, michaelfsun@google.com,
	mmandlik@google.com, abhishekpandit@chromium.org,
	mcchou@chromium.org, shawnku@google.com,
	linux-bluetooth@vger.kernel.org,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH RESEND] Bluetooth: btusb: medaitek: fix double free of skb in coredump
Date: Wed, 17 Apr 2024 16:27:38 -0700	[thread overview]
Message-ID: <da0859c4b24d314d9ff38179c26a58ee7e3f16d6.1713395895.git.sean.wang@kernel.org> (raw)

From: Sean Wang <sean.wang@mediatek.com>

hci_devcd_append() would free the skb on error so the caller don't
have to free it again otherwise it would cause the double free of skb.

Fixes: 0b7015132878 ("Bluetooth: btusb: mediatek: add MediaTek devcoredump support")
Reported-by : Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 drivers/bluetooth/btmtk.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c
index ac8ebccd3507..812fd2a8f853 100644
--- a/drivers/bluetooth/btmtk.c
+++ b/drivers/bluetooth/btmtk.c
@@ -380,8 +380,10 @@ int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb)
 	switch (data->cd_info.state) {
 	case HCI_DEVCOREDUMP_IDLE:
 		err = hci_devcd_init(hdev, MTK_COREDUMP_SIZE);
-		if (err < 0)
+		if (err < 0) {
+			kfree_skb(skb);
 			break;
+		}
 		data->cd_info.cnt = 0;
 
 		/* It is supposed coredump can be done within 5 seconds */
@@ -407,9 +409,6 @@ int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb)
 		break;
 	}
 
-	if (err < 0)
-		kfree_skb(skb);
-
 	return err;
 }
 EXPORT_SYMBOL_GPL(btmtk_process_coredump);
-- 
2.25.1



             reply	other threads:[~2024-04-17 23:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-17 23:27 sean.wang [this message]
2024-04-18  9:40 ` [PATCH RESEND] Bluetooth: btusb: medaitek: fix double free of skb in coredump Markus Elfring
2024-04-19 19:42   ` Luiz Augusto von Dentz
2024-04-19 19:56     ` Markus Elfring
2024-04-19 19:50 ` [PATCH RESEND] " patchwork-bot+bluetooth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=da0859c4b24d314d9ff38179c26a58ee7e3f16d6.1713395895.git.sean.wang@kernel.org \
    --to=sean.wang@kernel.org \
    --cc=Deren.Wu@mediatek.com \
    --cc=abhishekpandit@chromium.org \
    --cc=abhishekpandit@google.com \
    --cc=chris.lu@mediatek.com \
    --cc=frankgor@google.com \
    --cc=johan.hedberg@gmail.com \
    --cc=jsiuda@google.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=mcchou@chromium.org \
    --cc=michaelfsun@google.com \
    --cc=mmandlik@google.com \
    --cc=sean.wang@mediatek.com \
    --cc=shawnku@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).