Skip to content

Commit

Permalink
Bluetooth: hci_sock: Fix not validating setsockopt user input
Browse files Browse the repository at this point in the history
Check user input length before copying data.

Fixes: 09572fc ("Bluetooth: hci_sock: Add support for BT_{SND,RCV}BUF")
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
  • Loading branch information
Vudentz committed Apr 10, 2024
1 parent 9e8742c commit b218606
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions net/bluetooth/hci_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1946,10 +1946,9 @@ static int hci_sock_setsockopt_old(struct socket *sock, int level, int optname,

switch (optname) {
case HCI_DATA_DIR:
if (copy_from_sockptr(&opt, optval, sizeof(opt))) {
err = -EFAULT;
err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, len);
if (err)
break;
}

if (opt)
hci_pi(sk)->cmsg_mask |= HCI_CMSG_DIR;
Expand All @@ -1958,10 +1957,9 @@ static int hci_sock_setsockopt_old(struct socket *sock, int level, int optname,
break;

case HCI_TIME_STAMP:
if (copy_from_sockptr(&opt, optval, sizeof(opt))) {
err = -EFAULT;
err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, len);
if (err)
break;
}

if (opt)
hci_pi(sk)->cmsg_mask |= HCI_CMSG_TSTAMP;
Expand All @@ -1979,11 +1977,9 @@ static int hci_sock_setsockopt_old(struct socket *sock, int level, int optname,
uf.event_mask[1] = *((u32 *) f->event_mask + 1);
}

len = min_t(unsigned int, len, sizeof(uf));
if (copy_from_sockptr(&uf, optval, len)) {
err = -EFAULT;
err = bt_copy_from_sockptr(&uf, sizeof(uf), optval, len);
if (err)
break;
}

if (!capable(CAP_NET_RAW)) {
uf.type_mask &= hci_sec_filter.type_mask;
Expand Down Expand Up @@ -2042,10 +2038,9 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
goto done;
}

if (copy_from_sockptr(&opt, optval, sizeof(opt))) {
err = -EFAULT;
err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, len);
if (err)
break;
}

hci_pi(sk)->mtu = opt;
break;
Expand Down

0 comments on commit b218606

Please sign in to comment.