Skip to contentSkip to conversation

Re [PATCH] Bluetooth: Fix the vulnerable issue on enc key size

DISCUSSION 陆朱伟 1 participant 1 message Sep 28, 2020 Bluetooth drivers

lore
Share & tools
lore

陆朱伟

author
#0 lore raw

Hi Marcel,

Quoted 156 lines · Marcel Holtmann

Hi Alex,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

When someone attacks the service provider, it creates connection, authenticates. Then it requests key size of one byte and it identifies the key with brute force methods.

After l2cap info req/resp exchange is complete. the attacker sends

l2cap

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

connect with specific PSM.

In above procedure, there is no chance for the service provider to

check

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

the encryption key size before l2cap_connect(). Because the state of l2cap chan in conn->chan_l is BT_LISTEN, there is no l2cap chan with

the

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

state of BT_CONNECT or BT_CONNECT2.

So service provider should check the encryption key size in l2cap_connect()

---
net/bluetooth/l2cap_core.c | 7 +++++++

1 file changed, 7 insertions(+)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

net/bluetooth/l2cap_core.c static struct l2cap_chan

Quoted 5 lines
net/bluetooth/l2cap_core.c +0 -0
index ade83e224567..63df961d402d 100644
@@ -4150,6 +4150,13 @@ static struct l2cap_chan

