public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Pauli Virtanen <pav@iki.fi>
To: Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
	 linux-bluetooth@vger.kernel.org
Cc: devnexen@gmail.com
Subject: Re: [PATCH v3] Bluetooth: hci_conn: fix potential UAF in create_big_sync
Date: Sat, 11 Apr 2026 14:07:13 +0300	[thread overview]
Message-ID: <c8a8aca1bb455d72e5e902b4ae0487947457b0e6.camel@iki.fi> (raw)
In-Reply-To: <20260410201343.229470-1-luiz.dentz@gmail.com>

Hi,

pe, 2026-04-10 kello 16:13 -0400, Luiz Augusto von Dentz kirjoitti:
> From: David Carlier <devnexen@gmail.com>
> 
> Add hci_conn_valid() check in create_big_sync() to detect stale
> connections before proceeding with BIG creation. Fix
> create_big_complete() to handle the resulting -ECANCELED error
> and validate the connection under hci_dev_lock() before
> dereferencing, following the established pattern used by
> create_le_conn_complete() and create_pa_complete().
> 
> Without this, create_big_complete() would unconditionally
> dereference the stale conn pointer on error, causing a
> use-after-free via hci_connect_cfm() and hci_conn_del().
> 
> Fixes: eca0ae4aea66 ("Bluetooth: Add initial implementation of BIS connections")
> Cc: stable@vger.kernel.org
> Signed-off-by: David Carlier <devnexen@gmail.com>
> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> ---
>  net/bluetooth/hci_conn.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
> index 3a0592599086..7e6b3542809c 100644
> --- a/net/bluetooth/hci_conn.c
> +++ b/net/bluetooth/hci_conn.c
> @@ -2130,6 +2130,9 @@ static int create_big_sync(struct hci_dev *hdev, void *data)
>  	u32 flags = 0;
>  	int err;
>  
> +	if (!hci_conn_valid(hdev, conn))
> +		return -ECANCELED;
> +
>  	if (qos->bcast.out.phys == BIT(1))
>  		flags |= MGMT_ADV_FLAG_SEC_2M;
>  
> @@ -2204,11 +2207,17 @@ static void create_big_complete(struct hci_dev *hdev, void *data, int err)
>  
>  	bt_dev_dbg(hdev, "conn %p", conn);
>  
> +	if (err == -ECANCELED)
> +		goto done;
> +
>  	if (err) {
>  		bt_dev_err(hdev, "Unable to create BIG: %d", err);
>  		hci_connect_cfm(conn, err);
>  		hci_conn_del(conn);

hci_conn_del() is called without hci_dev_lock() here.

It probably should take the lock and check hci_conn_valid() inside the
critical section before calling into hci_conn_del().

Probably hci_conn_del() should have lockdep_assert_held(&hdev->lock)

>  	}
> +
> +done:
> +	hci_conn_put(conn);
>  }
>  
>  struct hci_conn *hci_bind_bis(struct hci_dev *hdev, bdaddr_t *dst, __u8 sid,
> @@ -2336,10 +2345,11 @@ struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst,
>  				 BT_BOUND, &data);
>  
>  	/* Queue start periodic advertising and create BIG */
> -	err = hci_cmd_sync_queue(hdev, create_big_sync, conn,
> +	err = hci_cmd_sync_queue(hdev, create_big_sync, hci_conn_get(conn),
>  				 create_big_complete);
>  	if (err < 0) {
>  		hci_conn_drop(conn);
> +		hci_conn_put(conn);
>  		return ERR_PTR(err);
>  	}
>  

-- 
Pauli Virtanen

  parent reply	other threads:[~2026-04-11 11:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-10 20:13 [PATCH v3] Bluetooth: hci_conn: fix potential UAF in create_big_sync Luiz Augusto von Dentz
2026-04-10 20:49 ` [v3] " bluez.test.bot
2026-04-11 11:07 ` Pauli Virtanen [this message]
2026-04-11 12:05   ` [PATCH v3] " David CARLIER

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=c8a8aca1bb455d72e5e902b4ae0487947457b0e6.camel@iki.fi \
    --to=pav@iki.fi \
    --cc=devnexen@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.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