Skip to contentSkip to conversation

Bluetooth: Prevent uninitialized data access in L2CAP configuration

PATCH In review Mat Martineau 3 participants 3 messages Dec 9, 2011 – Dec 19, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Bluetooth: Prevent uninitialized data access in L2CAP configuration

When configuring an ERTM or streaming mode connection, remote devices are expected to send an RFC option in a successful config response. A misbehaving remote device might not send an RFC option, and the L2CAP code should not access uninitialized data in this case.

---
 net/bluetooth/l2cap_core.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
net/bluetooth/l2cap_core.c +10 -1
index 5ea94a1..45dd423 100644
@@ -2152,7 +2152,7 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
 	void *ptr = req->data;
 	int type, olen;
 	unsigned long val;
-	struct l2cap_conf_rfc rfc;
+	struct l2cap_conf_rfc rfc = { .mode = L2CAP_MODE_BASIC };
 
 	BT_DBG("chan %p, rsp %p, len %d, req %p", chan, rsp, len, data);
 
@@ -2271,6 +2271,15 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
 		}
 	}
 
+	/* Use sane default values in case a misbehaving remote device
+	 * did not send an RFC option.
+	 */
+	BT_ERR("Expected RFC option was not found, using defaults");
+	rfc.mode = chan->mode;
+	rfc.retrans_timeout = cpu_to_le16(L2CAP_DEFAULT_RETRANS_TO);
+	rfc.monitor_timeout = cpu_to_le16(L2CAP_DEFAULT_MONITOR_TO);
+	rfc.max_pdu_size = cpu_to_le16(chan->imtu);
+
 done:
 	switch (rfc.mode) {
 	case L2CAP_MODE_ERTM:
Signature · 6 lines
1.7.8

--
Mat Martineau
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
maintainer Acked-by on v2 1/1
#1 lore raw

Hi Mat,

Quoted 25 lines

When configuring an ERTM or streaming mode connection, remote devices are expected to send an RFC option in a successful config response. A misbehaving remote device might not send an RFC option, and the L2CAP code should not access uninitialized data in this case.

---
 net/bluetooth/l2cap_core.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
net/bluetooth/l2cap_core.c +1 -1
index 5ea94a1..45dd423 100644
@@ -2152,7 +2152,7 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
 	void *ptr = req->data;
 	int type, olen;
 	unsigned long val;
-	struct l2cap_conf_rfc rfc;
+	struct l2cap_conf_rfc rfc = { .mode = L2CAP_MODE_BASIC };
 
 	BT_DBG("chan %p, rsp %p, len %d, req %p", chan, rsp, len, data);
 
@@ -2271,6 +2271,15 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
 		}

net/bluetooth/l2cap_core.c static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len) · line 2281

Quoted 10 lines
net/bluetooth/l2cap_core.c +8 -0
 	}
 
+	/* Use sane default values in case a misbehaving remote device
+	 * did not send an RFC option.
+	 */
+	BT_ERR("Expected RFC option was not found, using defaults");
+	rfc.mode = chan->mode;
+	rfc.retrans_timeout = cpu_to_le16(L2CAP_DEFAULT_RETRANS_TO);
+	rfc.monitor_timeout = cpu_to_le16(L2CAP_DEFAULT_MONITOR_TO);
+	rfc.max_pdu_size = cpu_to_le16(chan->imtu);

I would actually put the BT_ERR afterwards the assignments separated with an extra empty line, but that is just to make it a bit easier on the eyes.

net/bluetooth/l2cap_core.c static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len) · line 2285

Quoted 4 lines
net/bluetooth/l2cap_core.c +1 -0
+
 done:
 	switch (rfc.mode) {
 	case L2CAP_MODE_ERTM:

Regards

Marcel

#2 lore raw

Hi Mat,

Quoted 29 lines · Marcel Holtmann

Hi Mat,

Quoted 27 lines

When configuring an ERTM or streaming mode connection, remote devices are expected to send an RFC option in a successful config response. A misbehaving remote device might not send an RFC option, and the L2CAP code should not access uninitialized data in this case.

---
 net/bluetooth/l2cap_core.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
net/bluetooth/l2cap_core.c +1 -1
index 5ea94a1..45dd423 100644
@@ -2152,7 +2152,7 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
 	void *ptr = req->data;
 	int type, olen;
 	unsigned long val;
-	struct l2cap_conf_rfc rfc;
+	struct l2cap_conf_rfc rfc = { .mode = L2CAP_MODE_BASIC };
 
 	BT_DBG("chan %p, rsp %p, len %d, req %p", chan, rsp, len, data);
 
@@ -2271,6 +2271,15 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
 		}
 	}
 
Quoted 12 lines

net/bluetooth/l2cap_core.c static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len) · line 2281

Quoted 8 lines
net/bluetooth/l2cap_core.c +8 -0
+	/* Use sane default values in case a misbehaving remote device
+	 * did not send an RFC option.
+	 */
+	BT_ERR("Expected RFC option was not found, using defaults");
+	rfc.mode = chan->mode;
+	rfc.retrans_timeout = cpu_to_le16(L2CAP_DEFAULT_RETRANS_TO);
+	rfc.monitor_timeout = cpu_to_le16(L2CAP_DEFAULT_MONITOR_TO);
+	rfc.max_pdu_size = cpu_to_le16(chan->imtu);

I would actually put the BT_ERR afterwards the assignments separated with an extra empty line, but that is just to make it a bit easier on the eyes.

I applied this one with this change.

Gustavo