Message ID | 20240209070443.3617790-1-iam@sung-woo.kim |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-59056-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp675637dyd; Thu, 8 Feb 2024 23:06:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IHPztGtBPnzZ8XS5RYOAV4UGOiKnAsKZ3N02qnDFwaSGIDFgcIVHt1RHGQ1dP9fBExpLILf X-Received: by 2002:a37:e201:0:b0:785:9f04:87a5 with SMTP id g1-20020a37e201000000b007859f0487a5mr749541qki.38.1707462402003; Thu, 08 Feb 2024 23:06:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707462401; cv=pass; d=google.com; s=arc-20160816; b=MmfTgOkHuDSYzi6XXRPOLa7ak2prYUBmjMfMjN6/alXcCdUvDjIrio8J4KMtBVhdUg 5MLVuEjb8mE8NdtxfW0xLCYfzuvcPdKkD/8DgNXWmg2VumO0YxHFUvawqBmVpknBNNhy 0LQMZ+XDBp+rpsCaq1XLjpZKqTtoOHai82kAkA4D+OMBJV5pwduyA+T5qTVIMKXwwL8T MSY8BQLvTIjxvXj6rYY8q8O64uyZPL4kSMM3MgVilNP6LuFE2R3IsOtokYaJ7BG2AZ61 gOHHLVi3yjs1A7lzWbmGi9NCX78A4Novxoih/b2w4PYfgJwEZopAaa6EWzk1YEcbklCe IY3w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=oADkvQHAij8FCM4vmi8qRxP7ztqbgDTFL1If0dxUooo=; fh=N3Y+umr34p0fcnadvv6PMNEtm/L82JuEFaWY6Grcx0Q=; b=R90DLzQTVhASamnWZO9A/ZwnJVGP853bDoh8gO8GkmlECeMK2alUFSyS6AmglKp8Yr 3siSAVV/kO+X0otFcG957bJcLmysR9Q+f+u5spSMGkUWg8B/ko243tN1ylN8zwVEnqwz T5lOXYtJcaQGgdRGdff1m/B8GNzo/bcFQoiPs5CZfA8UXN4Nm0ryQDLNH85iXKWSJtBi as6Muh3sFYuOQinw6sOz2wutgLpCKcGTC+/0VMsZI45UVJ0AGWG69aWlG6WLzvnMl2Md +eCNlfrwvz70BhcmHeZ5wE2JS1YfvrLzYmJb8s6YWPY7zMo8dJS+d95E+80HnEiwxhcc UEDQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-59056-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59056-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sung-woo.kim X-Forwarded-Encrypted: i=2; AJvYcCWNxr8n4EpjscPclk72f2q6SJI0MgfXb0/W6ptaQ5UvemZOO8BNsz6XybbKmqW49KiiSxXUhRI2KRfcwkU5DAyLZ9EirA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f19-20020a05620a12f300b007859e6a0c9bsi1393227qkl.138.2024.02.08.23.06.41 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 23:06:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59056-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-59056-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59056-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sung-woo.kim Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6F08F1C23D8E for <ouuuleilei@gmail.com>; Fri, 9 Feb 2024 07:06:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 810B4657D4; Fri, 9 Feb 2024 07:06:21 +0000 (UTC) Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18F9B57308; Fri, 9 Feb 2024 07:06:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707462379; cv=none; b=tNz9IHojFL+9dCyqJadKR5cnTwn/QUl9jH76NjqCJtm5d+Qqi04uBi3KKFJaEjqWrwUhFMoyJQtCN40sc99ulVPnpdsqBq4nf1829ejRrmgrmP2HDdHfFIp1UrWRNRbCRRhJB0deLLrASta0pJb4z9fA3+I3dKtoHQesSWg5RBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707462379; c=relaxed/simple; bh=xdfzDXGsrnjsjgrVDLKFZyComOe6tbA2kOubScLODRQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=p57Am/8XDE1jOhCJ86DyXDOlAqyNCZIESmnP5H2uFSfAwuT719qx9qWCJgVwFo8qPlOMfYDmu9xBqN9G8VwOpwyUMVGQFBGz2K7R1mNEH6/fLveOiuj9mmvzha28ig6TivPFdm4Q5I+x/TNweC0matMj4PiXRqjj1nrYwVmP+Us= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=sung-woo.kim; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.222.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=sung-woo.kim Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-783d84ecb13so43172285a.0; Thu, 08 Feb 2024 23:06:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707462377; x=1708067177; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=oADkvQHAij8FCM4vmi8qRxP7ztqbgDTFL1If0dxUooo=; b=aW71Bhd7+sF5QHi0HDrYHhkNIDlkGjeL68IFPsKNlmQ4yjMUvJxp86FD4bPOgA4xC2 gz34x2z+/JeorlSAHad6yK2vzdNwo5d/on47T+uNxiphnz3gk1SaJ6VHJv8Xuv9kpx+I 9SUZF6hgs0wavRCNLj7YmFPUwxGacCXUccKYI1+FPvt7DXXsQoeYCzgIZc7spH+u+pC9 hzfP3Wk400UahqFULXz+Yy0qT4XJb/mdRTtFmq5u6QlrAk8GcL5Y7qsMIQc2f/Eu0VFm wcXZOIw48Vu2nwCTUU7uJehlgSlWDix7p5MmlIGTZpGoku5HUTmivmgSQ0KXaBtjsahd FAiw== X-Gm-Message-State: AOJu0YwzCxDuaOJfSOg/0okjSX/feznjkBrnPaiYj/IJbJl0Dj+SaAI5 yrTV7UnWP/7LO6+WFtxxfutGu5AS0ClZpKTD0zeLWu/8s4d4msiP X-Received: by 2002:a0c:aada:0:b0:68c:bdc0:1bd2 with SMTP id g26-20020a0caada000000b0068cbdc01bd2mr607755qvb.9.1707462376842; Thu, 08 Feb 2024 23:06:16 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXm1EzV9GLndmBzBAWO2JUZL47ACppeNoLaIsJhQa44I7jkyxsWe5w071H3ZMCMUA7fO7bqo39hJ5o/Zyw1ijs+kUbiRwa1CdX7SQoLEmv9AnV4uo9qUnxR1lMLFFeolbxMFGhhQVmv1vSEkCJX5cg3NqMwDNumeL/2pHAcA2sbesAs35XkB/A9ddRBkt6h/XP7bVpKcmTJ9O5ytSHAJg+hhqKeF0Z3qesEdNbtsCjO4RO7jJD65sa8ZqWiy/d3ONMAQHY= Received: from noodle.cs.purdue.edu (switch-lwsn2133-z1r11.cs.purdue.edu. [128.10.127.250]) by smtp.googlemail.com with ESMTPSA id b25-20020a0c9b19000000b00681785c95e0sm576315qve.46.2024.02.08.23.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 23:06:16 -0800 (PST) From: Sungwoo Kim <iam@sung-woo.kim> To: Cc: daveti@purdue.edu, Sungwoo Kim <iam@sung-woo.kim>, Marcel Holtmann <marcel@holtmann.org>, Johan Hedberg <johan.hedberg@gmail.com>, Luiz Augusto von Dentz <luiz.dentz@gmail.com>, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] Bluetooth: add missing checks in state transitions Date: Fri, 9 Feb 2024 02:04:44 -0500 Message-Id: <20240209070443.3617790-1-iam@sung-woo.kim> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790404095669333543 X-GMAIL-MSGID: 1790404095669333543 |
Series |
Bluetooth: add missing checks in state transitions
|
|
Commit Message
Sungwoo Kim
Feb. 9, 2024, 7:04 a.m. UTC
When an l2cap channel receives L2CAP_CONN_RSP, it revives from BT_DISCONN
to BT_CONFIG or BT_CONNECTED.
It is very weird, violates the specification, and I cannot see any real
usecase for this.
Similar to this, the L2cap channel has six illegal state transitions:
1. BT_CONNECT2 -> BT_CONFIG by L2CAP_CONN_RSP
2. BT_CONNECT2 -> BT_CONNECTED by L2CAP_CONF_RSP
3. BT_CONNECT2 -> BT_DISCONN by L2CAP_CONF_RSP
4. BT_CONNECTED -> BT_CONFIG by L2CAP_CONN_RSP
5. BT_DISCONN -> BT_CONFIG by L2CAP_CONN_RSP
6. BT_DISCONN -> BT_CONNECTED by L2CAP_CONN_RSP
This patch fixes 2, 3, 5, and 6 by adding checks.
For 1 and 4, I will make an RFC for as it requires some refactoring.
The detaild logs are described in here:
https://lore.kernel.org/lkml/CAJNyHpKpDdps4=QHZ77zu4jfY-NNBcGUrw6UwjuBKfpuSuE__g@mail.gmail.com/
Signed-off-by: Sungwoo Kim <iam@sung-woo.kim>
---
net/bluetooth/l2cap_core.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
Comments
Hello, could I ask for comments on this? On Fri, Feb 9, 2024 at 2:06 AM Sungwoo Kim <iam@sung-woo.kim> wrote: > > When an l2cap channel receives L2CAP_CONN_RSP, it revives from BT_DISCONN > to BT_CONFIG or BT_CONNECTED. > It is very weird, violates the specification, and I cannot see any real > usecase for this. > Similar to this, the L2cap channel has six illegal state transitions: > > 1. BT_CONNECT2 -> BT_CONFIG by L2CAP_CONN_RSP > 2. BT_CONNECT2 -> BT_CONNECTED by L2CAP_CONF_RSP > 3. BT_CONNECT2 -> BT_DISCONN by L2CAP_CONF_RSP > 4. BT_CONNECTED -> BT_CONFIG by L2CAP_CONN_RSP > 5. BT_DISCONN -> BT_CONFIG by L2CAP_CONN_RSP > 6. BT_DISCONN -> BT_CONNECTED by L2CAP_CONN_RSP > > This patch fixes 2, 3, 5, and 6 by adding checks. > For 1 and 4, I will make an RFC for as it requires some refactoring. > > The detaild logs are described in here: > https://lore.kernel.org/lkml/CAJNyHpKpDdps4=QHZ77zu4jfY-NNBcGUrw6UwjuBKfpuSuE__g@mail.gmail.com/ > > Signed-off-by: Sungwoo Kim <iam@sung-woo.kim> > --- > net/bluetooth/l2cap_core.c | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c > index 60298975d..c5fa2b683 100644 > --- a/net/bluetooth/l2cap_core.c > +++ b/net/bluetooth/l2cap_core.c > @@ -4339,6 +4339,14 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn, > > l2cap_chan_lock(chan); > > + switch (chan->state) { > + case BT_CLOSED: > + case BT_DISCONN: > + l2cap_chan_unlock(chan); > + l2cap_chan_put(chan); > + goto unlock; > + } > + > switch (result) { > case L2CAP_CR_SUCCESS: > if (__l2cap_get_chan_by_dcid(conn, dcid)) { > @@ -4552,6 +4560,14 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, > if (!chan) > return 0; > > + switch (chan->state) { > + case BT_CLOSED: > + case BT_CONNECT: > + case BT_CONNECT2: > + case BT_DISCONN: > + goto done; > + } > + > switch (result) { > case L2CAP_CONF_SUCCESS: > l2cap_conf_rfc_get(chan, rsp->data, len); > -- > 2.25.1 >
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 60298975d..c5fa2b683 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4339,6 +4339,14 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn, l2cap_chan_lock(chan); + switch (chan->state) { + case BT_CLOSED: + case BT_DISCONN: + l2cap_chan_unlock(chan); + l2cap_chan_put(chan); + goto unlock; + } + switch (result) { case L2CAP_CR_SUCCESS: if (__l2cap_get_chan_by_dcid(conn, dcid)) { @@ -4552,6 +4560,14 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, if (!chan) return 0; + switch (chan->state) { + case BT_CLOSED: + case BT_CONNECT: + case BT_CONNECT2: + case BT_DISCONN: + goto done; + } + switch (result) { case L2CAP_CONF_SUCCESS: l2cap_conf_rfc_get(chan, rsp->data, len);