Bluetooth: Fix local OOB data handling for SMP
Subsystems (2)
PATCH 1/4 Bluetooth: Fix local OOB data handling for SMP
From: Johan Hedberg <[email protected]>
We need to store the local ra/rb value in order to verify the Check value received from the remote. This patch adds a new 'lr' for the local ra/rb value and makes sure it gets used when verifying the DHKey Check PDU received from the remote.
--- net/bluetooth/smp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/bluetooth/smp.c +5 -2
@@ -95,7 +95,8 @@ struct smp_chan {u8 rrnd[16 ];/* SMP Pairing Random (remote) */ u8 pcnf[16 ];/* SMP Pairing Confirm */ u8 tk[16 ];/* SMP Temporary Key */ -u8 rr[16 ]; +u8 rr[16 ];/* Remote OOB ra/rb value */ +u8 lr[16 ];/* Local OOB ra/rb value */ u8 enc_key_size;u8 remote_key_dist;bdaddr_t id_addr;
@@ -1830,7 +1831,7 @@ static u8 sc_send_public_key(struct smp_chan *smp)memcpy (smp->local_pk, smp_dev->local_pk,64 );memcpy (smp->local_sk, smp_dev->local_sk,32 ); -memcpy (smp->rr, smp_dev->local_rr,16 ); +memcpy (smp->lr, smp_dev->local_rr,16 );if (smp_dev->debug_key)set_bit (SMP_FLAG_DEBUG_KEY , &smp->flags);
@@ -2634,6 +2635,8 @@ static int smp_cmd_dhkey_check(struct l2cap_conn *conn, struct sk_buff *skb)if (smp->method ==REQ_PASSKEY || smp->method ==DSP_PASSKEY )put_unaligned_le32 (hcon->passkey_notify, r); +else if (smp->method ==REQ_OOB ) +memcpy (r, smp->lr,16 ); err =smp_f6 (smp->tfm_cmac, smp->mackey, smp->rrnd, smp->prnd, r, io_cap, remote_addr, local_addr, e);
Signature · 1 line
2.1.0
PATCH 2/4 Bluetooth: Track local vs remote OOB data availability
From: Johan Hedberg <[email protected]>
There are several decisions in the SMP logic that depend not only on whether we're doing SMP or not, but also whether local and/or remote OOB data is present. This patch splits the existing SMP_FLAG_OOB into two new flags to track local and remote OOB data respectively.
--- net/bluetooth/smp.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
net/bluetooth/smp.c +6 -4
@@ -70,7 +70,8 @@ enum {SMP_FLAG_DEBUG_KEY ,SMP_FLAG_WAIT_USER ,SMP_FLAG_DHKEY_PENDING , - SMP_FLAG_OOB, +SMP_FLAG_REMOTE_OOB , + SMP_FLAG_LOCAL_OOB, }; struct smp_dev {
@@ -680,7 +681,7 @@ static void build_pairing_cmd(struct l2cap_conn *conn, oob_data =hci_find_remote_oob_data (hdev, &hcon->dst, bdaddr_type);if (oob_data && oob_data->present) { -set_bit (SMP_FLAG_OOB , &smp->flags); +set_bit (SMP_FLAG_REMOTE_OOB , &smp->flags); oob_flag =SMP_OOB_PRESENT ;memcpy (smp->rr, oob_data->rand256,16 );memcpy (smp->pcnf, oob_data->hash256,16 );
@@ -1820,7 +1821,7 @@ static u8 sc_send_public_key(struct smp_chan *smp)BT_DBG ("" ); -if (test_bit (SMP_FLAG_OOB , &smp->flags)) { +if (test_bit (SMP_FLAG_LOCAL_OOB , &smp->flags)) {struct l2cap_chan *chan = hdev->smp_data;struct smp_dev *smp_dev;
@@ -2453,7 +2454,8 @@ static u8 sc_select_method(struct smp_chan *smp)struct smp_cmd_pairing *local, *remote;u8 local_mitm, remote_mitm, local_io, remote_io, method; -if (test_bit (SMP_FLAG_OOB , &smp->flags)) +if (test_bit (SMP_FLAG_REMOTE_OOB , &smp->flags) || +test_bit (SMP_FLAG_LOCAL_OOB , &smp->flags))return REQ_OOB ;/* The preq/prsp contain the raw Pairing Request/Response PDUs
Signature · 1 line
2.1.0
PATCH 3/4 Bluetooth: Set local OOB data flag if remote has our OOB data
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
If the SMP Pairing Request or Response PDU received from the remote device indicates that it has received our OOB data we should set the SMP_FLAG_LOCAL_OOB flag.
--- net/bluetooth/smp.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/bluetooth/smp.c +6 -0
@@ -1735,6 +1735,9 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)memcpy (&smp->preq[1 ], req,sizeof (*req));skb_pull (skb,sizeof (*req)); +if (req->oob_flag ==SMP_OOB_PRESENT ) +set_bit (SMP_FLAG_LOCAL_OOB , &smp->flags); +/* SMP over BR/EDR requires special treatment */ if (conn->hcon->type ==ACL_LINK ) {/* We must have a BR/EDR SC link */
@@ -1899,6 +1902,9 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb)if (hci_dev_test_flag (hdev,HCI_SC_ONLY ) && !(auth &SMP_AUTH_SC ))return SMP_AUTH_REQUIREMENTS ; +if (rsp->oob_flag ==SMP_OOB_PRESENT ) +set_bit (SMP_FLAG_LOCAL_OOB , &smp->flags); + smp->prsp[0 ] =SMP_CMD_PAIRING_RSP ;memcpy (&smp->prsp[1 ], rsp,sizeof (*rsp));
Signature · 1 line
2.1.0
PATCH 4/4 Bluetooth: Fix verifying confirm value when lacking remote OOB data
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
If we haven't received remote OOB data we cannot perform any special checks on the confirm value. This patch updates the check after having received the public key to only perform the verification if we have remote OOB data present.
--- net/bluetooth/smp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/bluetooth/smp.c +3 -1
@@ -2562,7 +2562,7 @@ static int smp_cmd_public_key(struct l2cap_conn *conn, struct sk_buff *skb)return sc_passkey_round (smp,SMP_CMD_PUBLIC_KEY ); } -if (smp->method ==REQ_OOB ) { +if (test_bit (SMP_FLAG_REMOTE_OOB , &smp->flags)) { err =smp_f4 (smp->tfm_cmac, smp->remote_pk, smp->remote_pk, smp->rr,0 , cfm.confirm_val);if (err)
@@ -2570,7 +2570,9 @@ static int smp_cmd_public_key(struct l2cap_conn *conn, struct sk_buff *skb)if (memcmp (cfm.confirm_val, smp->pcnf,16 ))return SMP_CONFIRM_FAILED ; + } +if (smp->method ==REQ_OOB ) {if (hcon->out)smp_send_cmd (conn,SMP_CMD_PAIRING_RANDOM ,sizeof (smp->prnd), smp->prnd);
Signature · 1 line
2.1.0
Marcel Holtmann
maintainerHi Johan,
Quoted 9 lines
We need to store the local ra/rb value in order to verify the Check value received from the remote. This patch adds a new 'lr' for the local ra/rb value and makes sure it gets used when verifying the DHKey Check PDU received from the remote.
Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/smp.c| 7 +++++--1 file changed, 5 insertions(+), 2 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel
Marcel Holtmann
maintainerRe: [PATCH 2/4] Bluetooth: Track local vs remote OOB data availability
In reply to Johan HedbergHi Johan,
Quoted 9 lines
There are several decisions in the SMP logic that depend not only on whether we're doing SMP or not, but also whether local and/or remote OOB data is present. This patch splits the existing
SMP_FLAG_OOBinto two new flags to track local and remote OOB data respectively.Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/smp.c| 10 ++++++----1 file changed, 6 insertions(+), 4 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel
Marcel Holtmann
maintainerRe: [PATCH 3/4] Bluetooth: Set local OOB data flag if remote has our OOB data
In reply to Johan HedbergHi Johan,
Quoted 8 lines
If the SMP Pairing Request or Response PDU received from the remote device indicates that it has received our OOB data we should set the
SMP_FLAG_LOCAL_OOBflag.Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/smp.c| 6 ++++++1 file changed, 6 insertions(+)
patch has been applied to bluetooth-next tree.
Regards
Marcel
Marcel Holtmann
maintainerRe: [PATCH 4/4] Bluetooth: Fix verifying confirm value when lacking remote OOB data
In reply to Johan HedbergHi Johan,
Quoted 9 lines
If we haven't received remote OOB data we cannot perform any special checks on the confirm value. This patch updates the check after having received the public key to only perform the verification if we have remote OOB data present.
Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/smp.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel