* [PATCH] Bluetooth: mgmt: Fix dereference after NULL check
@ 2012-10-04 10:56 Andrei Emeltchenko
2012-10-04 12:17 ` Johan Hedberg
0 siblings, 1 reply; 3+ messages in thread
From: Andrei Emeltchenko @ 2012-10-04 10:56 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
hdev might be NULL, so we need to avoid possible NULL derefernce in
handler->func functions.
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
net/bluetooth/mgmt.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index b127b88..be3182c 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2738,7 +2738,6 @@ static const struct mgmt_handler {
int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
{
void *buf;
- u8 *cp;
struct mgmt_hdr *hdr;
u16 opcode, index, len;
struct hci_dev *hdev = NULL;
@@ -2802,14 +2801,17 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
goto done;
}
- if (hdev)
+ if (hdev) {
+ u8 *cp;
+
mgmt_init_hdev(sk, hdev);
- cp = buf + sizeof(*hdr);
+ cp = buf + sizeof(*hdr);
- err = handler->func(sk, hdev, cp, len);
- if (err < 0)
- goto done;
+ err = handler->func(sk, hdev, cp, len);
+ if (err < 0)
+ goto done;
+ }
err = msglen;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Bluetooth: mgmt: Fix dereference after NULL check
2012-10-04 10:56 [PATCH] Bluetooth: mgmt: Fix dereference after NULL check Andrei Emeltchenko
@ 2012-10-04 12:17 ` Johan Hedberg
2012-10-04 12:33 ` Andrei Emeltchenko
0 siblings, 1 reply; 3+ messages in thread
From: Johan Hedberg @ 2012-10-04 12:17 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
Hi Andrei,
On Thu, Oct 04, 2012, Andrei Emeltchenko wrote:
> hdev might be NULL, so we need to avoid possible NULL derefernce in
> handler->func functions.
>
> Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> ---
> net/bluetooth/mgmt.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
Nack. Some of the handlers actually should be getting a NULL hdev and
there's code higher up in the function you're changing that ensures that
NULL is allowed for those handlers but not for any others (which should
safely be able to skip NULL checks).
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Bluetooth: mgmt: Fix dereference after NULL check
2012-10-04 12:17 ` Johan Hedberg
@ 2012-10-04 12:33 ` Andrei Emeltchenko
0 siblings, 0 replies; 3+ messages in thread
From: Andrei Emeltchenko @ 2012-10-04 12:33 UTC (permalink / raw)
To: linux-bluetooth
Hi Johan,
On Thu, Oct 04, 2012 at 03:17:02PM +0300, Johan Hedberg wrote:
> Hi Andrei,
>
> On Thu, Oct 04, 2012, Andrei Emeltchenko wrote:
> > hdev might be NULL, so we need to avoid possible NULL derefernce in
> > handler->func functions.
> >
> > Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> > ---
> > net/bluetooth/mgmt.c | 14 ++++++++------
> > 1 file changed, 8 insertions(+), 6 deletions(-)
>
> Nack. Some of the handlers actually should be getting a NULL hdev and
> there's code higher up in the function you're changing that ensures that
> NULL is allowed for those handlers but not for any others (which should
> safely be able to skip NULL checks).
True, BTW: this would be nice to put this explanation as comment there.
Best regards
Andrei Emeltchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-10-04 12:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-04 10:56 [PATCH] Bluetooth: mgmt: Fix dereference after NULL check Andrei Emeltchenko
2012-10-04 12:17 ` Johan Hedberg
2012-10-04 12:33 ` Andrei Emeltchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox