Skip to contentSkip to conversation

Bluetooth: hci_sock: fix endian bug in hci_sock_setsockopt()

PATCH In review Dan Carpenter 2 participants 2 messages Jan 7, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bluetooth: hci_sock: fix endian bug in hci_sock_setsockopt()

This copies a u16 into the high bits of an int, which works on a big endian system but not on a little endian system.

Fixes 09572fca7223 ("Bluetooth: hci_sock: Add support for BT_{SND,RCV}BUF")
---
 net/bluetooth/hci_sock.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/bluetooth/hci_sock.c +3 -2
index 446573a12571..33b3c0ffc339 100644
@@ -1911,7 +1911,8 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
 			       sockptr_t optval, unsigned int len)
 {
 	struct sock *sk = sock->sk;
-	int err = 0, opt = 0;
+	int err = 0;
+	u16 opt;
 
 	BT_DBG("sk %p, opt %d", sk, optname);
 
@@ -1937,7 +1938,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
 			goto done;
 		}
 
-		if (copy_from_sockptr(&opt, optval, sizeof(u16))) {
+		if (copy_from_sockptr(&opt, optval, sizeof(opt))) {
 			err = -EFAULT;
 			break;
 		}
Signature · 1 line
2.20.1
maintainer
#1 lore raw

Hi Dan,

Quoted 8 lines

This copies a u16 into the high bits of an int, which works on a big endian system but not on a little endian system.

Fixes 09572fca7223 ("Bluetooth: hci_sock: Add support for BT_{SND,RCV}BUF")

---
net/bluetooth/hci_sock.c | 5 +++--

1 file changed, 3 insertions(+), 2 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel