[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAD=FV=XvSCzi1hjgcWa_AecsdG7wbe9o29n2M1cWLezqZk6Dig@mail.gmail.com>
Date: Fri, 30 Jun 2023 15:11:37 -0700
From: Doug Anderson <dianders@...omium.org>
To: Luiz Augusto von Dentz <luiz.dentz@...il.com>
Cc: Marcel Holtmann <marcel@...tmann.org>,
Johan Hedberg <johan.hedberg@...il.com>,
Stephen Boyd <swboyd@...omium.org>,
Manish Mandlik <mmandlik@...gle.com>,
Miao-chen Chou <mcchou@...gle.com>,
linux-bluetooth@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] Bluetooth: hci_sync: Avoid use-after-free in dbg for hci_remove_adv_monitor()
Hi,
On Fri, Jun 30, 2023 at 2:55 PM Luiz Augusto von Dentz
<luiz.dentz@...il.com> wrote:
>
> Hi Douglas,
>
> On Fri, Jun 30, 2023 at 2:40 PM Douglas Anderson <dianders@...omium.org> wrote:
> >
> > KASAN reports that there's a use-after-free in
> > hci_remove_adv_monitor(). Trawling through the disassembly, you can
> > see that the complaint is from the access in bt_dev_dbg() under the
> > HCI_ADV_MONITOR_EXT_MSFT case. The problem case happens because
> > msft_remove_monitor() can end up freeing the monitor
> > structure. Specifically:
> > hci_remove_adv_monitor() ->
> > msft_remove_monitor() ->
> > msft_remove_monitor_sync() ->
> > msft_le_cancel_monitor_advertisement_cb() ->
> > hci_free_adv_monitor()
> >
> > Let's fix the problem by just stashing the relevant data when it's
> > still valid.
> >
> > Fixes: 7cf5c2978f23 ("Bluetooth: hci_sync: Refactor remove Adv Monitor")
> > Signed-off-by: Douglas Anderson <dianders@...omium.org>
> > ---
> >
> > net/bluetooth/hci_core.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> > index 48917c68358d..dbb2043a9112 100644
> > --- a/net/bluetooth/hci_core.c
> > +++ b/net/bluetooth/hci_core.c
> > @@ -1972,6 +1972,7 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev,
> > struct adv_monitor *monitor)
> > {
> > int status = 0;
> > + int handle;
> >
> > switch (hci_get_adv_monitor_offload_ext(hdev)) {
> > case HCI_ADV_MONITOR_EXT_NONE: /* also goes here when powered off */
> > @@ -1980,9 +1981,10 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev,
> > goto free_monitor;
> >
> > case HCI_ADV_MONITOR_EXT_MSFT:
> > + handle = monitor->handle;
> > status = msft_remove_monitor(hdev, monitor);
> > bt_dev_dbg(hdev, "%s remove monitor %d msft status %d",
> > - hdev->name, monitor->handle, status);
> > + hdev->name, handle, status);
>
> Just move the call to bt_dev_dbg under msft_remove_monitor,
Sure. I wasn't sure how much the order of the printout matters, but if
it doesn't then just putting the print first makes sense. Done in v2.
> also there
> is no reason to print hdev->name since bt_dev_dbg already does that so
> while at it we can probably fix this as well.
I made that a separate patch just to keep it cleaner. I also fixed the
"add" function which has the same issue.
-Doug
Powered by blists - more mailing lists