mina-sshd: exceptionCaught(ServerSessionImpl[user@/10.x.x.x:23232])[state=Opened] IllegalStateException: Bad length (32796) for cmd=SSH_MSG_CHANNEL_DATA - max. allowed=32768
Client: WS_FTP 1.26/1.27 Server: SFTP server (mina 2.9.2)
Operation: Uploading a file
Mina version - 2.9.2
As sftp client tries to upload a file channel is closed as below exception is caught.
2023-08-10 10:16:31 2023-08-10T17:16:31.119Z WARN 337 --- [] [] [] [)-nio2-thread-3] o.a.s.server.session.ServerSessionImpl : exceptionCaught(ServerSessionImpl[user@/10.x.x.x:23232])[state=Opened] IllegalStateException: Bad length (32796) for cmd=SSH_MSG_CHANNEL_DATA - max. allowed=32768
Is there a way or config via core module props to increase the channel packet size limit?
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 18 (11 by maintainers)
Commits related to this issue
- GH-403: Work-around for WS_FTP client bug If the file handle size in Apache MINA sshd is > 4, WS_FTP client <= 12.9 sends (fileHandleSize - 4) too many bytes in SSH_FXP_WRITE requests. If that exceed... — committed to tomaswolf/mina-sshd by tomaswolf 10 months ago
- GH-403: Fix SFTP handle size Change the file handle implementation: use raw bytes, not hexified bytes. Representing file handles internally as hexified strings doubled the size, so with the default s... — committed to tomaswolf/mina-sshd by tomaswolf 10 months ago
- GH-403: Use 4-byte SFTP file handles by default Change the default size for SFTP file handles to 4 bytes, and change the implementation such that it produces collision-free 4-byte handles. The algor... — committed to tomaswolf/mina-sshd by tomaswolf 10 months ago
- GH-403: Fix SFTP handle size Change the file handle implementation: use raw bytes, not hexified bytes. Representing file handles internally as hexified strings doubled the size, so with the default s... — committed to tomaswolf/mina-sshd by tomaswolf 10 months ago
- GH-403: Use 4-byte SFTP file handles by default Change the default size for SFTP file handles to 4 bytes, and change the implementation such that it produces collision-free 4-byte handles. The algor... — committed to tomaswolf/mina-sshd by tomaswolf 10 months ago
- GH-403: Work-around for WS_FTP client bug If the file handle size in Apache MINA sshd is > 4, WS_FTP client <= 12.9 sends (fileHandleSize - 4) too many bytes in SSH_FXP_WRITE requests. If that exceed... — committed to tomaswolf/mina-sshd by tomaswolf 10 months ago
- GH-403: Fix SFTP handle size Change the file handle implementation: use raw bytes, not hexified bytes. Representing file handles internally as hexified strings doubled the size, so with the default s... — committed to tomaswolf/mina-sshd by tomaswolf 10 months ago
- GH-403: Use 4-byte SFTP file handles by default Change the default size for SFTP file handles to 4 bytes, and change the implementation such that it produces collision-free 4-byte handles. The algor... — committed to tomaswolf/mina-sshd by tomaswolf 10 months ago
@dragonknight88 : PR #405 has been merged. Using the 2.10.1-SNAPSHOT release from the Apache Snapshot maven repository you could test whether it really works with WS_FTP with different handle sizes. If not, feel free to re-open this.
Ultimately it would be good if the vendor of WS_FTP fixed that bug in their SFTP client.
Yes, that was my mistake when reading the code. File handle size 16 means it uses 16 bytes, but then converts these to a hex string, which gives 32 characters, and thus we have with
SftpModuleProperties.FILE_HANDLE_SIZE = 1632 bytes for the actual file handle and thus in the SSH network messages. As I wrote, the implementation is strange. š¦Now that this is confirmed:
BTW, the ā+4 confusionā is this: https://mailarchive.ietf.org/arch/msg/secsh/mIvfsnrukzaIvUBah5RJjDb3yyQ/
Itās basically unrelated to this handle size problem. But it makes the SFTP write from WS_FTP work if the handle size in Apache MINA sshd is set to 4: then we get 8 bytes of actual handle, and WS_FTP will send exactly 4 bytes too many, which Apache MINA sshd will accept, but for the wrong reason as itās not this ā+4 confusionā but a bug at another level that just happens to also cause exactly 4 extra bytes.
Yes, Iāll also do something like that. Except that this validation is in the connection protocol (RFC 4254), and fileHandleSize is known only in the higher-layer SFTP protocol, so a bit more is needed to implement this in a proper way without layer breaks. Weād want to accept this extra size only in SFTP channels, and only if itās exactly this expected extra amount of bytes.
All that said: I find the file handle implementation in Apache MINA sshd a little bit strange. I donāt know why it is done the way it is done; it strikes me as overly complicated. I see absolutely no reason why a file handle should be longer than 4 bytes, be it in memory or in the network packet.
So even if I think we may have found a bug in WS_FTP, I also think the Apache MINA sshd implementation could be simplified and use by default a handle size of 4 bytes.
Thanks, that helps. I was a bit confused for a moment by the log being chronologically descending, but thatās OK. The interesting bit are these two lines:
This shows the SSH message itself is internally consistent. We have
5eSSH_MSG_CHANNEL_DATA00 00 00 00Channel ID = 000 01 00 1cLength of data following: 65564 bytes, which is higher than the packet size you configured (65536)Next comes the data itself, which is an SFTP write request:
00 01 00 18Length of data following: 65560 bytes06SSH_FXP_WRITE00 00 04 d2SFTP request ID00 00 00 20SFTP file handle length (32)00 00 00 00 00 00 00 00File position to write to: offset 000 00 ff e3number of bytes to write: 65507 bytesAlso visible from the log: itās the first SSH_FXP_WRITE request for this file (thereās an SSH_FXP_OPEN request just before).
So whatever that client is doing, it really is sending 28 bytes too many. I do notice that 28 = 32 - 4. OpenSSH returns handles that have only 4 bytes. Apache MINA sshd uses by default handles of 16 bytes AFAIK, and it stringifies these 16 bytes, so we end up with 32 bytes (one byte per hex character).
The SFTP draft RFCs say that SFTP file handles may be up to 256 bytes long.
If you set the handle size in the Apache MINA sshd server to 8, we should end up with 16 hex chars. Does that client then send 12 extra bytes? And if the handle size is 20, we should have 40 bytes, does it then send 36 extra bytes? (For the configuration, see
SftpModuleProperties.FILE_HANDLE_SIZE. Apache MINA sshd allows values between 4 and 64.)If so, weād have established that this SFTP client can only handle SFTP file handles of 4 bytes. For larger handles, its length logic for SFTP write requests (SSH_FXP_WRITE) is wrong.
This would also explain why it works with OpenSSH: an OpenSSH server will use a handle size of 4 bytes.