From patchwork Tue Dec 6 13:17:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1712712 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=Al1SjdZy; 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 4NRLZk4tSmz23yv for ; Wed, 7 Dec 2022 00:18:21 +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 1p2Xpq-00023z-VZ; Tue, 06 Dec 2022 13:18:10 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1p2Xpp-00023h-1Y for kernel-team@lists.ubuntu.com; Tue, 06 Dec 2022 13:18:09 +0000 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (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-1.canonical.com (Postfix) with ESMTPS id 115F24154B for ; Tue, 6 Dec 2022 13:18:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1670332688; bh=rsU/M9VcD917Dnx7W3VE26Kd0BrXfG4oUwIjgNIPCsI=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Al1SjdZy9sZTzWXOuin1Kj0H/OWv8la1RVZV8Y/AaxIeg3mbRBouA12FyYrnwxWQ0 gXjZ+R1v6Jou3fD+6KiYhZD6pVxxocyBv+9wRMGnvdbvd9Yt0zbz0wikCq99XUcEnT Oj3mNKamRqsjV7gXSA/igN0Qc/YpzUnEYyQWvq/BgNNfx73jnaUAYpyyES0UBQpRnD C20TvL7X5/7yC5GO1dJgDX7vg6Nb6LbBELoPNIvVz5QKbHp0fNOKMaSZB0y8C5rbim z30jUuQQpsTuj0ILNqidOToNb69Sq4qsNKPL/Min620TnlJ5LURvVk99a51a6dzKI3 MRFkj3TPMFd3A== Received: by mail-ed1-f71.google.com with SMTP id z16-20020a05640235d000b0046d0912ae25so1588419edc.5 for ; Tue, 06 Dec 2022 05:18:08 -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=rsU/M9VcD917Dnx7W3VE26Kd0BrXfG4oUwIjgNIPCsI=; b=vtljIZ1L6nWlpes17VK9x5gRq+WSTbVnyqpETGVqy2oBWhhGzeI9c5bO7VKRethdyE 4ZGDXVw7XnYZ4OPq+3j/E4l/RXiBQaHErc8c/aQxhMDu3OT1n6ZcWqZP+rl7doV1xJZo DLscTAPjsx1o+FLbUBxfvi3T8BOH+HKgTSwHihk8lkN4+eCOYLKHKqF/bAwdDtNTeTBZ itPMbGBXXABoMj//0mbe2PvsmyU1wpnPxWW8Cwa40jAmOfIuuMYSQlCh66hZfzgrcF+O IPGan9uIn00y/G1ve9VRMX8jpK6a/mnwVZsDNty/CJZcGJhbO62sCkIJ6hOXrNPpjPMd 3lqA== X-Gm-Message-State: ANoB5pl91hLfDm7V6zFvhWTBlFXhqAJg3WaeEp7RgQeNe3gGOCtY7DDa f+LLe8L24ZvvWX5R1GFwFM2DtMBsHU6d5J0wgNhaV0b5bnc5DjNPUSd60xFcH3EYGv3smsbW+CJ 1Z6a6SAiO+dYHHWL9S7GmqLl2x+HnpKpG1uw8TRn7qQ== X-Received: by 2002:a17:906:b088:b0:7bd:6295:cdd with SMTP id x8-20020a170906b08800b007bd62950cddmr40529179ejy.534.1670332686694; Tue, 06 Dec 2022 05:18:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf6H3JDTK3612gJYV/v7P8mjJkpEF7yJlTK4BeP3aoDQ2D19fn1rJnbVOskXpDYLtXymU7L/OA== X-Received: by 2002:a17:906:b088:b0:7bd:6295:cdd with SMTP id x8-20020a170906b08800b007bd62950cddmr40529158ejy.534.1670332686426; Tue, 06 Dec 2022 05:18:06 -0800 (PST) Received: from localhost ([92.44.145.54]) by smtp.gmail.com with ESMTPSA id d4-20020a170906304400b007c10ad73927sm826670ejd.28.2022.12.06.05.18.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 05:18:06 -0800 (PST) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU Bionic v3 1/2] Bluetooth: L2CAP: Fix accepting connection request for invalid SPSM Date: Tue, 6 Dec 2022 16:17:50 +0300 Message-Id: <20221206131752.153365-2-cengiz.can@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221206131752.153365-1-cengiz.can@canonical.com> References: <20221206131752.153365-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 CVE-2022-42896 (backported from commit 711f8c3fb3db61897080468586b970c87c61d9e4) [cengizcan: 4.15 does not have commit 15f02b910562 ("Bluetooth: L2CAP: Add initial code for Enhanced Credit Based Mode") so skip patching `l2cap_ecred_conn_req` and only patch `l2cap_le_connect_req` instead.] [cengizcan: 4.15 does not have L2CAP_CR_LE_BAD_PSM defined so use L2CAP_CR_BAD_PSM as return value instead since they both indicate same type of error and are equal.] Signed-off-by: Cengiz Can --- net/bluetooth/l2cap_core.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 35c04727ddc0..066a16785b92 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -5552,6 +5552,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_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); From patchwork Tue Dec 6 13:17:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1712709 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=Yvb1CeG2; 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 4NRLZk4qnTz23yt for ; Wed, 7 Dec 2022 00:18:21 +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 1p2Xps-00024l-4q; Tue, 06 Dec 2022 13:18:12 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1p2Xpq-00023s-QH for kernel-team@lists.ubuntu.com; Tue, 06 Dec 2022 13:18:10 +0000 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (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-1.canonical.com (Postfix) with ESMTPS id 9309A4154B for ; Tue, 6 Dec 2022 13:18:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1670332690; bh=jrVq7v1vsVwxkgdA12G+5Gwd2H/ojhE+HQg21OEIme8=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Yvb1CeG2wUp31Koia5o05yRSE2YklQCAb7AQiyni6ZCG8Oq3D8S8gdxcB+Vrwmfqa skrz88x6OFAGyN/DgL9dfVaggI5idIhaDz3jPSXT+lzNGSyUTHoAv0Xt7qvD52WFLV ohAIoG2RTUT6J12nuDbO6sX4TzXWPAq0vItZNiP4WXwatdjYFn8GBgCW73iFwaR20U fkckh0pU2yqtyfAaGcerwoSXlM265RAMX+fAs4C1edfNf8x1CqRH4M7veyb35MNJqA M/Q/8qjspGMoUIBUrUrB8kJt7A4luLo5tgLBFRuUgtdNigChkIpNEHuM4zdBL0Vokg hLLEo75BDw+dA== Received: by mail-ej1-f70.google.com with SMTP id ds15-20020a170907724f00b007c0abebc958so1518319ejc.2 for ; Tue, 06 Dec 2022 05:18:10 -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=jrVq7v1vsVwxkgdA12G+5Gwd2H/ojhE+HQg21OEIme8=; b=WrnYjXbNHk6q/Pwu0nsY2NRkvtPAuzOnYSbxtW8vrUFyutXeWgrmcPXhQlHLiqUuWd YCUfNQGiiq3ygKBbM0A9odLd9mGLVQKeZh1rogAlttpGjjimGbEFKxGn7/S+89qyxW1s aaKOltU6vMzJ1B+8AlqYGD4ESyHJT7R37VBuos9rkekP1RknpRmSFJ6r0r6wfXOD2+Pf rQvZaI8VB74fxEsiVbVI5jYGMQsfURRH0uSBOQXY2Y3ClOD+yhD7AVPLOGGDTHK068NK tE9yk//xcF7dAkBToVoHrOHFA1cCdqdKpF3dT/S4bHotfZgsfmEkxjuyfRROjNsGJ3bm wm0g== X-Gm-Message-State: ANoB5pmI2F5F3Fx9KJbH0GY30Djgy2797LlvaXRW3L/E0aTa3RlfwVmt QVWPNW1vFtOIKG9odEgvTY/vCaPzQCb7giAJhlwk+gRhxEQ//2Y4Nrj9r9sHb5oaC/2GascwIk3 WN7zHYqPWBY8OhbIrLirdRv7MvQl9gInYwibfUqVyhw== X-Received: by 2002:a17:906:2a97:b0:7c0:ab1e:e361 with SMTP id l23-20020a1709062a9700b007c0ab1ee361mr20078277eje.579.1670332689556; Tue, 06 Dec 2022 05:18:09 -0800 (PST) X-Google-Smtp-Source: AA0mqf7DmAK2rQPukMyYB33r8m+V+k76KJ/ydo25orjO4XjD4B6O76nMq55ZQcOmKj42fVOXBT3qkQ== X-Received: by 2002:a17:906:2a97:b0:7c0:ab1e:e361 with SMTP id l23-20020a1709062a9700b007c0ab1ee361mr20078262eje.579.1670332689337; Tue, 06 Dec 2022 05:18:09 -0800 (PST) Received: from localhost ([92.44.145.54]) by smtp.gmail.com with ESMTPSA id n19-20020a17090695d300b007c0cbdfba04sm4784984ejy.70.2022.12.06.05.18.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 05:18:09 -0800 (PST) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU Bionic v3 2/2] Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm Date: Tue, 6 Dec 2022 16:17:51 +0300 Message-Id: <20221206131752.153365-3-cengiz.can@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221206131752.153365-1-cengiz.can@canonical.com> References: <20221206131752.153365-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 l2cap_global_chan_by_psm shall not return fixed channels as they are not meant to be connected by (S)PSM. Signed-off-by: Luiz Augusto von Dentz Reviewed-by: Tedd Ho-Jeong An CVE-2022-42896 (cherry picked from commit f937b758a188d6fd328a81367087eddbb2fce50f) Signed-off-by: Cengiz Can --- net/bluetooth/l2cap_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 066a16785b92..bf972012d215 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -1824,7 +1824,7 @@ static struct l2cap_chan *l2cap_global_chan_by_psm(int state, __le16 psm, if (link_type == LE_LINK && c->src_type == BDADDR_BREDR) continue; - if (c->psm == psm) { + if (c->chan_type != L2CAP_CHAN_FIXED && c->psm == psm) { int src_match, dst_match; int src_any, dst_any;