From: Hillf Danton <hdanton@sina.com>
To: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: Edward Adam Davis <eadavis@qq.com>,
syzbot+31c2f641b850a348a734@syzkaller.appspotmail.com,
johan.hedberg@gmail.com, linux-bluetooth@vger.kernel.org,
linux-kernel@vger.kernel.org, marcel@holtmann.org,
syzkaller-bugs@googlegroups.com
Subject: Re: [PATCH] Bluetooth: hci_core: sync hci rx and cmd sync work
Date: Fri, 17 Jan 2025 06:44:46 +0800 [thread overview]
Message-ID: <20250116224448.1933-1-hdanton@sina.com> (raw)
In-Reply-To: <CABBYNZ+99rvMrDs_j8niLtef537t7VFrEVY4NHdymW8wgnBNdQ@mail.gmail.com>
On Thu, 16 Jan 2025 10:31:03 -0500 Luiz Augusto von Dentz
> On Thu, Jan 16, 2025 at 5:42 AM Hillf Danton <hdanton@sina.com> wrote:
> >
> > This does not work because conn can be freed before bumping refcnt up,
> > and bumpup alone does not help l2cap_send_cmd() in case conn->hchan has been
> > cleared in l2cap_conn_del().
>
> Well then perhaps we can use hdev lock just to protect l2cap_data:
>
> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
> index 27b4c4a2ba1f..00ef61609d49 100644
> --- a/net/bluetooth/l2cap_core.c
> +++ b/net/bluetooth/l2cap_core.c
> @@ -7466,14 +7466,33 @@ static void l2cap_recv_reset(struct l2cap_conn *conn)
> conn->rx_len = 0;
> }
>
> +static struct l2cap_conn *l2cap_conn_hold_unless_zero(struct l2cap_conn *c)
> +{
> + BT_DBG("conn %p orig refcnt %u", c, kref_read(&c->ref));
> +
> + if (!kref_get_unless_zero(&c->ref))
> + return NULL;
> +
> + return c;
> +}
> +
> void l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)
> {
> - struct l2cap_conn *conn = hcon->l2cap_data;
> + struct l2cap_conn *conn;
> int len;
>
> + /* Lock hdev to access l2cap_data to avoid race with l2cap_conn_del */
> + hci_dev_lock(hcon->hdev);
> +
> + conn = hcon->l2cap_data;
> +
> if (!conn)
> conn = l2cap_conn_add(hcon);
>
> + conn = l2cap_conn_hold_unless_zero(conn);
> +
> + hci_dev_unlock(hcon->hdev);
> +
This does not work either because after releasing lock bumpup alone can
not prevent conn->hchan from being cleared.
next prev parent reply other threads:[~2025-01-16 22:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-26 9:32 [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_send_cmd syzbot
2025-01-06 9:04 ` syzbot
2025-01-15 9:46 ` [PATCH] Bluetooth: hci_core: sync hci rx and cmd sync work Edward Adam Davis
2025-01-15 10:31 ` bluez.test.bot
2025-01-15 16:13 ` [PATCH] " Luiz Augusto von Dentz
2025-01-16 10:42 ` Hillf Danton
2025-01-16 15:31 ` Luiz Augusto von Dentz
2025-01-16 22:44 ` Hillf Danton [this message]
2025-01-14 14:09 ` [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in l2cap_send_cmd syzbot
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=20250116224448.1933-1-hdanton@sina.com \
--to=hdanton@sina.com \
--cc=eadavis@qq.com \
--cc=johan.hedberg@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--cc=syzbot+31c2f641b850a348a734@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.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 NNTP newsgroup(s).