mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-05-15 04:06:18 +00:00
Bluetooth: SCO: Fix not validating setsockopt user input
syzbot reported sco_sock_setsockopt() is copying data without checking user input length. BUG: KASAN: slab-out-of-bounds in copy_from_sockptr_offset include/linux/sockptr.h:49 [inline] BUG: KASAN: slab-out-of-bounds in copy_from_sockptr include/linux/sockptr.h:55 [inline] BUG: KASAN: slab-out-of-bounds in sco_sock_setsockopt+0xc0b/0xf90 net/bluetooth/sco.c:893 Read of size 4 at addr ffff88805f7b15a3 by task syz-executor.5/12578 Fixes:ad10b1a487
("Bluetooth: Add Bluetooth socket voice option") Fixes:b96e9c671b
("Bluetooth: Add BT_DEFER_SETUP option to sco socket") Fixes:00398e1d51
("Bluetooth: Add support for BT_PKT_STATUS CMSG data for SCO connections") Fixes:f6873401a6
("Bluetooth: Allow setting of codec for HFP offload use case") Reported-by: syzbot <syzkaller@googlegroups.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
45d355a926
commit
51eda36d33
2 changed files with 19 additions and 13 deletions
|
@ -585,6 +585,15 @@ static inline struct sk_buff *bt_skb_sendmmsg(struct sock *sk,
|
||||||
return skb;
|
return skb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int bt_copy_from_sockptr(void *dst, size_t dst_size,
|
||||||
|
sockptr_t src, size_t src_size)
|
||||||
|
{
|
||||||
|
if (dst_size > src_size)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
return copy_from_sockptr(dst, src, dst_size);
|
||||||
|
}
|
||||||
|
|
||||||
int bt_to_errno(u16 code);
|
int bt_to_errno(u16 code);
|
||||||
__u8 bt_status(int err);
|
__u8 bt_status(int err);
|
||||||
|
|
||||||
|
|
|
@ -824,7 +824,7 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname,
|
||||||
sockptr_t optval, unsigned int optlen)
|
sockptr_t optval, unsigned int optlen)
|
||||||
{
|
{
|
||||||
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
||||||
int len, err = 0;
|
int err = 0;
|
||||||
struct bt_voice voice;
|
struct bt_voice voice;
|
||||||
u32 opt;
|
u32 opt;
|
||||||
struct bt_codecs *codecs;
|
struct bt_codecs *codecs;
|
||||||
|
@ -843,10 +843,9 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
|
err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, optlen);
|
||||||
err = -EFAULT;
|
if (err)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if (opt)
|
if (opt)
|
||||||
set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
|
set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
|
||||||
|
@ -863,11 +862,10 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname,
|
||||||
|
|
||||||
voice.setting = sco_pi(sk)->setting;
|
voice.setting = sco_pi(sk)->setting;
|
||||||
|
|
||||||
len = min_t(unsigned int, sizeof(voice), optlen);
|
err = bt_copy_from_sockptr(&voice, sizeof(voice), optval,
|
||||||
if (copy_from_sockptr(&voice, optval, len)) {
|
optlen);
|
||||||
err = -EFAULT;
|
if (err)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
/* Explicitly check for these values */
|
/* Explicitly check for these values */
|
||||||
if (voice.setting != BT_VOICE_TRANSPARENT &&
|
if (voice.setting != BT_VOICE_TRANSPARENT &&
|
||||||
|
@ -890,10 +888,9 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BT_PKT_STATUS:
|
case BT_PKT_STATUS:
|
||||||
if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
|
err = bt_copy_from_sockptr(&opt, sizeof(opt), optval, optlen);
|
||||||
err = -EFAULT;
|
if (err)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if (opt)
|
if (opt)
|
||||||
set_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags);
|
set_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags);
|
||||||
|
@ -934,9 +931,9 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy_from_sockptr(buffer, optval, optlen)) {
|
err = bt_copy_from_sockptr(buffer, optlen, optval, optlen);
|
||||||
|
if (err) {
|
||||||
hci_dev_put(hdev);
|
hci_dev_put(hdev);
|
||||||
err = -EFAULT;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue