netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: L2CAP: Fix u8 overflow
@ 2022-11-18 20:01 Sungwoo Kim
  2022-11-22  0:50 ` patchwork-bot+bluetooth
  0 siblings, 1 reply; 2+ messages in thread
From: Sungwoo Kim @ 2022-11-18 20:01 UTC (permalink / raw)
  Cc: Sungwoo Kim, Marcel Holtmann, Johan Hedberg,
	Luiz Augusto von Dentz, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-bluetooth, netdev,
	linux-kernel

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 <iam@sung-woo.kim>
---
 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 9c24947aa..9fdede5fe 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;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Bluetooth: L2CAP: Fix u8 overflow
  2022-11-18 20:01 [PATCH] Bluetooth: L2CAP: Fix u8 overflow Sungwoo Kim
@ 2022-11-22  0:50 ` patchwork-bot+bluetooth
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+bluetooth @ 2022-11-22  0:50 UTC (permalink / raw)
  To: Sungwoo Kim
  Cc: marcel, johan.hedberg, luiz.dentz, davem, edumazet, kuba, pabeni,
	linux-bluetooth, netdev, linux-kernel

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Fri, 18 Nov 2022 15:01:47 -0500 you wrote:
> 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              ........@...
> 
> [...]

Here is the summary with links:
  - Bluetooth: L2CAP: Fix u8 overflow
    https://git.kernel.org/bluetooth/bluetooth-next/c/ae4569813a6e

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-22  0:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-18 20:01 [PATCH] Bluetooth: L2CAP: Fix u8 overflow Sungwoo Kim
2022-11-22  0:50 ` patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).