net: mctp-serial: Fix for missing tx escapes
Subsystems (4)
Matt Johnston
maintainerv2 cover net: mctp-serial: Fix for missing tx escapes
The mctp-serial code to add escape characters was incorrect due to an off-by-one error. This series adds a test for the chunking which splits by escape characters, and fixes the bug.
v2: Fix kunit param const pointer
Matt Johnston (2):
net: mctp-serial: Add kunit test for next_chunk_len()
net: mctp-serial: Fix missing escapes on transmit
drivers/net/mctp/Kconfig | 5 ++ drivers/net/mctp/mctp-serial.c | 113 ++++++++++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 2 deletions(-)
Matt Johnston
maintainerPATCH v2 1/2 net: mctp-serial: Add kunit test for next_chunk_len()
Test various edge cases of inputs that contain characters that need escaping.
This adds a new kunit suite for mctp-serial.
---
v2: Fix kunit param const pointer
drivers/net/mctp/Kconfig | 5 ++ drivers/net/mctp/mctp-serial.c | 109 +++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+)
drivers/net/mctp/Kconfig +5 -0
@@ -21,6 +21,11 @@ config MCTP_SERIAL Say y here if you need to connect to MCTP endpoints over serial. To compile as a module, use m; the module will be called mctp-serial. +config MCTP_SERIAL_TEST + bool "MCTP serial tests" if !KUNIT_ALL_TESTS + depends on MCTP_SERIAL=y && KUNIT=y + default KUNIT_ALL_TESTS + config MCTP_TRANSPORT_I2C tristate "MCTP SMBus/I2C transport" # i2c-mux is optional, but we must build as a module if i2c-mux is a module
drivers/net/mctp/mctp-serial.c +109 -0
112 lines not on this page · raw message
Matt Johnston
maintainerPATCH v2 2/2 net: mctp-serial: Fix missing escapes on transmit
In reply to Matt Johnston0x7d and 0x7e bytes are meant to be escaped in the data portion of frames, but this didn't occur since next_chunk_len() had an off-by-one error. That also resulted in the final byte of a payload being written as a separate tty write op.
The chunk prior to an escaped byte would be one byte short, and the next call would never test the txpos+1 case, which is where the escaped byte was located. That meant it never hit the escaping case in mctp_serial_tx_work().
Example Input: 01 00 08 c8 7e 80 02
Previous incorrect chunks from next_chunk_len():
01 00 08
c8 7e 80
02
With this fix:
01 00 08 c8
7e
80 02
--- drivers/net/mctp/mctp-serial.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mctp/mctp-serial.c +2 -2
@@ -91,8 +91,8 @@ static int next_chunk_len(struct mctp_serial *dev)* will be those non-escaped bytes, and does not include the escaped * byte. */ -for (i =1 ; i + dev->txpos +1 < dev->txlen; i++) { -if (needs_escape (dev->txbuf[dev->txpos + i +1 ])) +for (i =1 ; i + dev->txpos < dev->txlen; i++) { +if (needs_escape (dev->txbuf[dev->txpos + i]))break ; }
This series was applied to netdev/net.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:
Quoted 11 lines · On Thu, 29 Aug 2024 15:43:44 +0800 you wrote:
The mctp-serial code to add escape characters was incorrect due to an off-by-one error. This series adds a test for the chunking which splits by escape characters, and fixes the bug.
v2: Fix kunit param const pointer
Matt Johnston (2):
net: mctp-serial: Add kunit test fornext_chunk_len()
net: mctp-serial: Fix missing escapes on transmit[...]
Here is the summary with links:
- [net,v2,1/2] net: mctp-serial: Add kunit test for next_chunk_len()
https://git.kernel.org/netdev/net/c/4fa9c5181cfe - [net,v2,2/2] net: mctp-serial: Fix missing escapes on transmit https://git.kernel.org/netdev/net/c/f962e8361adf
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html