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);