* [PATCH v3] Bluetooth: Add more enc key size check
@ 2023-12-12 2:30 Alex Lu
2023-12-12 3:04 ` [v3] " bluez.test.bot
2023-12-12 16:30 ` [PATCH v3] " patchwork-bot+bluetooth
0 siblings, 2 replies; 3+ messages in thread
From: Alex Lu @ 2023-12-12 2:30 UTC (permalink / raw)
To: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz,
linux-bluetooth, linux-kernel
Cc: Max Chou, Karen Hsu
From: Alex Lu <alex_lu@realsil.com.cn>
When we are slave role and receives l2cap conn req when encryption has
started, we should check the enc key size to avoid KNOB attack or BLUFFS
attack.
From SIG recommendation, implementations are advised to reject
service-level connections on an encrypted baseband link with key
strengths below 7 octets.
A simple and clear way to achieve this is to place the enc key size
check in hci_cc_read_enc_key_size()
The btmon log below shows the case that lacks enc key size check.
> HCI Event: Connect Request (0x04) plen 10
Address: BB:22:33:44:55:99 (OUI BB-22-33)
Class: 0x480104
Major class: Computer (desktop, notebook, PDA, organizers)
Minor class: Desktop workstation
Capturing (Scanner, Microphone)
Telephony (Cordless telephony, Modem, Headset)
Link type: ACL (0x01)
< HCI Command: Accept Connection Request (0x01|0x0009) plen 7
Address: BB:22:33:44:55:99 (OUI BB-22-33)
Role: Peripheral (0x01)
> HCI Event: Command Status (0x0f) plen 4
Accept Connection Request (0x01|0x0009) ncmd 2
Status: Success (0x00)
> HCI Event: Connect Complete (0x03) plen 11
Status: Success (0x00)
Handle: 1
Address: BB:22:33:44:55:99 (OUI BB-22-33)
Link type: ACL (0x01)
Encryption: Disabled (0x00)
...
> HCI Event: Encryption Change (0x08) plen 4
Status: Success (0x00)
Handle: 1 Address: BB:22:33:44:55:99 (OUI BB-22-33)
Encryption: Enabled with E0 (0x01)
< HCI Command: Read Encryption Key Size (0x05|0x0008) plen 2
Handle: 1 Address: BB:22:33:44:55:99 (OUI BB-22-33)
> HCI Event: Command Complete (0x0e) plen 7
Read Encryption Key Size (0x05|0x0008) ncmd 2
Status: Success (0x00)
Handle: 1 Address: BB:22:33:44:55:99 (OUI BB-22-33)
Key size: 6
// We should check the enc key size
...
> ACL Data RX: Handle 1 flags 0x02 dlen 12
L2CAP: Connection Request (0x02) ident 3 len 4
PSM: 25 (0x0019)
Source CID: 64
< ACL Data TX: Handle 1 flags 0x00 dlen 16
L2CAP: Connection Response (0x03) ident 3 len 8
Destination CID: 64
Source CID: 64
Result: Connection pending (0x0001)
Status: Authorization pending (0x0002)
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 1 Address: BB:22:33:44:55:99 (OUI BB-22-33)
Count: 1
#35: len 16 (25 Kb/s)
Latency: 5 msec (2-7 msec ~4 msec)
< ACL Data TX: Handle 1 flags 0x00 dlen 16
L2CAP: Connection Response (0x03) ident 3 len 8
Destination CID: 64
Source CID: 64
Result: Connection successful (0x0000)
Status: No further information available (0x0000)
Signed-off-by: Alex Lu <alex_lu@realsil.com.cn>
Signed-off-by: Max Chou <max.chou@realtek.com>
---
Changes in v3:
- Use a simple and clear approach according to maintainer's suggestion
Changes in v2:
- Fix compiling issue reported by sparse
net/bluetooth/hci_event.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 2ad7b9f86f74..ef8c3bed7361 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -750,9 +750,23 @@ static u8 hci_cc_read_enc_key_size(struct hci_dev *hdev, void *data,
} else {
conn->enc_key_size = rp->key_size;
status = 0;
+
+ if (conn->enc_key_size < hdev->min_enc_key_size) {
+ /* As slave role, the conn->state has been set to
+ * BT_CONNECTED and l2cap conn req might not be received
+ * yet, at this moment the l2cap layer almost does
+ * nothing with the non-zero status.
+ * So we also clear encrypt related bits, and then the
+ * handler of l2cap conn req will get the right secure
+ * state at a later time.
+ */
+ status = HCI_ERROR_AUTH_FAILURE;
+ clear_bit(HCI_CONN_ENCRYPT, &conn->flags);
+ clear_bit(HCI_CONN_AES_CCM, &conn->flags);
+ }
}
- hci_encrypt_cfm(conn, 0);
+ hci_encrypt_cfm(conn, status);
done:
hci_dev_unlock(hdev);
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [v3] Bluetooth: Add more enc key size check
2023-12-12 2:30 [PATCH v3] Bluetooth: Add more enc key size check Alex Lu
@ 2023-12-12 3:04 ` bluez.test.bot
2023-12-12 16:30 ` [PATCH v3] " patchwork-bot+bluetooth
1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2023-12-12 3:04 UTC (permalink / raw)
To: linux-bluetooth, alex_lu
[-- Attachment #1: Type: text/plain, Size: 2094 bytes --]
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=809021
---Test result---
Test Summary:
CheckPatch PASS 0.66 seconds
GitLint PASS 0.34 seconds
SubjectPrefix PASS 0.13 seconds
BuildKernel PASS 27.61 seconds
CheckAllWarning PASS 30.37 seconds
CheckSparse WARNING 36.53 seconds
CheckSmatch WARNING 98.92 seconds
BuildKernel32 PASS 27.25 seconds
TestRunnerSetup PASS 421.86 seconds
TestRunner_l2cap-tester PASS 22.96 seconds
TestRunner_iso-tester PASS 46.60 seconds
TestRunner_bnep-tester PASS 7.02 seconds
TestRunner_mgmt-tester FAIL 167.54 seconds
TestRunner_rfcomm-tester PASS 11.14 seconds
TestRunner_sco-tester PASS 14.67 seconds
TestRunner_ioctl-tester PASS 12.00 seconds
TestRunner_mesh-tester PASS 8.92 seconds
TestRunner_smp-tester PASS 9.93 seconds
TestRunner_userchan-tester PASS 7.33 seconds
IncrementalBuild PASS 26.08 seconds
Details
##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:
net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 497, Passed: 496 (99.8%), Failed: 1, Not Run: 0
Failed Test Cases
Pairing Acceptor - SMP over BR/EDR 1 Timed out 1.996 seconds
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] Bluetooth: Add more enc key size check
2023-12-12 2:30 [PATCH v3] Bluetooth: Add more enc key size check Alex Lu
2023-12-12 3:04 ` [v3] " bluez.test.bot
@ 2023-12-12 16:30 ` patchwork-bot+bluetooth
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2023-12-12 16:30 UTC (permalink / raw)
To: Alex Lu
Cc: marcel, johan.hedberg, luiz.dentz, linux-bluetooth, linux-kernel,
max.chou, karenhsu
Hello:
This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Tue, 12 Dec 2023 10:30:34 +0800 you wrote:
> From: Alex Lu <alex_lu@realsil.com.cn>
>
> When we are slave role and receives l2cap conn req when encryption has
> started, we should check the enc key size to avoid KNOB attack or BLUFFS
> attack.
> From SIG recommendation, implementations are advised to reject
> service-level connections on an encrypted baseband link with key
> strengths below 7 octets.
> A simple and clear way to achieve this is to place the enc key size
> check in hci_cc_read_enc_key_size()
>
> [...]
Here is the summary with links:
- [v3] Bluetooth: Add more enc key size check
https://git.kernel.org/bluetooth/bluetooth-next/c/19921189d442
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-12-12 16:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-12 2:30 [PATCH v3] Bluetooth: Add more enc key size check Alex Lu
2023-12-12 3:04 ` [v3] " bluez.test.bot
2023-12-12 16:30 ` [PATCH v3] " patchwork-bot+bluetooth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).