From: kovalev@altlinux.org
To: marcel@holtmann.org, johan.hedberg@gmail.com,
luiz.dentz@gmail.com, linux-bluetooth@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: Re: [PATCH net] Bluetooth: hci_event: fix possible multiple drops by marked conn->state after hci_disconnect()
Date: Thu, 11 Apr 2024 19:14:34 +0300 [thread overview]
Message-ID: <cfe268c1-9395-da7f-2db5-46152e348274@basealt.ru> (raw)
In-Reply-To: <20240411151929.403263-1-kovalev@altlinux.org>
11.04.2024 18:19, kovalev@altlinux.org wrote:
> From: Vasiliy Kovalev <kovalev@altlinux.org>
>
> When returning from the hci_disconnect() function, the conn->state
> continues to be set to BT_CONNECTED and hci_conn_drop() is executed,
> which decrements the conn->refcnt.
Syzkaller C reproducer:
https://lore.kernel.org/all/f8bb62a7-5845-53ed-7fbe-c0557c2745f2@basealt.ru/#t
During debugging, the value conn->refcnt goes down to -1000 and less.
> Syzkaller has generated a reproducer that results in multiple calls to
> hci_encrypt_change_evt() of the same conn object.
> --
> hci_encrypt_change_evt(){
> // conn->state == BT_CONNECTED
> hci_disconnect(){
> hci_abort_conn();
> }
> hci_conn_drop();
> // conn->state == BT_CONNECTED
> }
> --
> This behavior can cause the conn->refcnt to go far into negative values
> and cause problems. To get around this, you need to change the conn->state,
> namely to BT_DISCONN, as it was before. > Fixes: a13f316e90fd ("Bluetooth: hci_conn: Consolidate code for
aborting connections")
> Cc: stable@vger.kernel.org
> Signed-off-by: Vasiliy Kovalev <kovalev@altlinux.org>
> ---
> net/bluetooth/hci_event.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
> index 64477e1bde7cec..e0477021183f9b 100644
> --- a/net/bluetooth/hci_event.c
> +++ b/net/bluetooth/hci_event.c
> @@ -2989,6 +2989,7 @@ static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status)
>
> hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
> hci_conn_drop(conn);
> + conn->state = BT_DISCONN;
>
> unlock:
> hci_dev_unlock(hdev);
> @@ -3654,6 +3655,7 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data,
> hci_encrypt_cfm(conn, ev->status);
> hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
> hci_conn_drop(conn);
> + conn->state = BT_DISCONN;
> goto unlock;
> }
>
> @@ -5248,6 +5250,7 @@ static void hci_key_refresh_complete_evt(struct hci_dev *hdev, void *data,
> if (ev->status && conn->state == BT_CONNECTED) {
> hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
> hci_conn_drop(conn);
> + conn->state = BT_DISCONN;
> goto unlock;
> }
>
--
Regards,
Vasiliy Kovalev
prev parent reply other threads:[~2024-04-11 16:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-11 15:19 kovalev
2024-04-11 16:14 ` kovalev [this message]
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=cfe268c1-9395-da7f-2db5-46152e348274@basealt.ru \
--to=kovalev@altlinux.org \
--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=stable@vger.kernel.org \
/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®