Bluetooth: hci_sock: Fix not validating setsockopt user input

Check user input length before copying data.

Fixes: 09572fca ("Bluetooth: hci_sock: Add support for BT_{SND,RCV}BUF")
Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
parent 9e8742cd
...@@ -1946,10 +1946,9 @@ static int hci_sock_setsockopt_old(struct socket *sock, int level, int optname, ...@@ -1946,10 +1946,9 @@ static int hci_sock_setsockopt_old(struct socket *sock, int level, int optname,
switch (optname) { switch (optname) {
case HCI_DATA_DIR: case HCI_DATA_DIR:
if (copy_from_sockptr(&opt, optval, sizeof(opt))) { err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, len);
err = -EFAULT; if (err)
break; break;
}
if (opt) if (opt)
hci_pi(sk)->cmsg_mask |= HCI_CMSG_DIR; hci_pi(sk)->cmsg_mask |= HCI_CMSG_DIR;
...@@ -1958,10 +1957,9 @@ static int hci_sock_setsockopt_old(struct socket *sock, int level, int optname, ...@@ -1958,10 +1957,9 @@ static int hci_sock_setsockopt_old(struct socket *sock, int level, int optname,
break; break;
case HCI_TIME_STAMP: case HCI_TIME_STAMP:
if (copy_from_sockptr(&opt, optval, sizeof(opt))) { err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, len);
err = -EFAULT; if (err)
break; break;
}
if (opt) if (opt)
hci_pi(sk)->cmsg_mask |= HCI_CMSG_TSTAMP; hci_pi(sk)->cmsg_mask |= HCI_CMSG_TSTAMP;
...@@ -1979,11 +1977,9 @@ static int hci_sock_setsockopt_old(struct socket *sock, int level, int optname, ...@@ -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); uf.event_mask[1] = *((u32 *) f->event_mask + 1);
} }
len = min_t(unsigned int, len, sizeof(uf)); err = bt_copy_from_sockptr(&uf, sizeof(uf), optval, len);
if (copy_from_sockptr(&uf, optval, len)) { if (err)
err = -EFAULT;
break; break;
}
if (!capable(CAP_NET_RAW)) { if (!capable(CAP_NET_RAW)) {
uf.type_mask &= hci_sec_filter.type_mask; uf.type_mask &= hci_sec_filter.type_mask;
...@@ -2042,10 +2038,9 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname, ...@@ -2042,10 +2038,9 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
goto done; goto done;
} }
if (copy_from_sockptr(&opt, optval, sizeof(opt))) { err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, len);
err = -EFAULT; if (err)
break; break;
}
hci_pi(sk)->mtu = opt; hci_pi(sk)->mtu = opt;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment