]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
smb: client: Store original IO parameters and prevent zero IO sizes
authorWang Zhaolong <wangzhaolong1@huawei.com>
Mon, 31 Mar 2025 13:33:14 +0000 (21:33 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 May 2025 09:12:23 +0000 (11:12 +0200)
commit48e0b052d8a93a3f2c4be38be16735bd39ee04b1
tree8fce0a752fbd20404bed5126f46ea65f3dcb9495
parent5cb41fa3074d49c142a7b82a86defa9378a41cb8
smb: client: Store original IO parameters and prevent zero IO sizes

[ Upstream commit 287906b20035a04a234d1a3c64f760a5678387be ]

During mount option processing and negotiation with the server, the
original user-specified rsize/wsize values were being modified directly.
This makes it impossible to recover these values after a connection
reset, leading to potential degraded performance after reconnection.

The other problem is that When negotiating read and write sizes, there are
cases where the negotiated values might calculate to zero, especially
during reconnection when server->max_read or server->max_write might be
reset. In general, these values come from the negotiation response.
According to MS-SMB2 specification, these values should be at least 65536
bytes.

This patch improves IO parameter handling:

1. Adds vol_rsize and vol_wsize fields to store the original user-specified
   values separately from the negotiated values
2. Uses got_rsize/got_wsize flags to determine if values were
   user-specified rather than checking for non-zero values, which is more
   reliable
3. Adds a prevent_zero_iosize() helper function to ensure IO sizes are
   never negotiated down to zero, which could happen in edge cases like
   when server->max_read/write is zero

The changes make the CIFS client more resilient to unusual server
responses and reconnection scenarios, preventing potential failures
when IO sizes are calculated to be zero.

Signed-off-by: Wang Zhaolong <wangzhaolong1@huawei.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/smb/client/fs_context.c
fs/smb/client/fs_context.h
fs/smb/client/smb1ops.c
fs/smb/client/smb2ops.c
fs/smb/common/smb2pdu.h