Skip to content

Commit 000c2fa

Browse files
lrh2000Vudentz
authored andcommitted
bluetooth: Add cmd validity checks at the start of hci_sock_ioctl()
Previously, channel open messages were always sent to monitors on the first ioctl() call for unbound HCI sockets, even if the command and arguments were completely invalid. This can leave an exploitable hole with the abuse of invalid ioctl calls. This commit hardens the ioctl processing logic by first checking if the command is valid, and immediately returning with an ENOIOCTLCMD error code if it is not. This ensures that ioctl calls with invalid commands are free of side effects, and increases the difficulty of further exploitation by forcing exploitation to find a way to pass a valid command first. Signed-off-by: Ruihan Li <lrh2000@pku.edu.cn> Co-developed-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent db2bf51 commit 000c2fa

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

net/bluetooth/hci_sock.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,34 @@ static int hci_sock_ioctl(struct socket *sock, unsigned int cmd,
987987

988988
BT_DBG("cmd %x arg %lx", cmd, arg);
989989

990+
/* Make sure the cmd is valid before doing anything */
991+
switch (cmd) {
992+
case HCIGETDEVLIST:
993+
case HCIGETDEVINFO:
994+
case HCIGETCONNLIST:
995+
case HCIDEVUP:
996+
case HCIDEVDOWN:
997+
case HCIDEVRESET:
998+
case HCIDEVRESTAT:
999+
case HCISETSCAN:
1000+
case HCISETAUTH:
1001+
case HCISETENCRYPT:
1002+
case HCISETPTYPE:
1003+
case HCISETLINKPOL:
1004+
case HCISETLINKMODE:
1005+
case HCISETACLMTU:
1006+
case HCISETSCOMTU:
1007+
case HCIINQUIRY:
1008+
case HCISETRAW:
1009+
case HCIGETCONNINFO:
1010+
case HCIGETAUTHINFO:
1011+
case HCIBLOCKADDR:
1012+
case HCIUNBLOCKADDR:
1013+
break;
1014+
default:
1015+
return -ENOIOCTLCMD;
1016+
}
1017+
9901018
lock_sock(sk);
9911019

9921020
if (hci_pi(sk)->channel != HCI_CHANNEL_RAW) {

0 commit comments

Comments
 (0)