2019-11-01 20:43:50

by Tomas Bortoli

[permalink] [raw]
Subject: [PATCH] Fix invalid-free in bcsp_close()

Syzbot reported an invalid-free that I introduced fixing a memleak.

bcsp_recv() also frees bcsp->rx_skb but never nullifies its value.
Nullify bcsp->rx_skb every time it is freed.

Signed-off-by: Tomas Bortoli <[email protected]>
Reported-by: [email protected]
---
drivers/bluetooth/hci_bcsp.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c
index fe2e307009f4..cf4a56095817 100644
--- a/drivers/bluetooth/hci_bcsp.c
+++ b/drivers/bluetooth/hci_bcsp.c
@@ -591,6 +591,7 @@ static int bcsp_recv(struct hci_uart *hu, const void *data, int count)
if (*ptr == 0xc0) {
BT_ERR("Short BCSP packet");
kfree_skb(bcsp->rx_skb);
+ bcsp->rx_skb = NULL;
bcsp->rx_state = BCSP_W4_PKT_START;
bcsp->rx_count = 0;
} else
@@ -606,6 +607,7 @@ static int bcsp_recv(struct hci_uart *hu, const void *data, int count)
bcsp->rx_skb->data[2])) != bcsp->rx_skb->data[3]) {
BT_ERR("Error in BCSP hdr checksum");
kfree_skb(bcsp->rx_skb);
+ bcsp->rx_skb = NULL;
bcsp->rx_state = BCSP_W4_PKT_DELIMITER;
bcsp->rx_count = 0;
continue;
@@ -630,6 +632,7 @@ static int bcsp_recv(struct hci_uart *hu, const void *data, int count)
bscp_get_crc(bcsp));

kfree_skb(bcsp->rx_skb);
+ bcsp->rx_skb = NULL;
bcsp->rx_state = BCSP_W4_PKT_DELIMITER;
bcsp->rx_count = 0;
continue;
--
2.20.1


2019-11-25 12:45:57

by Alexander Potapenko

[permalink] [raw]
Subject: Re: [PATCH] Fix invalid-free in bcsp_close()

Hi Tomas, Marcel, Greg,

On Mon, Nov 4, 2019 at 3:20 PM Marcel Holtmann <[email protected]> wrote:
>
> Hi Tomas,
>
> > Syzbot reported an invalid-free that I introduced fixing a memleak.
> >
> > bcsp_recv() also frees bcsp->rx_skb but never nullifies its value.
> > Nullify bcsp->rx_skb every time it is freed.
> >
> > Signed-off-by: Tomas Bortoli <[email protected]>
> > Reported-by: [email protected]
> > ---
> > drivers/bluetooth/hci_bcsp.c | 3 +++
> > 1 file changed, 3 insertions(+)
>
> patch has been applied to bluetooth-next tree.
I believe this bug requires stable tags, as it can potentially provide
an arbitrary write (via __skb_unlink) and is triggerable locally with
user privileges.
> Regards
>
> Marcel
>
> --
> You received this message because you are subscribed to the Google Groups "syzkaller" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/msgid/syzkaller/E16896E5-B946-450F-BF42-04665D219EEA%40holtmann.org.



--
Alexander Potapenko
Software Engineer

Google Germany GmbH
Erika-Mann-Straße, 33
80636 München

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg

2019-11-26 08:35:18

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] Fix invalid-free in bcsp_close()

On Tue, Nov 26, 2019 at 07:18:46AM +0100, Marcel Holtmann wrote:
> Hi Alexander,
>
> >>> Syzbot reported an invalid-free that I introduced fixing a memleak.
> >>>
> >>> bcsp_recv() also frees bcsp->rx_skb but never nullifies its value.
> >>> Nullify bcsp->rx_skb every time it is freed.
> >>>
> >>> Signed-off-by: Tomas Bortoli <[email protected]>
> >>> Reported-by: [email protected]
> >>> ---
> >>> drivers/bluetooth/hci_bcsp.c | 3 +++
> >>> 1 file changed, 3 insertions(+)
> >>
> >> patch has been applied to bluetooth-next tree.
> > I believe this bug requires stable tags, as it can potentially provide
> > an arbitrary write (via __skb_unlink) and is triggerable locally with
> > user privileges.
>
> I do not have a reproducer for it, but if you do, feel free to propose it for -stable inclusion.

Now queued up, thanks.

greg k-h