Module Name:src
Committed By: martin
Date: Sat Sep 28 07:50:23 UTC 2019
Modified Files:
src/sys/netbt [netbsd-7]: hci.h hci_event.c
Log Message:
Pull up following revision(s) (requested by plunky in ticket #1709):
sys/netbt/hci_event.c: revision 1.26
sys/netbt/hci.h: revision 1.46
When encrypted connections are configured, verify that the encryption
key length has a minimum size when the adaptor supports that.
This addresses the 'Key Negotiation of Bluetooth' attack, CVE-2019-9506
https://www.bluetooth.com/security/statement-key-negotiation-of-bluetooth/
To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.39.2.1 src/sys/netbt/hci.h
cvs rdiff -u -r1.23 -r1.23.28.1 src/sys/netbt/hci_event.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/netbt/hci.h
diff -u src/sys/netbt/hci.h:1.39 src/sys/netbt/hci.h:1.39.2.1
--- src/sys/netbt/hci.h:1.39 Tue Jul 1 05:49:18 2014
+++ src/sys/netbt/hci.h Sat Sep 28 07:50:23 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: hci.h,v 1.39 2014/07/01 05:49:18 rtr Exp $ */
+/* $NetBSD: hci.h,v 1.39.2.1 2019/09/28 07:50:23 martin Exp $ */
/*-
* Copyright (c) 2005 Iain Hibbert.
@@ -54,7 +54,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: hci.h,v 1.39 2014/07/01 05:49:18 rtr Exp $
+ * $Id: hci.h,v 1.39.2.1 2019/09/28 07:50:23 martin Exp $
* $FreeBSD: src/sys/netgraph/bluetooth/include/ng_hci.h,v 1.6 2005/01/07 01:45:43 imp Exp $
*/
@@ -1786,6 +1786,17 @@ typedef struct {
uint16_t accuracy; /* clock accuracy */
} __packed hci_read_clock_rp;
+#define HCI_OCF_READ_ENCRYPTION_KEY_SIZE 0x0008
+#define HCI_CMD_READ_ENCRYPTION_KEY_SIZE 0x1408
+typedef struct {
+ uint16_t con_handle; /* connection handle */
+} __packed hci_read_encryption_key_size_cp;
+
+typedef struct {
+ uint8_t status; /* 0x00 - success */
+ uint16_t con_handle; /* connection handle */
+ uint8_t size; /* key size */
+} __packed hci_read_encryption_key_size_rp;
/**
**
Index: src/sys/netbt/hci_event.c
diff -u src/sys/netbt/hci_event.c:1.23 src/sys/netbt/hci_event.c:1.23.28.1
--- src/sys/netbt/hci_event.c:1.23 Wed Jul 27 10:25:09 2011
+++ src/sys/netbt/hci_event.c Sat Sep 28 07:50:23 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: hci_event.c,v 1.23 2011/07/27 10:25:09 plunky Exp $ */
+/* $NetBSD: hci_event.c,v 1.23.28.1 2019/09/28 07:50:23 martin Exp $ */
/*-
* Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
*/
#include
-__KERNEL_RCSID(0, "$NetBSD: hci_event.c,v 1.23 2011/07/27 10:25:09 plunky Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hci_event.c,v 1.23.28.1 2019/09/28 07:50:23 martin Exp $");
#include
#include
@@ -63,6 +63,7 @@ static void hci_cmd_read_local_features(
static void hci_cmd_read_local_extended_features(struct hci_unit *, struct mbuf *);
static void hci_cmd_read_local_ver(struct hci_unit *, struct mbuf *);
static void hci_cmd_read_local_commands(struct hci_unit *, struct mbuf *);
+static void hci_cmd_read_encryption_key_size(struct hci_unit *, struct mbuf *);
static void hci_cmd_reset(struct hci_unit *, struct mbuf *);
static void hci_cmd_create_con(struct hci_unit *unit, uint8_t status);
@@ -351,6 +352,10 @@ hci_event_command_compl(struct hci_unit
hci_cmd_read_local_commands(unit, m);
break;
+ case HCI_CMD_READ_ENCRYPTION_KEY_SIZE:
+ hci_cmd_read_encryption_key_size(unit, m);
+ break;
+
case HCI_CMD_RESET:
hci_cmd_reset(unit, m);
break;
@@ -618,10 +623,11 @@ hci_event_con_compl(struct hci_unit *uni
return;
}
- /* XXX could check auth_enable here */
-
- if (ep.encryption_mode)
- link->hl_flags |= (HCI_LINK_AUTH | HCI_LINK_ENCRYPT);
+ /*
+ * We purposefully ignore ep.encryption_mode here - if that is set then
+ * the link will be authenticated and encrypted, but we still want to
+ * verify the key size and setmode sets the right flags
+ */
link->hl_state = HCI_LINK_OPEN;
link->hl_handle = HCI_CON_HANDLE(le16toh(ep.con_handle));
@@ -772,17 +778,16 @@ hci_event_auth_compl(struct hci_unit *un
/*
* Encryption Change
*
- * The encryption status has changed. Basically, we note the change
- * then notify the upper layer protocol unless further mode changes
- * are pending.
- * Note that if encryption gets disabled when it has been requested,
- * we will attempt to enable it again.. (its a feature not a bug :)
+ * The encryption status has changed. Make a note if disabled, or
+ * check the key size if possible before allowing it is enabled.
+ * (checking of key size was enabled in 3.0 spec)
*/
static void
hci_event_encryption_change(struct hci_unit *unit, struct mbuf *m)
{
hci_encryption_change_ep ep;
struct hci_link *link;
+ uint16_t con_handle;
int err;
if (m->m_pkthdr.len < sizeof(ep))
@@