Bluetooth: Fix ignoring debug keys in mgmt_load_link_keys
Subsystems (2)
PATCH 1/3 Bluetooth: Fix ignoring debug keys in mgmt_load_link_keys
From: Johan Hedberg <[email protected]>
We should never allow user space to feed back debug keys to the kernel. If the user desires to use debug keys require setting the appropriate debug keys mode and performing a new pairing.
--- net/bluetooth/mgmt.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/bluetooth/mgmt.c +6 -0
@@ -2426,6 +2426,12 @@ static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data,for (i =0 ; i < key_count; i++) {struct mgmt_link_key_info *key = &cp->keys[i]; +/* Always ignore debug keys and require a new pairing if +* the user wants to use them. +*/ +if (key->type ==HCI_LK_DEBUG_COMBINATION ) +continue ; +hci_add_link_key (hdev,NULL , &key->addr.bdaddr, key->val, key->type, key->pin_len,NULL ); }
Signature · 1 line
1.9.3
PATCH 2/3 Bluetooth: Add a new HCI_USE_DEBUG_KEYS flag
From: Johan Hedberg <[email protected]>
To pave the way for actively using debug keys for pairing this patch adds a new HCI_USE_DEBUG_KEYS flag for the purpose. When the flag is set we issue a HCI_Write_SSP_Debug mode whenever HCI_Write_SSP_Mode(0x01) has been issued as well as before issuing a HCI_Write_SSP_Mode(0x00) command.
--- include/net/bluetooth/hci.h | 1 + net/bluetooth/mgmt.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-)
include/net/bluetooth/hci.h +1 -0
@@ -125,6 +125,7 @@ enum {HCI_PAIRABLE ,HCI_SERVICE_CACHE ,HCI_KEEP_DEBUG_KEYS , +HCI_USE_DEBUG_KEYS ,HCI_UNREGISTER , HCI_USER_CHANNEL,
net/bluetooth/mgmt.c +10 -2
@@ -1877,6 +1877,10 @@ static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) goto failed; } +if (!cp->val &&test_bit (HCI_USE_DEBUG_KEYS , &hdev->dev_flags)) +hci_send_cmd (hdev,HCI_OP_WRITE_SSP_DEBUG_MODE , +sizeof (cp->val), &cp->val); + err =hci_send_cmd (hdev,HCI_OP_WRITE_SSP_MODE ,1 , &cp->val);if (err <0 ) {mgmt_pending_remove (cmd);
@@ -5784,10 +5788,14 @@ void mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status)hci_req_init (&req, hdev); -if (test_bit (HCI_SSP_ENABLED , &hdev->dev_flags)) +if (test_bit (HCI_SSP_ENABLED , &hdev->dev_flags)) { +if (test_bit (HCI_USE_DEBUG_KEYS , &hdev->dev_flags)) +hci_req_add (&req,HCI_OP_WRITE_SSP_DEBUG_MODE , +sizeof (enable), &enable);update_eir (&req); -else + }else {clear_eir (&req); + }hci_req_run (&req,NULL ); }
Signature · 1 line
1.9.3
PATCH 3/3 Bluetooth: Add support for mode 0x02 for mgmt_set_debug_keys
In reply to [email protected]From: Johan Hedberg <[email protected]>
This patch adds a new valid mode 0x02 for the mgmt_set_debug_keys command. The 0x02 mode sets the HCI_USE_DEBUG_KEYS flag which makes us always use debug keys for pairing.
--- net/bluetooth/mgmt.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
net/bluetooth/mgmt.c +16 -2
@@ -4349,12 +4349,12 @@ static int set_debug_keys(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) {struct mgmt_mode *cp = data; -bool changed; +bool changed, use_changed;int err;BT_DBG ("request for %s" , hdev->name); -if (cp->val !=0x00 && cp->val !=0x01 ) +if (cp->val !=0x00 && cp->val !=0x01 && cp->val !=0x02 )return cmd_status (sk, hdev->id,MGMT_OP_SET_DEBUG_KEYS ,MGMT_STATUS_INVALID_PARAMS );
@@ -4367,6 +4367,20 @@ static int set_debug_keys(struct sock *sk, struct hci_dev *hdev, changed =test_and_clear_bit (HCI_KEEP_DEBUG_KEYS , &hdev->dev_flags); +if (cp->val ==0x02 ) + use_changed = !test_and_set_bit (HCI_USE_DEBUG_KEYS , + &hdev->dev_flags); +else + use_changed =test_and_clear_bit (HCI_USE_DEBUG_KEYS , + &hdev->dev_flags); + +if (hdev_is_powered (hdev) && use_changed && +test_bit (HCI_SSP_ENABLED , &hdev->dev_flags)) { +u8 mode = (cp->val ==0x02 ) ?0x01 :0x00 ; +hci_send_cmd (hdev,HCI_OP_WRITE_SSP_DEBUG_MODE , +sizeof (mode), &mode); + } + err =send_settings_rsp (sk,MGMT_OP_SET_DEBUG_KEYS , hdev);if (err <0 ) goto unlock;
Signature · 1 line
1.9.3
Marcel Holtmann
maintainerHi Johan,
Quoted 8 lines
We should never allow user space to feed back debug keys to the kernel. If the user desires to use debug keys require setting the appropriate debug keys mode and performing a new pairing.
Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/mgmt.c| 6 ++++++1 file changed, 6 insertions(+)
patch has been applied to bluetooth-next tree.
Regards
Marcel
Marcel Holtmann
maintainerRe: [PATCH 2/3] Bluetooth: Add a new HCI_USE_DEBUG_KEYS flag
In reply to [email protected]Hi Johan,
Quoted 11 lines
To pave the way for actively using debug keys for pairing this patch adds a new
HCI_USE_DEBUG_KEYSflag for the purpose. When the flag is set we issue aHCI_Write_SSP_Debugmode wheneverHCI_Write_SSP_Mode(0x01)has been issued as well as before issuing aHCI_Write_SSP_Mode(0x00)command.Signed-off-by Johan Hedberg <[email protected]>---
include/net/bluetooth/hci.h| 1 +net/bluetooth/mgmt.c| 12 ++++++++++--2 files changed, 11 insertions(+), 2 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel
Marcel Holtmann
maintainerRe: [PATCH 3/3] Bluetooth: Add support for mode 0x02 for mgmt_set_debug_keys
In reply to [email protected]Hi Johan,
Quoted 8 lines
This patch adds a new valid mode
0x02for themgmt_set_debug_keyscommand. The0x02mode sets theHCI_USE_DEBUG_KEYSflag which makes us always use debug keys for pairing.Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/mgmt.c| 18 ++++++++++++++++--1 file changed, 16 insertions(+), 2 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel