Bluetooth: L2CAP: Fix regressions caused by reusing ident
Subsystems (2)
Luiz Augusto von Dentz
maintainerPATCH 1/1 Bluetooth: L2CAP: Fix regressions caused by reusing ident
From: Luiz Augusto von Dentz <[email protected]>
This attempt to fix regressions caused by reusing ident which apparently is not handled well on certain stacks causing the stack to not respond to requests, so instead of simple returning the first unallocated id this stores the last used tx_ident and then attempt to use the next until all available ids are exausted and then cycle starting over to 1.
--- include/net/bluetooth/l2cap.h | 1 + net/bluetooth/l2cap_core.c | 39 +++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-)
include/net/bluetooth/l2cap.h +1 -0
@@ -658,6 +658,7 @@ struct l2cap_conn {struct sk_buff *rx_skb;__u32 rx_len;struct ida tx_ida; +__u8 tx_ident;struct sk_buff_head pending_rx;struct work_struct pending_rx_work;
net/bluetooth/l2cap_core.c +30 -9
@@ -926,16 +926,37 @@ int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator)static int l2cap_get_ident (struct l2cap_conn *conn) { -/* LE link does not support tools like l2ping so use the full range */ -if (conn->hcon->type ==LE_LINK ) -return ida_alloc_range (&conn->tx_ida,1 ,255 ,GFP_ATOMIC ); +int ident; -/* Get next available identificator. -* 1 - 128 are used by kernel. -* 129 - 199 are reserved. -* 200 - 254 are used by utilities like l2ping, etc. -*/ -return ida_alloc_range (&conn->tx_ida,1 ,128 ,GFP_ATOMIC ); +/* LE link does not support tools like l2ping so use the full range */ +if (conn->hcon->type ==LE_LINK ) { +/* Allocate ident using min as last used + 1 (cyclic) */ + ident =ida_alloc_range (&conn->tx_ida, ++conn->tx_ident, +255 ,GFP_ATOMIC ); +/* Force min 1 to start over */ +if (ident <0 ) + ident =ida_alloc_range (&conn->tx_ida,1 ,255 , +GFP_ATOMIC ); + }else { +/* Get next available identificator. +* 1 - 128 are used by kernel. +* 129 - 199 are reserved. +* 200 - 254 are used by utilities like l2ping, etc. +*/ + +/* Allocate ident using min as last used + 1 (cyclic) */ + ident =ida_alloc_range (&conn->tx_ida, ++conn->tx_ident, +128 ,GFP_ATOMIC ); +/* Force min 1 to start over */ +if (ident <0 ) + ident =ida_alloc_range (&conn->tx_ida,1 ,128 , +GFP_ATOMIC ); + } + +if (ident >0 ) + conn->tx_ident = ident; + +return ident; } static void l2cap_send_acl(struct l2cap_conn *conn, struct sk_buff *skb,
Signature · 1 line
2.53.0
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1068106
---Test result---
Test Summary:
CheckPatch PENDING 0.54 seconds GitLint PENDING 0.54 seconds SubjectPrefix PASS 0.06 seconds BuildKernel PASS 27.06 seconds CheckAllWarning PASS 29.69 seconds CheckSparse PASS 28.44 seconds BuildKernel32 PASS 25.51 seconds TestRunnerSetup PASS 575.15 seconds TestRunner_l2cap-tester PASS 28.26 seconds TestRunner_iso-tester FAIL 35.32 seconds TestRunner_bnep-tester PASS 6.23 seconds TestRunner_mgmt-tester FAIL 116.16 seconds TestRunner_rfcomm-tester PASS 9.30 seconds TestRunner_sco-tester FAIL 18.56 seconds TestRunner_ioctl-tester PASS 10.23 seconds TestRunner_mesh-tester FAIL 12.50 seconds TestRunner_smp-tester PASS 8.57 seconds TestRunner_userchan-tester PASS 6.70 seconds IncrementalBuild PENDING 0.70 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: TestRunner_iso-tester - FAIL
Desc: Run iso-tester with test-runner
Output:
BUG: KASAN: slab-use-after-free in le_read_features_complete+0x7e/0x2b0
Total: 141, Passed: 141 (100.0%), Failed: 0, Not Run: 0
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 494, Passed: 489 (99.0%), Failed: 1, Not Run: 4
Failed Test Cases
Read Exp Feature - Success Failed 0.112 seconds
##############################
Test: TestRunner_sco-tester - FAIL
Desc: Run sco-tester with test-runner
Output:
WARNING: possible circular locking dependency detected
BUG: sleeping function called from invalid context at net/core/sock.c:3782
Total: 30, Passed: 30 (100.0%), Failed: 0, Not Run: 0
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0
Failed Test Cases
Mesh - Send cancel - 1 Timed out 2.736 seconds Mesh - Send cancel - 2 Timed out 1.994 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:
---
Regards,
Linux Bluetooth
Luiz Augusto von Dentz
maintainerHi Christian,
Quoted 82 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This attempt to fix regressions caused by reusing ident which apparently is not handled well on certain stacks causing the stack to not respond to requests, so instead of simple returning the first unallocated id this stores the last used
tx_identand then attempt to use the next until all available ids are exausted and then cycle starting over to 1.Fixes 6c3ea155e5ee ("Bluetooth: L2CAP: Fix not tracking outstanding TX ident")Signed-off-by Luiz Augusto von Dentz <[email protected]>--- include/net/bluetooth/l2cap.h | 1 + net/bluetooth/l2cap_core.c | 39 +++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-)include/net/bluetooth/l2cap.h +1
-0@@ -658,6 +658,7 @@ struct l2cap_conn {struct sk_buff *rx_skb;__u32 rx_len;struct ida tx_ida; +__u8 tx_ident;struct sk_buff_head pending_rx;struct work_struct pending_rx_work;net/bluetooth/l2cap_core.c +30
-10@@ -926,16 +926,37 @@ int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator)static int l2cap_get_ident (struct l2cap_conn *conn) { -/* LE link does not support tools like l2ping so use the full range */ -if (conn->hcon->type ==LE_LINK ) -return ida_alloc_range (&conn->tx_ida,1 ,255 ,GFP_ATOMIC ); +int ident; -/* Get next available identificator. -* 1 - 128 are used by kernel. -* 129 - 199 are reserved. -* 200 - 254 are used by utilities like l2ping, etc. -*/ -return ida_alloc_range (&conn->tx_ida,1 ,128 ,GFP_ATOMIC ); +/* LE link does not support tools like l2ping so use the full range */ +if (conn->hcon->type ==LE_LINK ) { +/* Allocate ident using min as last used + 1 (cyclic) */ + ident =ida_alloc_range (&conn->tx_ida, ++conn->tx_ident, +255 ,GFP_ATOMIC ); +/* Force min 1 to start over */ +if (ident <0 ) + ident =ida_alloc_range (&conn->tx_ida,1 ,255 , +GFP_ATOMIC ); + }else { +/* Get next available identificator. +* 1 - 128 are used by kernel. +* 129 - 199 are reserved. +* 200 - 254 are used by utilities like l2ping, etc. +*/ + +/* Allocate ident using min as last used + 1 (cyclic) */ + ident =ida_alloc_range (&conn->tx_ida, ++conn->tx_ident, +128 ,GFP_ATOMIC ); +/* Force min 1 to start over */ +if (ident <0 ) + ident =ida_alloc_range (&conn->tx_ida,1 ,128 , +GFP_ATOMIC ); + } + +if (ident >0 ) + conn->tx_ident = ident; + +return ident; } static void l2cap_send_acl(struct l2cap_conn *conn, struct sk_buff *skb, --
Quoted 2 lines
2.53.0
Do you have any capacity to test the above with L2CAP/COS/CED/BI-29-C?
Signature · 1 line
Luiz Augusto von Dentz
Hi Luiz,
Quoted 84 lines · Luiz Augusto von Dentz
Hi Christian,
Quoted 80 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This attempt to fix regressions caused by reusing ident which apparently is not handled well on certain stacks causing the stack to not respond to requests, so instead of simple returning the first unallocated id this stores the last used
tx_identand then attempt to use the next until all available ids are exausted and then cycle starting over to 1.Fixes 6c3ea155e5ee ("Bluetooth: L2CAP: Fix not tracking outstanding TX ident")Signed-off-by Luiz Augusto von Dentz <[email protected]>--- include/net/bluetooth/l2cap.h | 1 + net/bluetooth/l2cap_core.c | 39 +++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-)include/net/bluetooth/l2cap.h +1
-0@@ -658,6 +658,7 @@ struct l2cap_conn {struct sk_buff *rx_skb;__u32 rx_len;struct ida tx_ida; +__u8 tx_ident;struct sk_buff_head pending_rx;struct work_struct pending_rx_work;net/bluetooth/l2cap_core.c +30
-9@@ -926,16 +926,37 @@ int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator)static int l2cap_get_ident (struct l2cap_conn *conn) { -/* LE link does not support tools like l2ping so use the full range */ -if (conn->hcon->type ==LE_LINK ) -return ida_alloc_range (&conn->tx_ida,1 ,255 ,GFP_ATOMIC ); +int ident; -/* Get next available identificator. -* 1 - 128 are used by kernel. -* 129 - 199 are reserved. -* 200 - 254 are used by utilities like l2ping, etc. -*/ -return ida_alloc_range (&conn->tx_ida,1 ,128 ,GFP_ATOMIC ); +/* LE link does not support tools like l2ping so use the full range */ +if (conn->hcon->type ==LE_LINK ) { +/* Allocate ident using min as last used + 1 (cyclic) */ + ident =ida_alloc_range (&conn->tx_ida, ++conn->tx_ident, +255 ,GFP_ATOMIC ); +/* Force min 1 to start over */ +if (ident <0 ) + ident =ida_alloc_range (&conn->tx_ida,1 ,255 , +GFP_ATOMIC ); + }else { +/* Get next available identificator. +* 1 - 128 are used by kernel. +* 129 - 199 are reserved. +* 200 - 254 are used by utilities like l2ping, etc. +*/ + +/* Allocate ident using min as last used + 1 (cyclic) */ + ident =ida_alloc_range (&conn->tx_ida, ++conn->tx_ident, +128 ,GFP_ATOMIC ); +/* Force min 1 to start over */ +if (ident <0 ) + ident =ida_alloc_range (&conn->tx_ida,1 ,128 , +GFP_ATOMIC ); + } + +if (ident >0 ) + conn->tx_ident = ident; + +return ident; }
Quoted 6 lines
Quoted 4 lines
net/bluetooth/l2cap_core.c +0
-1static void l2cap_send_acl(struct l2cap_conn *conn, struct sk_buff *skb, --2.53.0
Do you have any capacity to test the above with L2CAP/COS/CED/BI-29-C?
Today my test system seems a little bit bitchy, so L2CAP/COS/CED/BI-29-C even doesn't complete with my latest working version...
After applying this patch on top of my latest version (6.19.9 + the BT patches I already submitted), I see a new error (log is below). At 40344 ms, the connection request sent by the IUT has an identifier value of '0' (just after wrapping around) which is not a valid identifier as of Core Vol 3, part A, chapter 4 (page 1122):
"Signaling identifier 0x00 is an invalid identifier and shall never be used in any command."
Any idea why the identifier used by the IUT wraps around from 255 to 0 instead of 1?
regards,
Christian
+40078 ms
Verdict Description: Received CMD:LE Credit Based Connection REQ:
Code: [20 (0x14)] Code
Identifier: [254 (0xFE)]
Length: [10 (0x000A)]
SPSM: [128 (0x0080)]
Source CID: [64 (0x0040)]
MTU: [672 (0x02A0)]
MPS: [23 (0x0017)]
Initial Credits: [30 (0x001E)]+40078 ms
Verdict Description: Sent=LE Credit Based Connection RSP:
Code: [21 (0x15)] Code
Identifier: [0 (0x00)]
Length: [10 (0x000A)]
Destination CID: [79 (0x004F)]
MTU: [64 (0x0040)]
MPS: [64 (0x0040)]
Initial Credits: [2 (0x0002)]
Result: [0 (0x0000)] Connection Successful+40078 ms
Send Event HCI!ACL_DATA_REQ{
connectionHandle=0x0010,
boundary=0x00,
broadcasting=0x00,
length=0x0012,
p_data[0]=0x0E
}+40250 ms
Receive Event HCI?ACL_DATA{
connHandle=0x0010,
length=18,
boundaryFlag=0x02,
broadcastFlag=0x00
}+40250 ms
Verdict Description: ReceivePacket!
receive=0E00050014FF0A0080004000A00217001E00, CID=5
+40250 ms
Verdict Description: Received CMD:LE Credit Based Connection REQ:
Code: [20 (0x14)] Code
Identifier: [255 (0xFF)]
Length: [10 (0x000A)]
SPSM: [128 (0x0080)]
Source CID: [64 (0x0040)]
MTU: [672 (0x02A0)]
MPS: [23 (0x0017)]
Initial Credits: [30 (0x001E)]+40250 ms
Verdict Description: Sent=LE Credit Based Connection RSP:
Code: [21 (0x15)] Code
Identifier: [0 (0x00)]
Length: [10 (0x000A)]
Destination CID: [80 (0x0050)]
MTU: [64 (0x0040)]
MPS: [64 (0x0040)]
Initial Credits: [2 (0x0002)]
Result: [0 (0x0000)] Connection Successful+40250 ms
Send Event HCI!ACL_DATA_REQ{
connectionHandle=0x0010,
boundary=0x00,
broadcasting=0x00,
length=0x0012,
p_data[0]=0x0E
}+40344 ms
Receive Event HCI?ACL_DATA{
connHandle=0x0010,
length=18,
boundaryFlag=0x02,
broadcastFlag=0x00
}+40344 ms
Verdict Description: ReceivePacket!
receive=0E00050014000A0080004000A00217001E00, CID=5
+40344 ms
Verdict Description: Received CMD:LE Credit Based Connection REQ:
Code: [20 (0x14)] Code
Identifier: [0 (0x00)]
Length: [10 (0x000A)]
SPSM: [128 (0x0080)]
Source CID: [64 (0x0040)]
MTU: [672 (0x02A0)]
MPS: [23 (0x0017)]
Initial Credits: [30 (0x001E)]+40344 ms
Verdict Description: Sent=LE Credit Based Connection RSP:
Code: [21 (0x15)] Code
Identifier: [0 (0x00)]
Length: [10 (0x000A)]
Destination CID: [81 (0x0051)]
MTU: [64 (0x0040)]
MPS: [64 (0x0040)]
Initial Credits: [2 (0x0002)]
Result: [0 (0x0000)] Connection Successful+40344 ms
Send Event HCI!ACL_DATA_REQ{
connectionHandle=0x0010,
boundary=0x00,
broadcasting=0x00,
length=0x0012,
p_data[0]=0x0E
}+40422 ms
Indecisive: Received Identifier is not unique. Received=0
+40422 ms
Verdict Description: Received Identifier is not unique. Received=0
+40625 ms
Send Event HCI!HCI_RESET
Luiz Augusto von Dentz
maintainerHi Christian,
Quoted 104 lines · Christian Eggers
Hi Luiz,
Quoted 84 lines · Luiz Augusto von Dentz
Hi Christian,
Quoted 80 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This attempt to fix regressions caused by reusing ident which apparently is not handled well on certain stacks causing the stack to not respond to requests, so instead of simple returning the first unallocated id this stores the last used
tx_identand then attempt to use the next until all available ids are exausted and then cycle starting over to 1.Fixes 6c3ea155e5ee ("Bluetooth: L2CAP: Fix not tracking outstanding TX ident")Signed-off-by Luiz Augusto von Dentz <[email protected]>--- include/net/bluetooth/l2cap.h | 1 + net/bluetooth/l2cap_core.c | 39 +++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-)include/net/bluetooth/l2cap.h +1
-0@@ -658,6 +658,7 @@ struct l2cap_conn {struct sk_buff *rx_skb;__u32 rx_len;struct ida tx_ida; +__u8 tx_ident;struct sk_buff_head pending_rx;struct work_struct pending_rx_work;net/bluetooth/l2cap_core.c +30
-9@@ -926,16 +926,37 @@ int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator)static int l2cap_get_ident (struct l2cap_conn *conn) { -/* LE link does not support tools like l2ping so use the full range */ -if (conn->hcon->type ==LE_LINK ) -return ida_alloc_range (&conn->tx_ida,1 ,255 ,GFP_ATOMIC ); +int ident; -/* Get next available identificator. -* 1 - 128 are used by kernel. -* 129 - 199 are reserved. -* 200 - 254 are used by utilities like l2ping, etc. -*/ -return ida_alloc_range (&conn->tx_ida,1 ,128 ,GFP_ATOMIC ); +/* LE link does not support tools like l2ping so use the full range */ +if (conn->hcon->type ==LE_LINK ) { +/* Allocate ident using min as last used + 1 (cyclic) */ + ident =ida_alloc_range (&conn->tx_ida, ++conn->tx_ident, +255 ,GFP_ATOMIC ); +/* Force min 1 to start over */ +if (ident <0 ) + ident =ida_alloc_range (&conn->tx_ida,1 ,255 , +GFP_ATOMIC ); + }else { +/* Get next available identificator. +* 1 - 128 are used by kernel. +* 129 - 199 are reserved. +* 200 - 254 are used by utilities like l2ping, etc. +*/ + +/* Allocate ident using min as last used + 1 (cyclic) */ + ident =ida_alloc_range (&conn->tx_ida, ++conn->tx_ident, +128 ,GFP_ATOMIC ); +/* Force min 1 to start over */ +if (ident <0 ) + ident =ida_alloc_range (&conn->tx_ida,1 ,128 , +GFP_ATOMIC ); + } + +if (ident >0 ) + conn->tx_ident = ident; + +return ident; }Quoted 6 lines
Quoted 4 lines
net/bluetooth/l2cap_core.c +0
-1static void l2cap_send_acl(struct l2cap_conn *conn, struct sk_buff *skb, --2.53.0
Do you have any capacity to test the above with L2CAP/COS/CED/BI-29-C?
Today my test system seems a little bit bitchy, so L2CAP/COS/CED/BI-29-C even doesn't complete with my latest working version...
After applying this patch on top of my latest version (6.19.9 + the BT patches I already submitted), I see a new error (log is below). At 40344 ms, the connection request sent by the IUT has an identifier value of '0' (just after wrapping around) which is not a valid identifier as of Core Vol 3, part A, chapter 4 (page 1122):
Quoted 5 lines
"Signaling identifier
0x00is an invalid identifier and shall never be used in any command."Any idea why the identifier used by the IUT wraps around from 255 to 0 instead of 1?
Yeah, that seem to be a bug in the new version, let me check how to fix it.
Quoted 160 lines
regards,
Christian+40078 ms
Verdict Description: Received CMD:LE Credit Based Connection REQ:Code: [20 (0x14)] Code Identifier: [254 (0xFE)] Length: [10 (0x000A)] SPSM: [128 (0x0080)] Source CID: [64 (0x0040)] MTU: [672 (0x02A0)] MPS: [23 (0x0017)] Initial Credits: [30 (0x001E)]+40078 ms
Verdict Description: Sent=LE Credit Based Connection RSP:Code: [21 (0x15)] Code Identifier: [0 (0x00)] Length: [10 (0x000A)] Destination CID: [79 (0x004F)] MTU: [64 (0x0040)] MPS: [64 (0x0040)] Initial Credits: [2 (0x0002)] Result: [0 (0x0000)] Connection Successful+40078 ms
Send Event HCI!ACL_DATA_REQ{ connectionHandle=0x0010, boundary=0x00, broadcasting=0x00, length=0x0012, p_data[0]=0x0E }+40250 ms
Receive Event HCI?ACL_DATA{ connHandle=0x0010, length=18, boundaryFlag=0x02, broadcastFlag=0x00 }+40250 ms
Verdict Description: ReceivePacket!
receive=0E00050014FF0A0080004000A00217001E00, CID=5+40250 ms
Verdict Description: Received CMD:LE Credit Based Connection REQ:Code: [20 (0x14)] Code Identifier: [255 (0xFF)] Length: [10 (0x000A)] SPSM: [128 (0x0080)] Source CID: [64 (0x0040)] MTU: [672 (0x02A0)] MPS: [23 (0x0017)] Initial Credits: [30 (0x001E)]+40250 ms
Verdict Description: Sent=LE Credit Based Connection RSP:Code: [21 (0x15)] Code Identifier: [0 (0x00)] Length: [10 (0x000A)] Destination CID: [80 (0x0050)] MTU: [64 (0x0040)] MPS: [64 (0x0040)] Initial Credits: [2 (0x0002)] Result: [0 (0x0000)] Connection Successful+40250 ms
Send Event HCI!ACL_DATA_REQ{ connectionHandle=0x0010, boundary=0x00, broadcasting=0x00, length=0x0012, p_data[0]=0x0E }+40344 ms
Receive Event HCI?ACL_DATA{ connHandle=0x0010, length=18, boundaryFlag=0x02, broadcastFlag=0x00 }+40344 ms
Verdict Description: ReceivePacket!
receive=0E00050014000A0080004000A00217001E00, CID=5+40344 ms
Verdict Description: Received CMD:LE Credit Based Connection REQ:Code: [20 (0x14)] Code Identifier: [0 (0x00)] Length: [10 (0x000A)] SPSM: [128 (0x0080)] Source CID: [64 (0x0040)] MTU: [672 (0x02A0)] MPS: [23 (0x0017)] Initial Credits: [30 (0x001E)]+40344 ms
Verdict Description: Sent=LE Credit Based Connection RSP:Code: [21 (0x15)] Code Identifier: [0 (0x00)] Length: [10 (0x000A)] Destination CID: [81 (0x0051)] MTU: [64 (0x0040)] MPS: [64 (0x0040)] Initial Credits: [2 (0x0002)] Result: [0 (0x0000)] Connection Successful+40344 ms
Send Event HCI!ACL_DATA_REQ{ connectionHandle=0x0010, boundary=0x00, broadcasting=0x00, length=0x0012, p_data[0]=0x0E }+40422 ms
Indecisive: Received Identifier is not unique. Received=0+40422 ms
Verdict Description: Received Identifier is not unique. Received=0+40625 ms
Send Event HCI!HCI_RESET
Signature · 1 line
Luiz Augusto von Dentz