Skip to content

Commit fe4840d

Browse files
committed
Bluetooth: SMP: If an unallowed command is received consider it a failure
If a command is received while a bonding is ongoing consider it a pairing failure so the session is cleanup properly and the device is disconnected immediately instead of continuing with other commands that may result in the session to get stuck without ever completing such as the case bellow: > ACL Data RX: Handle 2048 flags 0x02 dlen 21 SMP: Identity Information (0x08) len 16 Identity resolving key[16]: d7e08edef97d3e62cd2331f82d8073b0 > ACL Data RX: Handle 2048 flags 0x02 dlen 21 SMP: Signing Information (0x0a) len 16 Signature key[16]: 1716c536f94e843a9aea8b13ffde477d Bluetooth: hci0: unexpected SMP command 0x0a from XX:XX:XX:XX:XX:XX > ACL Data RX: Handle 2048 flags 0x02 dlen 12 SMP: Identity Address Information (0x09) len 7 Address: XX:XX:XX:XX:XX:XX (Intel Corporate) While accourding to core spec 6.1 the expected order is always BD_ADDR first first then CSRK: When using LE legacy pairing, the keys shall be distributed in the following order: LTK by the Peripheral EDIV and Rand by the Peripheral IRK by the Peripheral BD_ADDR by the Peripheral CSRK by the Peripheral LTK by the Central EDIV and Rand by the Central IRK by the Central BD_ADDR by the Central CSRK by the Central When using LE Secure Connections, the keys shall be distributed in the following order: IRK by the Peripheral BD_ADDR by the Peripheral CSRK by the Peripheral IRK by the Central BD_ADDR by the Central CSRK by the Central According to the Core 6.1 for commands used for key distribution "Key Rejected" can be used: '3.6.1. Key distribution and generation A device may reject a distributed key by sending the Pairing Failed command with the reason set to "Key Rejected". Fixes: b28b494 ("Bluetooth: Add strict checks for allowed SMP PDUs") Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 6ec3185 commit fe4840d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

net/bluetooth/smp.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2977,8 +2977,25 @@ static int smp_sig_channel(struct l2cap_chan *chan, struct sk_buff *skb)
29772977
if (code > SMP_CMD_MAX)
29782978
goto drop;
29792979

2980-
if (smp && !test_and_clear_bit(code, &smp->allow_cmd))
2980+
if (smp && !test_and_clear_bit(code, &smp->allow_cmd)) {
2981+
/* If there is a context and the command is not allowed consider
2982+
* it a failure so the session is cleanup properly.
2983+
*/
2984+
switch (code) {
2985+
case SMP_CMD_IDENT_INFO:
2986+
case SMP_CMD_IDENT_ADDR_INFO:
2987+
case SMP_CMD_SIGN_INFO:
2988+
/* 3.6.1. Key distribution and generation
2989+
*
2990+
* A device may reject a distributed key by sending the
2991+
* Pairing Failed command with the reason set to
2992+
* "Key Rejected".
2993+
*/
2994+
smp_failure(conn, SMP_KEY_REJECTED);
2995+
break;
2996+
}
29812997
goto drop;
2998+
}
29822999

29833000
/* If we don't have a context the only allowed commands are
29843001
* pairing request and security request.

net/bluetooth/smp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ struct smp_cmd_keypress_notify {
138138
#define SMP_NUMERIC_COMP_FAILED 0x0c
139139
#define SMP_BREDR_PAIRING_IN_PROGRESS 0x0d
140140
#define SMP_CROSS_TRANSP_NOT_ALLOWED 0x0e
141+
#define SMP_KEY_REJECTED 0x0f
141142

142143
#define SMP_MIN_ENC_KEY_SIZE 7
143144
#define SMP_MAX_ENC_KEY_SIZE 16

0 commit comments

Comments
 (0)