From: Johan Hovold <jhovold@gmail.com>
To: David Herrmann <dh.herrmann@googlemail.com>
Cc: Marcel Holtmann <marcel@holtmann.org>,
"Gustavo F. Padovan" <padovan@profusion.mobi>,
"David S. Miller" <davem@davemloft.net>,
linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, stable <stable@vger.kernel.org>
Subject: Re: [PATCH 1/2] bluetooth: hci_ldisc: fix NULL-pointer dereference on tty_close
Date: Fri, 9 Mar 2012 15:29:39 +0100 [thread overview]
Message-ID: <20120309142939.GD4497@localhost> (raw)
In-Reply-To: <CANq1E4Sd45FtZN6NXs7TZ1k6VrFkbcAZug-1UQwW-XPB0e5Aag@mail.gmail.com>
Hi David,
On Fri, Mar 09, 2012 at 02:44:30PM +0100, David Herrmann wrote:
> On Wed, Mar 7, 2012 at 5:01 PM, Johan Hovold <jhovold@gmail.com> wrote:
> > Do not close protocol driver until device has been unregistered.
> >
> > This fixes a race between tty_close and hci_dev_open which can result in
> > a NULL-pointer dereference.
> >
> > The line discipline closes the protocol driver while we may still have
> > hci_dev_open sleeping on the req_lock mutex resulting in a NULL-pointer
> > dereference when lock is acquired and hci_init_req called.
[...]
> > diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
> > index 0711448..6946081 100644
> > --- a/drivers/bluetooth/hci_ldisc.c
> > +++ b/drivers/bluetooth/hci_ldisc.c
> > @@ -310,11 +310,11 @@ static void hci_uart_tty_close(struct tty_struct *tty)
> > hci_uart_close(hdev);
> >
> > if (test_and_clear_bit(HCI_UART_PROTO_SET, &hu->flags)) {
> > - hu->proto->close(hu);
> > if (hdev) {
> > hci_unregister_dev(hdev);
> > hci_free_dev(hdev);
> > }
> > + hu->proto->close(hu);
> > }
> > }
> > }
>
> I can confirm this. hci_uart_set_proto() opens the proto before it
> registers the hci device. Hence, we should also unregister the hci
> device before closing the proto. I also looked whether this introduces
> other race conditions but no proto-callback can be called here as they
> are all protected by the tty-layer which synchronizes all
> tty-callbacks. Therefore, I think this is the correct fix.
>
> We can apply this to stable even without the "destruct"-fixes from me
> as hu->proto->$cb$() doesn't care whether hdev is valid or not. I
> don't think the destruct-fixes are important enough to send them to
> stable.
Unfortunately hu is is not valid once hci_unregister returns as it will
call the destruct callback. So my patch depends on changing this
behaviour first. (I could also store a pointer to the protocol before
calling unregister in my patch.)
Secondly, I must disagree with you regarding whether the memory leak you
found is critical enough to be added to the stable trees. We're leaking
kernel memory in a deterministic and easily triggered way which could be
exploited by a malicious user.
> Reviewed-by: David Herrmann <dh.herrmann@googlemail.com>
Thanks,
Johan
WARNING: multiple messages have this Message-ID (diff)
From: Johan Hovold <jhovold@gmail.com>
To: David Herrmann <dh.herrmann@googlemail.com>
Cc: Marcel Holtmann <marcel@holtmann.org>,
"Gustavo F. Padovan" <padovan@profusion.mobi>,
"David S. Miller" <davem@davemloft.net>,
linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, stable <stable@vger.kernel.org>
Subject: Re: [PATCH 1/2] bluetooth: hci_ldisc: fix NULL-pointer dereference on tty_close
Date: Fri, 9 Mar 2012 15:29:39 +0100 [thread overview]
Message-ID: <20120309142939.GD4497@localhost> (raw)
In-Reply-To: <CANq1E4Sd45FtZN6NXs7TZ1k6VrFkbcAZug-1UQwW-XPB0e5Aag@mail.gmail.com>
Hi David,
On Fri, Mar 09, 2012 at 02:44:30PM +0100, David Herrmann wrote:
> On Wed, Mar 7, 2012 at 5:01 PM, Johan Hovold <jhovold@gmail.com> wrote:
> > Do not close protocol driver until device has been unregistered.
> >
> > This fixes a race between tty_close and hci_dev_open which can result in
> > a NULL-pointer dereference.
> >
> > The line discipline closes the protocol driver while we may still have
> > hci_dev_open sleeping on the req_lock mutex resulting in a NULL-pointer
> > dereference when lock is acquired and hci_init_req called.
[...]
> > diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
> > index 0711448..6946081 100644
> > --- a/drivers/bluetooth/hci_ldisc.c
> > +++ b/drivers/bluetooth/hci_ldisc.c
> > @@ -310,11 +310,11 @@ static void hci_uart_tty_close(struct tty_struct *tty)
> > � � � � � � � � � � � �hci_uart_close(hdev);
> >
> > � � � � � � � �if (test_and_clear_bit(HCI_UART_PROTO_SET, &hu->flags)) {
> > - � � � � � � � � � � � hu->proto->close(hu);
> > � � � � � � � � � � � �if (hdev) {
> > � � � � � � � � � � � � � � � �hci_unregister_dev(hdev);
> > � � � � � � � � � � � � � � � �hci_free_dev(hdev);
> > � � � � � � � � � � � �}
> > + � � � � � � � � � � � hu->proto->close(hu);
> > � � � � � � � �}
> > � � � �}
> > �}
>
> I can confirm this. hci_uart_set_proto() opens the proto before it
> registers the hci device. Hence, we should also unregister the hci
> device before closing the proto. I also looked whether this introduces
> other race conditions but no proto-callback can be called here as they
> are all protected by the tty-layer which synchronizes all
> tty-callbacks. Therefore, I think this is the correct fix.
>
> We can apply this to stable even without the "destruct"-fixes from me
> as hu->proto->$cb$() doesn't care whether hdev is valid or not. I
> don't think the destruct-fixes are important enough to send them to
> stable.
Unfortunately hu is is not valid once hci_unregister returns as it will
call the destruct callback. So my patch depends on changing this
behaviour first. (I could also store a pointer to the protocol before
calling unregister in my patch.)
Secondly, I must disagree with you regarding whether the memory leak you
found is critical enough to be added to the stable trees. We're leaking
kernel memory in a deterministic and easily triggered way which could be
exploited by a malicious user.
> Reviewed-by: David Herrmann <dh.herrmann@googlemail.com>
Thanks,
Johan
next prev parent reply other threads:[~2012-03-09 14:29 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-07 16:01 [PATCH 0/2] bluetooth: fix NULL-pointer dereferences Johan Hovold
2012-03-07 16:01 ` [PATCH 1/2] bluetooth: hci_ldisc: fix NULL-pointer dereference on tty_close Johan Hovold
2012-03-07 19:33 ` Marcel Holtmann
2012-03-08 11:57 ` Johan Hovold
2012-03-08 17:45 ` Marcel Holtmann
2012-03-08 17:45 ` Marcel Holtmann
2012-03-09 13:04 ` Johan Hovold
2012-03-09 13:04 ` Johan Hovold
2012-03-09 13:52 ` David Herrmann
2012-03-09 13:52 ` David Herrmann
2012-03-09 13:52 ` David Herrmann
2012-03-09 13:52 ` David Herrmann
2012-03-09 14:40 ` Johan Hovold
2012-03-09 14:40 ` Johan Hovold
2012-03-09 15:02 ` David Herrmann
2012-03-09 15:02 ` David Herrmann
2012-03-09 15:02 ` David Herrmann
2012-03-09 15:08 ` Johan Hovold
2012-03-09 15:08 ` Johan Hovold
2012-03-09 15:08 ` Johan Hovold
2012-03-09 13:44 ` David Herrmann
2012-03-09 13:44 ` David Herrmann
2012-03-09 13:44 ` David Herrmann
2012-03-09 14:29 ` Johan Hovold [this message]
2012-03-09 14:29 ` Johan Hovold
2012-03-09 14:35 ` David Herrmann
2012-03-09 14:35 ` David Herrmann
2012-03-09 14:35 ` David Herrmann
2012-03-09 14:35 ` David Herrmann
2012-03-09 15:15 ` Johan Hovold
2012-03-09 15:15 ` Johan Hovold
2012-03-07 16:02 ` [PATCH 2/2] bluetooth: hci_core: fix NULL-pointer dereference at unregister Johan Hovold
2012-03-07 19:29 ` Marcel Holtmann
2012-03-07 19:29 ` Marcel Holtmann
2012-03-08 11:56 ` Johan Hovold
2012-03-08 17:43 ` Marcel Holtmann
2012-03-08 17:43 ` Marcel Holtmann
2012-03-09 12:53 ` [PATCH 2/2 v2] " Johan Hovold
2012-03-09 14:04 ` David Herrmann
2012-03-09 14:04 ` David Herrmann
2012-03-09 14:04 ` David Herrmann
2012-03-09 14:48 ` Johan Hovold
2012-03-09 14:48 ` Johan Hovold
2012-03-09 14:48 ` Johan Hovold
-- strict thread matches above, loose matches on Subject: below --
2012-03-15 13:47 bluetooth: bug fixes for bluetooth-next Johan Hovold
2012-03-15 13:48 ` [PATCH 1/2] bluetooth: hci_ldisc: fix NULL-pointer dereference on tty_close Johan Hovold
2012-03-15 15:21 ` Marcel Holtmann
2012-03-16 16:03 ` Johan Hedberg
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=20120309142939.GD4497@localhost \
--to=jhovold@gmail.com \
--cc=davem@davemloft.net \
--cc=dh.herrmann@googlemail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcel@holtmann.org \
--cc=netdev@vger.kernel.org \
--cc=padovan@profusion.mobi \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.