Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp527814yba; Mon, 1 Apr 2019 11:06:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqzH1haKPCEDKjEhKqftGjpsU4JfNEf3WMV2nTi0YeaOmN1NQlNf+DvML/ScsaJCKP0DOFx3 X-Received: by 2002:a62:a219:: with SMTP id m25mr63999241pff.197.1554142005215; Mon, 01 Apr 2019 11:06:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554142005; cv=none; d=google.com; s=arc-20160816; b=c6NysiITiVpk1wktdwUkH5XVrplT5+94ZA+OodOnlkRswn2D0KHzi2fy8Wl0FIHmx1 HUthL7aM3u8NaZ62zG+l7HibY9hRB0ZcKSuKJj5KKpSJDL3B4AC2aJg5GNy85DVvQ43c t6pd6ZuYG7851LFGvyJ+0zHT0dw8dp/mStUlA4V2mSTVCwLHtGLdY21rnqofio/oFD2n ierBd2c5uECU4hYl0gDke7UNQl3AgLoY+WI1iuvFKSdRiSdJUNbW3g87kt7sIrPZfJhC lvhHxaRa7UvYCxtLRE+AAqgs8LdoFi6x3ax4VhRmDtjBd2KH740V1ANWqluu3K4B6hOp 6eow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KG39gQhX4Mlw51XxHo621xVffik/luT+XXZyikPCBHI=; b=KQ5IInlmTmktscebcTtWHcgxdPp85G8D8CwDZk7mbXk6evIiUaZTc6rNu2qutiwKom /vRmCgNrKitb9Uz0A04a3otd820UaGsos5mgCfqYzsh9PclI+j9AzgDwn26LKT4bafBF 80QIkRb+fEl/MToq7qsBAmIZkd9AtOJkZT0kbYfZUeYcGq9t19aYuyHhRSUAue3ctxwe iXK3OPBjcD9URGse2Pj9a/RciK13F0hoOQgfD2CWps8mAzIdLFkWr0jmw7fetdPM/NnQ u0XVl3Yhk630r42HE6OHHPIKuwfRuGnSWot2BWG4o+fjKR2dEJUtkYSFKELuyejI8ZvM Knzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lZEvwl93; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h8si9910125plb.282.2019.04.01.11.06.29; Mon, 01 Apr 2019 11:06:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lZEvwl93; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730695AbfDASF6 (ORCPT + 99 others); Mon, 1 Apr 2019 14:05:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:35216 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728907AbfDARNE (ORCPT ); Mon, 1 Apr 2019 13:13:04 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A7A9020883; Mon, 1 Apr 2019 17:13:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554138783; bh=spU2CR+J9WzZcMMkNIFcFuiNzBVUrzvOxEq+9UVGKPc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lZEvwl93GVu1Ar9e6sEsJRcs+grwSN6jkSS4n36opPgjZzwvvRqwE0WtOW0P1OL9X 5MaOwbVD6hYENVa8KKgAglO/g9sJGa1r+sc2aKHlMIph7+zjSohjvICwnto6d/cioX fhAYsnrFzThhP+naGrtajCQMRP2qpeyBwTszZI6M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marcel Holtmann , Johan Hedberg Subject: [PATCH 4.19 002/134] Bluetooth: Verify that l2cap_get_conf_opt provides large enough buffer Date: Mon, 1 Apr 2019 19:00:38 +0200 Message-Id: <20190401170044.456489926@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401170044.243719205@linuxfoundation.org> References: <20190401170044.243719205@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Marcel Holtmann commit 7c9cbd0b5e38a1672fcd137894ace3b042dfbf69 upstream. The function l2cap_get_conf_opt will return L2CAP_CONF_OPT_SIZE + opt->len as length value. The opt->len however is in control over the remote user and can be used by an attacker to gain access beyond the bounds of the actual packet. To prevent any potential leak of heap memory, it is enough to check that the resulting len calculation after calling l2cap_get_conf_opt is not below zero. A well formed packet will always return >= 0 here and will end with the length value being zero after the last option has been parsed. In case of malformed packets messing with the opt->len field the length value will become negative. If that is the case, then just abort and ignore the option. In case an attacker uses a too short opt->len value, then garbage will be parsed, but that is protected by the unknown option handling and also the option parameter size checks. Signed-off-by: Marcel Holtmann Reviewed-by: Greg Kroah-Hartman Signed-off-by: Johan Hedberg Signed-off-by: Greg Kroah-Hartman --- net/bluetooth/l2cap_core.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -3336,6 +3336,8 @@ static int l2cap_parse_conf_req(struct l while (len >= L2CAP_CONF_OPT_SIZE) { len -= l2cap_get_conf_opt(&req, &type, &olen, &val); + if (len < 0) + break; hint = type & L2CAP_CONF_HINT; type &= L2CAP_CONF_MASK; @@ -3554,6 +3556,8 @@ static int l2cap_parse_conf_rsp(struct l while (len >= L2CAP_CONF_OPT_SIZE) { len -= l2cap_get_conf_opt(&rsp, &type, &olen, &val); + if (len < 0) + break; switch (type) { case L2CAP_CONF_MTU: @@ -3739,6 +3743,8 @@ static void l2cap_conf_rfc_get(struct l2 while (len >= L2CAP_CONF_OPT_SIZE) { len -= l2cap_get_conf_opt(&rsp, &type, &olen, &val); + if (len < 0) + break; switch (type) { case L2CAP_CONF_RFC: