linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
To: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
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: Thu, 22 Jul 2021 08:42:05 +0900	[thread overview]
Message-ID: <bb9ceb4d-9e5c-1487-233b-426bc58e9a91@i-love.sakura.ne.jp> (raw)
In-Reply-To: <CABBYNZLt=fJTtdj9qvC22GkF_uYFe59D2bS3u61K14=Gq43Qbw@mail.gmail.com>

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.

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.


  reply	other threads:[~2021-07-21 23:42 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 [this message]
2021-07-23 21:28     ` Luiz Augusto von Dentz
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=bb9ceb4d-9e5c-1487-233b-426bc58e9a91@i-love.sakura.ne.jp \
    --to=penguin-kernel@i-love.sakura.ne.jp \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan.hedberg@gmail.com \
    --cc=linma@zju.edu.cn \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --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).