[SRU][F][PATCH 1/5] Bluetooth: SCO: Fix not validating setsockopt user input
Koichiro Den
koichiro.den at canonical.com
Mon Oct 28 07:58:56 UTC 2024
From: Luiz Augusto von Dentz <luiz.von.dentz at intel.com>
[ Upstream commit 51eda36d33e43201e7a4fd35232e069b2c850b01 ]
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: ad10b1a48754 ("Bluetooth: Add Bluetooth socket voice option")
Fixes: b96e9c671b05 ("Bluetooth: Add BT_DEFER_SETUP option to sco socket")
Fixes: 00398e1d5183 ("Bluetooth: Add support for BT_PKT_STATUS CMSG data for SCO connections")
Fixes: f6873401a608 ("Bluetooth: Allow setting of codec for HFP offload use case")
Reported-by: syzbot <syzkaller at googlegroups.com>
Signed-off-by: Eric Dumazet <edumazet at google.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz at intel.com>
Signed-off-by: Sasha Levin <sashal at kernel.org>
(backported from commit b0e30c37695b614bee69187f86eaf250e36606ce linux-5.10.y)
[koichiroden: Due to the absence of the entire patch series
"get rid of the address_space override in setsockopt v2"
(https://lore.kernel.org/all/20200723060908.50081-1-hch@lst.de/),
newly introduced bt_copy_from_user replacing bt_copy_from_sockptr.
Also dropped changed on BT_PKT_STATUS case, which does not exist in this
tree due to missing commit:
00398e1d5183 ("Bluetooth: Add support for BT_PKT_STATUS CMSG data for SCO connections")]
CVE-2024-35967
Signed-off-by: Koichiro Den <koichiro.den at canonical.com>
---
include/net/bluetooth/bluetooth.h | 9 +++++++++
net/bluetooth/sco.c | 14 ++++++--------
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 421d41ef4e9c..60b7d267e3f8 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -435,6 +435,15 @@ static inline struct sk_buff *bt_skb_sendmmsg(struct sock *sk,
return skb;
}
+static inline int bt_copy_from_user(void *dst, size_t dst_size,
+ const void __user *src, size_t src_size)
+{
+ if (dst_size > src_size)
+ return -EINVAL;
+
+ return copy_from_user(dst, src, dst_size);
+}
+
int bt_to_errno(u16 code);
void hci_sock_set_flag(struct sock *sk, int nr);
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 92e0712edf8d..78798284484f 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -817,7 +817,7 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname,
char __user *optval, unsigned int optlen)
{
struct sock *sk = sock->sk;
- int len, err = 0;
+ int err = 0;
struct bt_voice voice;
u32 opt;
@@ -833,10 +833,9 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname,
break;
}
- if (get_user(opt, (u32 __user *) optval)) {
- err = -EFAULT;
+ err = bt_copy_from_user(&opt, sizeof(opt), optval, optlen);
+ if (err)
break;
- }
if (opt)
set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
@@ -853,11 +852,10 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname,
voice.setting = sco_pi(sk)->setting;
- len = min_t(unsigned int, sizeof(voice), optlen);
- if (copy_from_user((char *)&voice, optval, len)) {
- err = -EFAULT;
+ err = bt_copy_from_user(&voice, sizeof(voice), optval,
+ optlen);
+ if (err)
break;
- }
/* Explicitly check for these values */
if (voice.setting != BT_VOICE_TRANSPARENT &&
--
2.43.0
More information about the kernel-team
mailing list