From patchwork Fri Dec 2 18:10:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1711667 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=lAAxt5jO; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NPLn72sfxz23yg for ; Sat, 3 Dec 2022 18:20:25 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1p1Mog-0004Mf-67; Sat, 03 Dec 2022 07:20:06 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1p1AVV-00046B-UC for kernel-team@lists.ubuntu.com; Fri, 02 Dec 2022 18:11:29 +0000 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id C598442218 for ; Fri, 2 Dec 2022 18:11:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1670004689; bh=qxprw8ULrRqSlV9uBJ3DHwtpJOCwDzRKLXbqiGyCpbY=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=lAAxt5jOf/0ZIMpyV5HGwbYq+oyaHjtmj2EXHygQlZ6tOMSGP18nFI6NIG7LUb31R XBSL8O0eJzorVjN2YgFawzdXOHeWuFiXhqc1YTvPEl/elIQeq02/Axq5mxW9KCqB3E qxrGEw5sJ/EBO+lA+2oUR8ccjk7I6nwPyFiHOqDRJRP4KnXY+ekkyFidSyUtWoG+Rn jB39YMMEOcf6IxGR92OUmJ2X4G6iYb0zzdx2Ln/TFMgGkr+Hz1qKAzu0ioIOve3NKK BHp1DkHgJtPd+JNRRXK/eN/zwtfbVuft5w/+GOviScIR4K+ajcvzxXTjpvYj4FvQA7 3TM4SvyUGo3KQ== Received: by mail-wm1-f69.google.com with SMTP id v125-20020a1cac83000000b003cfa148576dso2856430wme.3 for ; Fri, 02 Dec 2022 10:11:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qxprw8ULrRqSlV9uBJ3DHwtpJOCwDzRKLXbqiGyCpbY=; b=cJlDNkgNAabYSdnABOeqqzZees5mbFocW68roNc2lhNWQQMoUxWHfF9pXQjsjEdpj1 C2g9ippOzSGXAuPJJy3Ql4AhnFbDVsM6JCzZsaNzPeQqAo5P4fxQ76ceeNFGsqAaeSaH PUzguwjl8rdo2U1+japO9s9iHMJWZslnQnTbubS43CIa1swVCSNbYj6oBg5L85/0VDo3 zEHtvz8m5q/glvnN8nhWws9u/LvjU9NGVheH7IHSQL5duGEI1zXkaIQlQxaZGX3/5KM1 HzjyQpYAb64/Rfpt3gSnhNpwokZXj/JNj/jDRpOc7diY8j2DPw2Xm3aAwBxjtRCndJN2 PWuA== X-Gm-Message-State: ANoB5pleNQ0m5pyER/1EynvT9dmuO3cXKtpRx5V1z0IaJuA4v07LZGOR ilGBpDxomOdG7sJXIPFtBVQKtRxE5+f9TFndGcHEU3mfTEpZr+HN/xOpf2c+ItwcVrnkEiO4/5/ roiZoaPz2h5acBrNHZu0+QoTZGNUgLovAyM5ZkyVZ5g== X-Received: by 2002:a5d:44c4:0:b0:242:3140:54c6 with SMTP id z4-20020a5d44c4000000b00242314054c6mr7842474wrr.252.1670004689280; Fri, 02 Dec 2022 10:11:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf5xRtO0ENMMrop9m5NZsvE16S18Bfkppi49wwBZtFhrPImgXwzpEfLLjdGAYBrHSs1AK8o+gA== X-Received: by 2002:a5d:44c4:0:b0:242:3140:54c6 with SMTP id z4-20020a5d44c4000000b00242314054c6mr7842461wrr.252.1670004689031; Fri, 02 Dec 2022 10:11:29 -0800 (PST) Received: from localhost ([92.44.145.54]) by smtp.gmail.com with ESMTPSA id w12-20020a05600c474c00b003b435c41103sm16844845wmo.0.2022.12.02.10.11.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 10:11:28 -0800 (PST) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU OEM-5.14/Jammy/HWE-5.17 1/2] Bluetooth: L2CAP: Fix accepting connection request for invalid SPSM Date: Fri, 2 Dec 2022 21:10:20 +0300 Message-Id: <20221202181017.405052-4-cengiz.can@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221202181017.405052-1-cengiz.can@canonical.com> References: <20221202181017.405052-1-cengiz.can@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Luiz Augusto von Dentz The Bluetooth spec states that the valid range for SPSM is from 0x0001-0x00ff so it is invalid to accept values outside of this range: BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 3, Part A page 1059: Table 4.15: L2CAP_LE_CREDIT_BASED_CONNECTION_REQ SPSM ranges CVE: CVE-2022-42896 CC: stable@vger.kernel.org Reported-by: Tamás Koczka Signed-off-by: Luiz Augusto von Dentz Reviewed-by: Tedd Ho-Jeong An (cherry picked from commit 711f8c3fb3db61897080468586b970c87c61d9e4) Signed-off-by: Cengiz Can --- net/bluetooth/l2cap_core.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index df41c1650528..8bfd2162163e 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -5772,6 +5772,19 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn, BT_DBG("psm 0x%2.2x scid 0x%4.4x mtu %u mps %u", __le16_to_cpu(psm), scid, mtu, mps); + /* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 3, Part A + * page 1059: + * + * Valid range: 0x0001-0x00ff + * + * Table 4.15: L2CAP_LE_CREDIT_BASED_CONNECTION_REQ SPSM ranges + */ + if (!psm || __le16_to_cpu(psm) > L2CAP_PSM_LE_DYN_END) { + result = L2CAP_CR_LE_BAD_PSM; + chan = NULL; + goto response; + } + /* Check if we have socket listening on psm */ pchan = l2cap_global_chan_by_psm(BT_LISTEN, psm, &conn->hcon->src, &conn->hcon->dst, LE_LINK); @@ -5959,6 +5972,18 @@ static inline int l2cap_ecred_conn_req(struct l2cap_conn *conn, psm = req->psm; + /* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 3, Part A + * page 1059: + * + * Valid range: 0x0001-0x00ff + * + * Table 4.15: L2CAP_LE_CREDIT_BASED_CONNECTION_REQ SPSM ranges + */ + if (!psm || __le16_to_cpu(psm) > L2CAP_PSM_LE_DYN_END) { + result = L2CAP_CR_LE_BAD_PSM; + goto response; + } + BT_DBG("psm 0x%2.2x mtu %u mps %u", __le16_to_cpu(psm), mtu, mps); memset(&pdu, 0, sizeof(pdu));