Bluetooth: hci_sock: Fix not validating setsockopt user input
[ Upstream commit b2186061d6043d6345a97100460363e990af0d46 ]
Check user input length before copying data.
Fixes: 09572fca72
("Bluetooth: hci_sock: Add support for BT_{SND,RCV}BUF")
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
dd8118ed43
commit
781f3a97a3
@ -1883,10 +1883,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;
|
||||
@ -1895,10 +1894,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;
|
||||
@ -1916,11 +1914,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;
|
||||
@ -1979,10 +1975,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;
|
||||
|
Loading…
Reference in New Issue
Block a user