From patchwork Thu Jan 26 20:37:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1732556 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=HUg0MXZZ; 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 4P2swC2Xk7z23hm for ; Fri, 27 Jan 2023 07:37:45 +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 1pL903-0006oB-UU; Thu, 26 Jan 2023 20:37:35 +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 1pL902-0006no-3W for kernel-team@lists.ubuntu.com; Thu, 26 Jan 2023 20:37:34 +0000 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.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-1.canonical.com (Postfix) with ESMTPS id B87183F1E9 for ; Thu, 26 Jan 2023 20:37:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1674765453; bh=zEOTMidjDRU7Zpvnp7i6aP8I2vgI15U9V3NMG2sqy5A=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HUg0MXZZVpNDxRstXRtuqdIFg4BGbhjJ9SpBjrGI2nrXnkeGEclUXxUaljFTiOYuq wV3ENd9x9KGQBwQlSIlczGjXI53NCyyImUXxQ9NsQ+z7S9tbKrvJ4tpbs7oc+BdePL Ih45tDSSg4fIo/EEm0qrCddto6auMxjpvVmaWJ4q//a92Uorusp8ROFKsFMiu6HiKi 2rqO1V4A+Q7mmokqWOqfvkjRy7Cn0MAtitT16CbWS60raetFOSPL4g6mtunB3JnJsV +nJVIYhAiZhvVpyJDPGj1A26ebM1LCwmVspC8PSclDLujo67c6gC5z+boKJunPkTaV nCmPZ3FofJ6+Q== Received: by mail-ej1-f69.google.com with SMTP id qf20-20020a1709077f1400b0086ec9755517so1949166ejc.15 for ; Thu, 26 Jan 2023 12:37:33 -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=zEOTMidjDRU7Zpvnp7i6aP8I2vgI15U9V3NMG2sqy5A=; b=CH6ehvAPQ+li3Vn7D5Mhw18SkFRtfydx6vasUyhtSoeTMiNx5ccp7rl9XkyiTCJpco 5aCOC5zfXUdu8TKPdPSPM4lmbnRGjWbag0BeLzPmjQiTZmdE8GveAxIHXHvOXWfQ9QvW gdIq5pKEaQzJRakRLSW49Bt7fqtTgsAzgQ58njVwMpWbXKPLlEvAPNEk9hfpAOfGFkwG Z+Q7GivmxZgYJdf+DEM62ZI3E6a31GiZv2x7OFhT4o2xNXwWiGEry8tBvI56Nw7xEV5U s7gqCdKy8D2LGeDn7ueAv4w7SrnjQWNF6oluOf7HGWo79tNyyx0QWsd9LMh0+BEk4Ru7 U7gg== X-Gm-Message-State: AFqh2krwHdaoIR758FpAKl3ZeSIvRRet/ABxavQ8TcEBuA8jgW+fowI4 L6oBI7i9nQxpfWEc4B9be1YbdRoMqSVoLX5ofpUmuq6pKVaB6pYkux0yvjGXk2CAKUGVm/3/8M7 AXW7TnSg5hZKETLpWD7EEVqCjc8k2oTDXvpLXIM1sVg== X-Received: by 2002:a05:6402:43cf:b0:472:f7c1:361 with SMTP id p15-20020a05640243cf00b00472f7c10361mr42465640edc.29.1674765452722; Thu, 26 Jan 2023 12:37:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXvJlt0A4qeGK6cqpNvHyZCY2Qvf6FwtF6LOC2utVrRXz2gQDi1GjQqPEqQaGx3evnovzWlS/w== X-Received: by 2002:a05:6402:43cf:b0:472:f7c1:361 with SMTP id p15-20020a05640243cf00b00472f7c10361mr42465628edc.29.1674765452386; Thu, 26 Jan 2023 12:37:32 -0800 (PST) Received: from localhost ([176.234.222.100]) by smtp.gmail.com with ESMTPSA id f9-20020a056402354900b0049e9e9204basm1243553edd.21.2023.01.26.12.37.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 12:37:32 -0800 (PST) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU OEM-6.0 1/1] Bluetooth: L2CAP: Fix u8 overflow Date: Thu, 26 Jan 2023 23:37:22 +0300 Message-Id: <20230126203722.454754-2-cengiz.can@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230126203722.454754-1-cengiz.can@canonical.com> References: <20230126203722.454754-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: Sungwoo Kim By keep sending L2CAP_CONF_REQ packets, chan->num_conf_rsp increases multiple times and eventually it will wrap around the maximum number (i.e., 255). This patch prevents this by adding a boundary check with L2CAP_MAX_CONF_RSP Btmon log: Bluetooth monitor ver 5.64 = Note: Linux version 6.1.0-rc2 (x86_64) 0.264594 = Note: Bluetooth subsystem version 2.22 0.264636 @ MGMT Open: btmon (privileged) version 1.22 {0x0001} 0.272191 = New Index: 00:00:00:00:00:00 (Primary,Virtual,hci0) [hci0] 13.877604 @ RAW Open: 9496 (privileged) version 2.22 {0x0002} 13.890741 = Open Index: 00:00:00:00:00:00 [hci0] 13.900426 (...) > ACL Data RX: Handle 200 flags 0x00 dlen 1033 #32 [hci0] 14.273106 invalid packet size (12 != 1033) 08 00 01 00 02 01 04 00 01 10 ff ff ............ > ACL Data RX: Handle 200 flags 0x00 dlen 1547 #33 [hci0] 14.273561 invalid packet size (14 != 1547) 0a 00 01 00 04 01 06 00 40 00 00 00 00 00 ........@..... > ACL Data RX: Handle 200 flags 0x00 dlen 2061 #34 [hci0] 14.274390 invalid packet size (16 != 2061) 0c 00 01 00 04 01 08 00 40 00 00 00 00 00 00 04 ........@....... > ACL Data RX: Handle 200 flags 0x00 dlen 2061 #35 [hci0] 14.274932 invalid packet size (16 != 2061) 0c 00 01 00 04 01 08 00 40 00 00 00 07 00 03 00 ........@....... = bluetoothd: Bluetooth daemon 5.43 14.401828 > ACL Data RX: Handle 200 flags 0x00 dlen 1033 #36 [hci0] 14.275753 invalid packet size (12 != 1033) 08 00 01 00 04 01 04 00 40 00 00 00 ........@... Signed-off-by: Sungwoo Kim Signed-off-by: Luiz Augusto von Dentz CVE-2022-45934 (cherry picked from commit bcd70260ef56e0aee8a4fc6cd214a419900b0765) Signed-off-by: Cengiz Can Acked-by: Thadeu Lima de Souza Cascardo --- net/bluetooth/l2cap_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 4df3d0ed6c80..6402edcacdcb 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4453,7 +4453,8 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, chan->ident = cmd->ident; l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP, len, rsp); - chan->num_conf_rsp++; + if (chan->num_conf_rsp < L2CAP_CONF_MAX_CONF_RSP) + chan->num_conf_rsp++; /* Reset config buffer. */ chan->conf_len = 0;