summaryrefslogtreecommitdiffstats
path: root/CVE-2019-3459-and-CVE-2019-3460.patch
blob: c7fa62736b196368a2857dcd6e4b2aa4d3f21f40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
From 20614b74e481f0c9f94032ae99f110d4647b65a6 Mon Sep 17 00:00:00 2001
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Thu, 10 Jan 2019 07:28:33 +0100
Subject: [PATCH 1/2] Bluetooth: check message types in l2cap_get_conf_opt

l2cap_get_conf_opt can handle a "default" message type, but it needs to
be verified that it really is the correct type (CONF_EFS or CONF_RFC)
before passing it back to the caller.  To do this we need to check the
return value of this call now and handle the error correctly up the
stack.

Based on a patch from Ran Menscher.

Reported-by: Ran Menscher <ran.menscher@karambasecurity.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jeremy Cline <jcline@redhat.com>
---
 net/bluetooth/l2cap_core.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index d17a4736e47c..a0ce6e8e5ef7 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -2979,6 +2979,10 @@ static inline int l2cap_get_conf_opt(void **ptr, int *type, int *olen,
 		break;
 
 	default:
+		/* Only CONF_EFS and CONF_RFC are allowed here */
+		if ((opt->type != L2CAP_CONF_EFS) &&
+		    (opt->type != L2CAP_CONF_RFC))
+			return -EPROTO;
 		*val = (unsigned long) opt->val;
 		break;
 	}
@@ -3323,7 +3327,7 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data, size_t data
 	void *endptr = data + data_size;
 	void *req = chan->conf_req;
 	int len = chan->conf_len;
-	int type, hint, olen;
+	int type, hint, olen, err;
 	unsigned long val;
 	struct l2cap_conf_rfc rfc = { .mode = L2CAP_MODE_BASIC };
 	struct l2cap_conf_efs efs;
@@ -3335,7 +3339,10 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data, size_t data
 	BT_DBG("chan %p", chan);
 
 	while (len >= L2CAP_CONF_OPT_SIZE) {
-		len -= l2cap_get_conf_opt(&req, &type, &olen, &val);
+		err = l2cap_get_conf_opt(&req, &type, &olen, &val);
+		if (err < 0)
+			return err;
+		len -= err;
 
 		hint  = type & L2CAP_CONF_HINT;
 		type &= L2CAP_CONF_MASK;
@@ -3538,7 +3545,7 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
 	struct l2cap_conf_req *req = data;
 	void *ptr = req->data;
 	void *endptr = data + size;
-	int type, olen;
+	int type, olen, err;
 	unsigned long val;
 	struct l2cap_conf_rfc rfc = { .mode = L2CAP_MODE_BASIC };
 	struct l2cap_conf_efs efs;
@@ -3546,7 +3553,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
 	BT_DBG("chan %p, rsp %p, len %d, req %p", chan, rsp, len, data);
 
 	while (len >= L2CAP_CONF_OPT_SIZE) {
-		len -= l2cap_get_conf_opt(&rsp, &type, &olen, &val);
+		err = l2cap_get_conf_opt(&rsp, &type, &olen, &val);
+		if (err < 0)
+			return err;
+		len -= err;
 
 		switch (type) {
 		case L2CAP_CONF_MTU:
@@ -3706,7 +3716,7 @@ void __l2cap_connect_rsp_defer(struct l2cap_chan *chan)
 
 static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
 {
-	int type, olen;
+	int type, olen, err;
 	unsigned long val;
 	/* Use sane default values in case a misbehaving remote device
 	 * did not send an RFC or extended window size option.
@@ -3726,7 +3736,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
 		return;
 
 	while (len >= L2CAP_CONF_OPT_SIZE) {
-		len -= l2cap_get_conf_opt(&rsp, &type, &olen, &val);
+		err = l2cap_get_conf_opt(&rsp, &type, &olen, &val);
+		if (err < 0)
+			return;
+		len -= err;
 
 		switch (type) {
 		case L2CAP_CONF_RFC:
-- 
2.20.1

From 50cd5314f5ffa264906f4986f414750d648c4ece Mon Sep 17 00:00:00 2001
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Thu, 10 Jan 2019 07:29:17 +0100
Subject: [PATCH 2/2] Bluetooth: check the buffer size for some messages before
 parsing

The L2CAP_CONF_EFS and L2CAP_CONF_RFC messages can be sent from
userspace so their structure sizes need to be checked before parsing
them.

Based on a patch from Ran Menscher.

Reported-by: Ran Menscher <ran.menscher@karambasecurity.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jeremy Cline <jcline@redhat.com>
---
 net/bluetooth/l2cap_core.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index a0ce6e8e5ef7..d8d3cbdc0d29 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -3360,7 +3360,8 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data, size_t data
 			break;
 
 		case L2CAP_CONF_RFC:
-			if (olen == sizeof(rfc))
+			if ((olen == sizeof(rfc)) &&
+			    (endptr - ptr >= L2CAP_CONF_OPT_SIZE + sizeof(rfc)))
 				memcpy(&rfc, (void *) val, olen);
 			break;
 
@@ -3370,7 +3371,8 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data, size_t data
 			break;
 
 		case L2CAP_CONF_EFS:
-			if (olen == sizeof(efs)) {
+			if ((olen == sizeof(efs)) &&
+			    (endptr - ptr >= L2CAP_CONF_OPT_SIZE + sizeof(efs))) {
 				remote_efs = 1;
 				memcpy(&efs, (void *) val, olen);
 			}
@@ -3575,7 +3577,8 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
 			break;
 
 		case L2CAP_CONF_RFC:
-			if (olen == sizeof(rfc))
+			if ((olen == sizeof(rfc)) &&
+			    (endptr - ptr >= L2CAP_CONF_OPT_SIZE + sizeof(rfc)))
 				memcpy(&rfc, (void *)val, olen);
 
 			if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
@@ -3595,7 +3598,8 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
 			break;
 
 		case L2CAP_CONF_EFS:
-			if (olen == sizeof(efs)) {
+			if ((olen == sizeof(efs)) &&
+			    (endptr - ptr >= L2CAP_CONF_OPT_SIZE + sizeof(efs))) {
 				memcpy(&efs, (void *)val, olen);
 
 				if (chan->local_stype != L2CAP_SERV_NOTRAFIC &&
-- 
2.20.1