From: Dan Rosenberg <drosenberg@vsecurity.com>
Date: Fri, 24 Jun 2011 12:38:05 +0000 (-0400)
Subject: Bluetooth: Prevent buffer overflow in l2cap config request
X-Git-Tag: firefly_0821_release~7613^2~421
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1752e5327a01247d605515dbba86ad32a493db93;p=firefly-linux-kernel-4.4.55.git

Bluetooth: Prevent buffer overflow in l2cap config request

A remote user can provide a small value for the command size field in
the command header of an l2cap configuration request, resulting in an
integer underflow when subtracting the size of the configuration request
header.  This results in copying a very large amount of data via
memcpy() and destroying the kernel heap.  Check for underflow.

Signed-off-by: Dan Rosenberg <drosenberg@vsecurity.com>
Cc: stable <stable@kernel.org>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
---

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 9c7bccfcc720..38efc9f32c40 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -2535,7 +2535,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr
 
 	/* Reject if config buffer is too small. */
 	len = cmd_len - sizeof(*req);
-	if (chan->conf_len + len > sizeof(chan->conf_req)) {
+	if (len < 0 || chan->conf_len + len > sizeof(chan->conf_req)) {
 		l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP,
 				l2cap_build_conf_rsp(chan, rsp,
 					L2CAP_CONF_REJECT, flags), rsp);