mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pauli Virtanen <pav@iki.fi>
To: Takashi Iwai <tiwai@suse.de>,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>,
	 linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: Is commit 4d94f0555827 safe?
Date: Mon, 03 Mar 2025 19:47:45 +0200	[thread overview]
Message-ID: <52df2ea6bac070c015987547840c78ac27538def.camel@iki.fi> (raw)
In-Reply-To: <87tt8acbmw.wl-tiwai@suse.de>

Hi,

ma, 2025-03-03 kello 17:38 +0100, Takashi Iwai kirjoitti:
> On Mon, 03 Mar 2025 17:29:58 +0100,
> Luiz Augusto von Dentz wrote:
> > 
> > Hi,
> > 
> > On Mon, Mar 3, 2025 at 10:56 AM Takashi Iwai <tiwai@suse.de> wrote:
> > > 
> > > On Mon, 03 Mar 2025 16:50:37 +0100,
> > > Luiz Augusto von Dentz wrote:
> > > > 
> > > > Hi Takashi,
> > > > 
> > > > On Mon, Mar 3, 2025 at 10:10 AM Takashi Iwai <tiwai@suse.de> wrote:
> > > > > 
> > > > > On Mon, 03 Mar 2025 15:57:16 +0100,
> > > > > Luiz Augusto von Dentz wrote:
> > > > > > 
> > > > > > Hi Takashi,
> > > > > > 
> > > > > > Well the assumption was that because we are doing a copy of the struct
> > > > > > being unregistered/freed would never cause any errors, so to trigger
> > > > > > something like UAF like the comment was suggesting the function
> > > > > > callback would need to be unmapped so even if the likes of iso_exit is
> > > > > > called it function (e.g. iso_connect_cfm) remains in memory.
> > > > > 
> > > > > But it doesn't guarantee that the callback function would really
> > > > > work.  e.g. if the callback accesses some memory that was immediately
> > > > > freed after the unregister call, it will lead to a UAF, even though
> > > > > the function itself is still present on the memory.
> > > > > 
> > > > > That said, the current situation makes hard to judge the object life
> > > > > time.
> > > > > 
> > > > > > You can find the previous version here:
> > > > > > 
> > > > > > https://syzkaller.appspot.com/text?tag=Patch&x=100c0de8580000
> > > > > > 
> > > > > > Problem with it was that it is invalid to unlock and relock like that.
> > > > > 
> > > > > Thanks for the pointer!
> > > > > 
> > > > > 
> > > > > BTW, I saw another patch posted to replace the mutex with spinlock
> > > > > (and you replied later on that it's been already fixed).
> > > > > Is it an acceptable approach at all?
> > > > 
> > > > I don't remember if I saw that, but yeah anything that makes the issue
> > > > go away, and doesn't create new problems, would probably be
> > > > acceptable.
> > > 
> > > I saw this one:
> > >   https://lore.kernel.org/all/20230907122234.146449-1-william.xuanziyang@huawei.com/
> > 
> > Ive might have missed it, we will probably need to rebase it but other
> > than that it should be acceptable.
> 
> Does it mean that you'd revert the change and apply the above one
> (with rebase or modification)?  Or would you keep a part of the
> current change (e.g. match callback looks neat) while applying the
> similar fix using the spinlock?

My current understanding of this is that the actual problem for
4d94f0555827 was incorrect RCU use at the callsite in
hci_le_create_big_complete_evt(). That part was rewritten in

commit 581dd2dc168f ("Bluetooth: hci_event: Fix using rcu_read_(un)lock
while iterating")

and now it no longer calls hci_connect_cfm() from atomic context. I
suspect there were no other callsites that needed hci callbacks be rcu-
safe, so the original mutex is maybe OK as well.

For the other patch 

https://lore.kernel.org/all/20230907122234.146449-1-william.xuanziyang@huawei.com/

The current code is doing rcu_read_unlock() in list_for_each_entry_rcu,
so it's not quite correct. This could be reorganized to restart the
loop after unlock and skip if (conn->abort_reason), which may be
preferable to spinlock in rcu critical section.

-- 
Pauli Virtanen

  reply	other threads:[~2025-03-03 17:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-02  9:59 Takashi Iwai
2025-03-03 14:57 ` Luiz Augusto von Dentz
2025-03-03 15:10   ` Takashi Iwai
2025-03-03 15:50     ` Luiz Augusto von Dentz
2025-03-03 15:56       ` Takashi Iwai
2025-03-03 16:29         ` Luiz Augusto von Dentz
2025-03-03 16:38           ` Takashi Iwai
2025-03-03 17:47             ` Pauli Virtanen [this message]
2025-03-03 18:19               ` Luiz Augusto von Dentz
2025-03-04  8:32                 ` Takashi Iwai

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=52df2ea6bac070c015987547840c78ac27538def.camel@iki.fi \
    --to=pav@iki.fi \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=luiz.von.dentz@intel.com \
    --cc=tiwai@suse.de \
    /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®