[PATCH] Fix invalid-free in bcsp_close()

16 views
Skip to first unread message

Tomas Bortoli

unread,
Nov 1, 2019, 4:42:50 PM11/1/19
to mar...@holtmann.org, johan....@gmail.com, linux-b...@vger.kernel.org, linux-...@vger.kernel.org, syzk...@googlegroups.com, Tomas Bortoli, syzbot+a0d209...@syzkaller.appspotmail.com
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 <tomasb...@gmail.com>
Reported-by: syzbot+a0d209...@syzkaller.appspotmail.com
---
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

Marcel Holtmann

unread,
Nov 4, 2019, 9:19:53 AM11/4/19
to Tomas Bortoli, Johan Hedberg, Bluez mailing list, lkml, syzk...@googlegroups.com, syzbot+a0d209...@syzkaller.appspotmail.com
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 <tomasb...@gmail.com>
> Reported-by: syzbot+a0d209...@syzkaller.appspotmail.com
> ---
> drivers/bluetooth/hci_bcsp.c | 3 +++
> 1 file changed, 3 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel

Alexander Potapenko

unread,
Nov 25, 2019, 7:41:04 AM11/25/19
to Marcel Holtmann, Tomas Bortoli, Greg Kroah-Hartman, Johan Hedberg, Bluez mailing list, lkml, syzkaller, syzbot+a0d209...@syzkaller.appspotmail.com
Hi Tomas, Marcel, Greg,
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 syzkaller+...@googlegroups.com.
> 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

Marcel Holtmann

unread,
Nov 26, 2019, 1:18:47 AM11/26/19
to Alexander Potapenko, Tomas Bortoli, Greg Kroah-Hartman, Johan Hedberg, Bluez mailing list, lkml, syzkaller, syzbot+a0d209...@syzkaller.appspotmail.com
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 <tomasb...@gmail.com>
>>> Reported-by: syzbot+a0d209...@syzkaller.appspotmail.com
>>> ---
>>> 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.

Regards

Marcel

Greg Kroah-Hartman

unread,
Nov 26, 2019, 3:13:02 AM11/26/19
to Marcel Holtmann, Alexander Potapenko, Tomas Bortoli, Johan Hedberg, Bluez mailing list, lkml, syzkaller, syzbot+a0d209...@syzkaller.appspotmail.com
Now queued up, thanks.

greg k-h
Reply all
Reply to author
Forward
0 new messages