From: Anderson Lizardo <anderson.lizardo@openbossa.org>
To: johan.hedberg@gmail.com
Cc: linux-bluetooth@vger.kernel.org, Johan Hedberg <johan.hedberg@nokia.com>
Subject: Re: [PATCH 2/3] Bluetooth: Add initial Bluetooth Management interface callbacks
Date: Mon, 6 Dec 2010 09:11:35 -0400 [thread overview]
Message-ID: <AANLkTimYKSvo8WpNa-ft61MoBaAgKZxt5j0qVuRBfCb3@mail.gmail.com> (raw)
In-Reply-To: <1291573170-3708-3-git-send-email-johan.hedberg@gmail.com>
Hi Johan,
On Sun, Dec 5, 2010 at 2:19 PM, <johan.hedberg@gmail.com> wrote:
> +static void cmd_status(struct sock *sk, u16 cmd, u8 status)
> +{
I see some inconsistence on how you calculate struct sizes on this
function. See below...
> + struct sk_buff *skb;
> + struct mgmt_hdr *hdr;
> + struct mgmt_ev_cmd_status *ev;
> +
> + BT_DBG("sock %p", sk);
> +
> + skb = alloc_skb(sizeof(*hdr) + sizeof(*ev), GFP_ATOMIC);
Here you use sizeof(<var>)
> + if (!skb)
> + return;
> +
> + hdr = (void *) skb_put(skb, sizeof(struct mgmt_hdr));
But here you use sizeof(<struct>). Could be sizeof(*hdr) ? Note there
is also the (unused) MGMT_HDR_SIZE.
> +
> + hdr->opcode = cpu_to_le16(MGMT_EV_CMD_STATUS);
> + hdr->len = cpu_to_le16(3);
and here a hard-coded size. Could be sizeof(struct mgmt_ev_cmd_status)
? or maybe create a #define for it?
> +
> + ev = (void *) skb_put(skb, sizeof(*ev));
> + ev->status = status;
> + put_unaligned_le16(cmd, &ev->opcode);
> +
> + if (sock_queue_rcv_skb(sk, skb) < 0)
> + kfree_skb(skb);
> +}
> +
> +int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
> +{
> + unsigned char *buf;
> + struct mgmt_hdr *hdr;
> + u16 opcode, len;
> + int err;
> +
> + BT_DBG("got %zu bytes", msglen);
> +
> + if (msglen < sizeof(*hdr))
> + return -EINVAL;
> +
> + buf = kmalloc(msglen, GFP_ATOMIC);
> + if (!buf)
> + return -ENOMEM;
> +
> + if (memcpy_fromiovec(buf, msg->msg_iov, msglen)) {
> + err = -EFAULT;
> + goto done;
> + }
> +
> + hdr = (struct mgmt_hdr *) buf;
> + opcode = get_unaligned_le16(&hdr->opcode);
> + len = get_unaligned_le16(&hdr->len);
> +
> + if (len != msglen - sizeof(struct mgmt_hdr)) {
You could use sizeof(*hdr) here.
> + err = -EINVAL;
> + goto done;
> + }
> +
> + switch (opcode) {
> + default:
> + BT_DBG("Unknown op %u", opcode);
> + cmd_status(sk, opcode, 0x01);
> + break;
> + }
> +
> + err = msglen;
Would there be a chance of integer overflow here? The function returns
(signed) int, but msglen is (unsigned) size_t.
> +
> +done:
> + kfree(buf);
> + return err;
> +}
Regards,
--
Anderson Lizardo
OpenBossa Labs - INdT
Manaus - Brazil
next prev parent reply other threads:[~2010-12-06 13:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-05 18:19 Initial Management interface patches (rebased) johan.hedberg
2010-12-05 18:19 ` [PATCH 1/3] Bluetooth: Add Bluetooth Management interface definitions johan.hedberg
2010-12-05 18:19 ` [PATCH 2/3] Bluetooth: Add initial Bluetooth Management interface callbacks johan.hedberg
2010-12-06 13:11 ` Anderson Lizardo [this message]
2010-12-06 14:21 ` Johan Hedberg
2010-12-06 20:37 ` Gustavo F. Padovan
2010-12-05 18:19 ` [PATCH 3/3] Bluetooth: Make hci_send_to_sock usable for management control sockets johan.hedberg
-- strict thread matches above, loose matches on Subject: below --
2010-12-07 22:21 Initial Management patches (rebased again) johan.hedberg
2010-12-07 22:21 ` [PATCH 2/3] Bluetooth: Add initial Bluetooth Management interface callbacks johan.hedberg
2010-11-24 14:39 Initial set of Management interface patches johan.hedberg
2010-11-24 14:39 ` [PATCH 2/3] Bluetooth: Add initial Bluetooth Management interface callbacks johan.hedberg
2010-11-24 14:48 ` Marcel Holtmann
2010-11-24 14:55 ` Andrei Emeltchenko
2010-11-24 21:47 ` Johan Hedberg
2010-11-24 21:58 ` Gustavo F. Padovan
2010-11-24 15:38 ` Anderson Lizardo
2010-11-24 19:10 ` Gustavo F. Padovan
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=AANLkTimYKSvo8WpNa-ft61MoBaAgKZxt5j0qVuRBfCb3@mail.gmail.com \
--to=anderson.lizardo@openbossa.org \
--cc=johan.hedberg@gmail.com \
--cc=johan.hedberg@nokia.com \
--cc=linux-bluetooth@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 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).