From: Neeraj Sanjay Kale <neeraj.sanjaykale@nxp.com>
To: Dominique MARTINET <dominique.martinet@atmark-techno.com>
Cc: "marcel@holtmann.org" <marcel@holtmann.org>,
"luiz.dentz@gmail.com" <luiz.dentz@gmail.com>,
"linux-bluetooth@vger.kernel.org"
<linux-bluetooth@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Amitkumar Karwar <amitkumar.karwar@nxp.com>,
Rohit Fule <rohit.fule@nxp.com>, Sherry Sun <sherry.sun@nxp.com>,
Luke Wang <ziniu.wang_1@nxp.com>, Bough Chen <haibo.chen@nxp.com>,
LnxRevLi <LnxRevLi@nxp.com>,
Guillaume Legoupil <guillaume.legoupil@nxp.com>,
Salim Chebbo <salim.chebbo@nxp.com>
Subject: Re: [PATCH v1 1/3] Bluetooth: btnxpuart: Fix Null pointer dereference in btnxpuart_flush()
Date: Thu, 20 Mar 2025 10:20:24 +0000 [thread overview]
Message-ID: <AS4PR04MB969287FECB099EB02DD45EF2E7D82@AS4PR04MB9692.eurprd04.prod.outlook.com> (raw)
In-Reply-To: <Z9i1b9hzZzwJnIYh@atmark-techno.com>
Hello Dominique,
>
> Hi,
>
> Neeraj Sanjay Kale wrote on Wed, May 15, 2024 at 12:36:55PM +0530:
> > @@ -1269,8 +1271,10 @@ static int btnxpuart_flush(struct hci_dev
> > *hdev)
> >
> > cancel_work_sync(&nxpdev->tx_work);
> >
> > - kfree_skb(nxpdev->rx_skb);
> > - nxpdev->rx_skb = NULL;
> > + if (!IS_ERR_OR_NULL(nxpdev->rx_skb)) {
> > + kfree_skb(nxpdev->rx_skb);
> > + nxpdev->rx_skb = NULL;
> > + }
>
> This is an old patch but I hit that on our slightly old tree and was wondering
> about this patch: why does flush() have to free rx at all?
>
> I think this either needs a lock or (preferably) just remove this free:
> - This is inherently racy with btnxpuart_receive_buf() which is run in another
> workqueue with no lock involved as far as I understand, so this is not just
> about errors but you could also free something in a weird place here.
> As far as I understand, even if we don't do anything, the rx path will free the
> reply if no matching request was found.
> - looking at other drivers, the hdev->flush() call never does anything about rx
> and seems to only be about rx (ah, checking again as of master
> drivers/bluetooth/btmtkuart.c seems to have this same problem as of before
> this patch e.g. they're not checking for errors either... This probably needs
> something akin to this patch or removal as well. All other drivers have flush
> seem to be mostly about tx, but I do see some cancel work for rx as well so
> I'm a bit unclear as to what is expected of flush())
Well this comes from an example driver which Marcel had proposed for reference to create a standalone BT driver based on serdev.
https://lore.kernel.org/lkml/2991d8c04ce54f49aa292e9ac1968b7cb3b6a383.1530004712.git.sean.wang@mediatek.com/
When NXP (and probably Mediatek too) patches for hci_uart were rejected, standalone BTUART drivers were implemented based on this reference driver.
Later Francesco Dolcini added the rx_skb free logic in btnxpuart_close. To avoid breaking any functionality, we let rx_skb free logic to be kept in both places, close() and flush()
https://lore.kernel.org/all/20240304181421.14777-1-francesco@dolcini.it/T/
Based on the description you shared, I think it is safe to remove kfree_skb(rx_skb) from the flush() functions and keep it only in close() functions.
Thanks,
Neeraj
next prev parent reply other threads:[~2025-03-20 10:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-15 7:06 [PATCH v1 0/3] Enable status prints for firmware download Neeraj Sanjay Kale
2024-05-15 7:06 ` [PATCH v1 1/3] Bluetooth: btnxpuart: Fix Null pointer dereference in btnxpuart_flush() Neeraj Sanjay Kale
2025-03-17 23:51 ` Dominique MARTINET
2025-03-20 10:20 ` Neeraj Sanjay Kale [this message]
2024-05-15 7:06 ` [PATCH v1 2/3] Bluetooth: btnxpuart: Enable status prints for firmware download Neeraj Sanjay Kale
2024-05-15 7:06 ` [PATCH v1 3/3] Bluetooth: btnxpuart: Handle FW Download Abort scenario Neeraj Sanjay Kale
2024-05-15 20:00 ` [PATCH v1 0/3] Enable status prints for firmware download 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=AS4PR04MB969287FECB099EB02DD45EF2E7D82@AS4PR04MB9692.eurprd04.prod.outlook.com \
--to=neeraj.sanjaykale@nxp.com \
--cc=LnxRevLi@nxp.com \
--cc=amitkumar.karwar@nxp.com \
--cc=dominique.martinet@atmark-techno.com \
--cc=guillaume.legoupil@nxp.com \
--cc=haibo.chen@nxp.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--cc=rohit.fule@nxp.com \
--cc=salim.chebbo@nxp.com \
--cc=sherry.sun@nxp.com \
--cc=ziniu.wang_1@nxp.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
all inboxes | Powered by JetHome®