From: Luiz Augusto von Dentz <luiz.dentz@gmail.com> To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp> Cc: Marcel Holtmann <marcel@holtmann.org>, Johan Hedberg <johan.hedberg@gmail.com>, "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>, LinMa <linma@zju.edu.cn>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Linus Torvalds <torvalds@linux-foundation.org> Subject: Re: [PATCH] Bluetooth: reorganize ioctls from hci_sock_bound_ioctl() Date: Fri, 23 Jul 2021 14:28:01 -0700 [thread overview] Message-ID: <CABBYNZJnC-b0s5LW=zTLh4_bV44Uv2-6LXXy+vRAgQmxk=defg@mail.gmail.com> (raw) In-Reply-To: <bb9ceb4d-9e5c-1487-233b-426bc58e9a91@i-love.sakura.ne.jp> Hi Tetsuo, On Wed, Jul 21, 2021 at 4:42 PM Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp> wrote: > > On 2021/07/22 3:17, Luiz Augusto von Dentz wrote: > > I think it would have been cleaner if we have dedicated functions for > > each command like I did in my patch: > > > > https://patchwork.kernel.org/project/bluetooth/patch/20210717000731.3836303-1-luiz.dentz@gmail.com/ > > But your patch was proven to be unsafe. There is a use-after-unregister > race window which would require at least 1000 lines of modification and > a lot of careful review if we try to manage without my patch. > Such all-in-one-step change is too much for "sleep in atomic context" > regression fix which is preventing syzbot from testing Bluetooth module > and is preventing Linux distributors from fixing CVE-2021-3573. Im not saying you should adopt my solution, the locking etc stay the same as in this set but each command should have a helper function to make it clearer that way we don't have to re-evaluate the command over and over. > As far as I can see, it is lock_sock() (not bh_lock_sock_nested() in your > patch) that is needed for protecting > > sk->sk_err = EPIPE; > sk->sk_state = BT_OPEN; > sk->sk_state_change(sk); > > in hci_sock_dev_event(HCI_DEV_UNREG) from concurrent modification > > lock_sock(sk); > > if (sk->sk_state == BT_BOUND) { > err = -EALREADY; > goto done; > } > > (...snipped...) > > - hci_pi(sk)->hdev = hdev; > + if (hdev) { > + hci_pi(sk)->dev = hdev->id; > + hci_dev_put(hdev); > + } > > (...snipped...) > /* Race window is here. */ > (...snipped...) > > sk->sk_state = BT_BOUND; > done: > release_sock(sk); > > in hci_sock_bind(). > > > > > That way it is simpler to protect the likes of > > copy_from_user/copy_to_user, etc, even if we have to some checks > > duplicated on each function we can have a helper function to checks > > the flags, etc. > > My patch calls copy_from_user()/copy_to_user() without lock_sock() > which works nicely with "[PATCH v3] Bluetooth: call lock_sock() outside > of spinlock section". I'd like to backport "[PATCH v2] Bluetooth: > reorganize ioctls from hci_sock_bound_ioctl()" together. Yep, Im not asking you to change any of that. -- Luiz Augusto von Dentz
next prev parent reply other threads:[~2021-07-23 21:28 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-20 10:49 Tetsuo Handa 2021-07-20 11:58 ` bluez.test.bot 2021-07-20 15:02 ` [PATCH v2] " Tetsuo Handa 2021-07-20 16:09 ` [v2] " bluez.test.bot 2021-07-21 18:17 ` [PATCH] " Luiz Augusto von Dentz 2021-07-21 23:42 ` Tetsuo Handa 2021-07-23 21:28 ` Luiz Augusto von Dentz [this message] 2021-07-31 2:40 ` [PATCH v3] " Tetsuo Handa 2021-07-31 3:15 ` [v3] " bluez.test.bot 2021-08-01 18:49 ` [PATCH v3] " Marcel Holtmann 2021-08-24 14:59 ` Tetsuo Handa
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='CABBYNZJnC-b0s5LW=zTLh4_bV44Uv2-6LXXy+vRAgQmxk=defg@mail.gmail.com' \ --to=luiz.dentz@gmail.com \ --cc=gregkh@linuxfoundation.org \ --cc=johan.hedberg@gmail.com \ --cc=linma@zju.edu.cn \ --cc=linux-bluetooth@vger.kernel.org \ --cc=marcel@holtmann.org \ --cc=penguin-kernel@i-love.sakura.ne.jp \ --cc=torvalds@linux-foundation.org \ --subject='Re: [PATCH] Bluetooth: reorganize ioctls from hci_sock_bound_ioctl()' \ /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
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).