*l2cap_connect(struct

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

l2cap_conn *conn,

net/bluetooth/l2cap_core.c static struct l2cap_chan · line 4152

Quoted 4 lines
net/bluetooth/l2cap_core.c +1 -0
 	if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE) {
 		if (l2cap_chan_check_security(chan, false)) {
+			if (!l2cap_check_enc_key_size(conn->hcon))

{

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

net/bluetooth/l2cap_core.c static struct l2cap_chan · line 4153

Quoted 1 line
net/bluetooth/l2cap_core.c +1 -0
+				l2cap_state_change(chan,

BT_DISCONN);

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

net/bluetooth/l2cap_core.c static struct l2cap_chan · line 4154

Quoted 1 line
net/bluetooth/l2cap_core.c +1 -0
+				__set_chan_timer(chan,

L2CAP_DISC_TIMEOUT);

net/bluetooth/l2cap_core.c static struct l2cap_chan · line 4161

Quoted 7 lines
net/bluetooth/l2cap_core.c +4 -0
+				result = L2CAP_CR_SEC_BLOCK;
+				status = L2CAP_CS_NO_INFO;
+				goto response;
+			}
 			if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) {
 				l2cap_state_change(chan, BT_CONNECT2);
 				result = L2CAP_CR_PEND;

I am not following what you are trying to fix here. Can you show this

with

Quoted 5 lines
Quoted 5 lines

a

Quoted 4 lines
Quoted 4 lines

btmon trace from an attacking device?

Regards

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Marcel

I'm sorry, I didn't have btmon trace from an attacking device. I didn't have the real attacking device. I just simulate the attacking. I have a device that can create one byte size encryption key. It uses the link key that was produced by pairing with the service

provider.

Quoted 1 line
Quoted 1 line

Actually the KNOB (Key Negotiation of Bluetooth Attack) says, the link key

is

Quoted 2 lines
Quoted 2 lines

unnecessary for the reconnection.

Quoted 1 line

I use this device to reconnect to service provider, and then initiate the

Key

Quoted 1 line
Quoted 1 line

Negotiation for one byte size encryption key. Actually the attacker

identified

Quoted 8 lines
Quoted 6 lines

the encryption key with some brute force methods.

Quoted 2 lines

I want to provide the trace on service provider side.

what kernel version are you running? I wonder if we should always return L2CAP_CR_PEND here. Do you have a reproducer code?

I'm running kernel 5.8.0-rc6 on acceptor and kernel 5.8.5 on the initiator

which acts as an attacker.

Quoted 2 lines

For the attack simulation, some code needs to be changed on each size. On the acceptor, the master parameter for bt_io_listen() in bluetoothd

should be changed to FALSE in profiles/audio/a2dp.c a2dp_server_listen() and profiles/audio/avctp.c avctp_server_socket().

Quoted 1 line

The change makes the kernel not to change the role to master when it

receives hci conn req event.

Quoted 1 line

I did the change in order to make the controller to send

LMP_ENCRYPTION_KEY_SIZE_REQ PDU for one byte key size.

Review static void l2cap_conn_start(struct l2cap_conn

Quoted 3 lines

On the initiator, the below encryption key size check should be removed.

(quoted diff) +0 -0
@@ -1622,10 +1624,13 @@ static void l2cap_conn_start(struct l2cap_conn

*conn)

Quoted 15 lines
(quoted diff) +7 -4
                               continue;
                       }
 
-                       if (l2cap_check_enc_key_size(conn->hcon))
-                               l2cap_start_connection(chan);
-                       else
-                               l2cap_chan_close(chan, ECONNREFUSED);
+                       /* Just simulate KNOB */
+                       l2cap_start_connection(chan);
+                       /* if (l2cap_check_enc_key_size(conn->hcon))
+                        *      l2cap_start_connection(chan);
+                        * else
+                        *      l2cap_chan_close(chan, ECONNREFUSED);
+                        */
 
Quoted 7 lines

At last, I did the test as below:
1. On the initiator, pair acceptor
2. Run l2test -r -P 3 on the acceptor
3. Run l2test -n -P 3 <bdaddr> on the initiator

Quoted 2 lines

The problem really is that the MASK_REQ_DONE indication is not enough

to

Quoted 1 line
Quoted 1 line

make a decision for the key size. We have to ensure that also the key size

is

Quoted 5 lines
Quoted 3 lines

actually available. If that is not yet done, then we should not check it. This means that any response to L2CAP_Connect_Request PDU needs to be delayed until the key size has been read.

In my test case, the key size has been read from controller before the l2cap

conn request PDU is received.

Quoted 2 lines

< HCI Command: Read Encryption Key Size (0x05|0x0008) plen 2

#22 [hci0] 43.089859

Quoted 2 lines

Handle: 1

Quoted 1 line

HCI Event: Command Complete (0x0e) plen 7

#23 [hci0] 43.091528

Quoted 5 lines
     Read Encryption Key Size (0x05|0x0008) ncmd 2
       Status: Success (0x00)
       Handle: 1
       Key size: 1
Quoted 1 line

ACL Data RX: Handle 1 flags 0x02 dlen 10 #24

[hci0] 43.140888

Quoted 4 lines
     L2CAP: Information Request (0x0a) ident 1 len 2
       Type: Extended features supported (0x0002)

......

Quoted 1 line

ACL Data RX: Handle 1 flags 0x02 dlen 12 #34

[hci0] 43.148405

Quoted 3 lines
     L2CAP: Connection Request (0x02) ident 3 len 4
       PSM: 3 (0x0003)
       Source CID: 64

the easiest way to fake this is just to assign a different value than the one returned by Read Encryption Key Size on the acceptor side. No need to mess with LMP details.

net/bluetooth/hci_event.c +0 -0
index 1df95145f574..741b7ad31ff8 100644

net/bluetooth/hci_event.c static void read_enc_key_size_complete(struct · line 3039

Quoted 7 lines
net/bluetooth/hci_event.c +1 -1
@@ -3034,7 +3034,7 @@ static void read_enc_key_size_complete(struct
 hci_dev *hdev, u8 status,
                           handle);
                conn->enc_key_size = 0;
        } else {
-               conn->enc_key_size = rp->key_size;
+               conn->enc_key_size = 1;
        }

Yes, you're right. Just to assign a different value is the easiest way.
Previously I struggled to provide complete evidence for qualification test, so I made the change a bit more complicated. I'm sorry to mess it.

Quoted 5 lines

If you add this change to both sides, what are the steps to reproduce this and what does btmon show? You might have to also enable dynamic_debug for l2cap.ko so that we see the function call trace.

Quoted 8 lines

I am a bit pedantic with this one, since it is critical to understand where the current changes to handle anything KNOB related have their shortcomings. I spent so much time testing every single corner case. Certainly I could have missed something, but if I really did, this time around I want to either simplify the code or properly comment it at least.

Please see the other email thread / patch from Archie trying to also add another encryption key size check.

Thanks for your remainder. It seems that Archie and I have encountered the same problem. I also found this when I did the qualification.

Quoted 6 lines

Regards

Marcel