Skip to content

Quickly sandbox your AI agent.

Python

SMB: fix FileFsSectorSizeInformation size and force nosharesock so remounts don't wedge

Jace Medlin47a228099296
diff --git a/packages/quicksand-core/quicksand_core/_types.py b/packages/quicksand-core/quicksand_core/_types.py
index 4082231..a8ab9a1 100644
--- a/packages/quicksand-core/quicksand_core/_types.py
+++ b/packages/quicksand-core/quicksand_core/_types.py
@@ -459,9 +459,16 @@ class MountOptions:
"""Return CIFS mount options string.
Uses sec=none for guest/anonymous access, sec=ntlmssp for authenticated.
+
+ ``nosharesock`` forces a dedicated TCP connection per mount instead of
+ reusing one keyed by server address. The pure-Python SMB server serves
+ one session per connection and closes it on unmount; without
+ ``nosharesock`` a subsequent mount to the same host tries to resume the
+ just-closed session and fails with ``mount error(115) Operation now in
+ progress`` (a mount/unmount/mount cycle then wedges).
"""
sec = "none" if not password else "ntlmssp"
- return f"username={username},password={password},sec={sec},vers=3.0"
+ return f"username={username},password={password},sec={sec},vers=3.0,nosharesock"
# =============================================================================
diff --git a/packages/quicksand-smb/quicksand_smb/_query.py b/packages/quicksand-smb/quicksand_smb/_query.py
index a26bc7d..b782d19 100644
--- a/packages/quicksand-smb/quicksand_smb/_query.py
+++ b/packages/quicksand-smb/quicksand_smb/_query.py
@@ -409,13 +409,21 @@ def _handle_fs_info(info_class: int, path: Path) -> bytes | None:
)
elif info_class == FS_SECTOR_SIZE_INFORMATION:
+ # FILE_FS_SECTOR_SIZE_INFORMATION is 7 UINT32s (28 bytes) per
+ # [MS-FSCC] 2.5.8. Emitting only five (20 bytes) makes the Linux CIFS
+ # client reject the reply ("buffer length 20 smaller than minimum size
+ # 28") and retry/stall — which intermittently wedged statfs (e.g. during
+ # umount). The last two fields are the sector/partition alignment byte
+ # offsets; 0 means aligned.
return struct.pack(
- "<IIIII",
+ "<IIIIIII",
4096, # LogicalBytesPerSector
4096, # PhysicalBytesPerSectorForAtomicity
4096, # PhysicalBytesPerSectorForPerformance
4096, # FileSystemEffectivePhysicalBytesPerSectorForAtomicity
0, # Flags
+ 0, # ByteOffsetForSectorAlignment
+ 0, # ByteOffsetForPartitionAlignment
)
return None
diff --git a/tests/unit/smb/test_smb_server.py b/tests/unit/smb/test_smb_server.py
index 31343be..fed6816 100644
--- a/tests/unit/smb/test_smb_server.py
+++ b/tests/unit/smb/test_smb_server.py
@@ -908,3 +908,48 @@ class TestDynamicConfig:
header = _smb_header(Command.CREATE, tree_id=2, session_id=1)
response = _dispatch(session, parse_request(header + body))
assert _get_status(response) == STATUS_SUCCESS
+
+
+class TestFsInfoSizes:
+ """Regression tests for filesystem-info response sizes ([MS-FSCC] 2.5).
+
+ An undersized FILE_FS_SECTOR_SIZE_INFORMATION (20 bytes instead of the
+ required 28) made the Linux CIFS client reject the reply ("buffer length 20
+ smaller than minimum size 28") and stall statfs, which intermittently
+ wedged mount/unmount cycles. Each class must be at least its fixed size.
+ """
+
+ def test_fs_info_class_sizes(self, tmp_path):
+ from quicksand_smb._query import (
+ FS_ATTRIBUTE_INFORMATION,
+ FS_DEVICE_INFORMATION,
+ FS_FULL_SIZE_INFORMATION,
+ FS_SECTOR_SIZE_INFORMATION,
+ FS_SIZE_INFORMATION,
+ FS_VOLUME_INFORMATION,
+ _handle_fs_info,
+ )
+
+ # info_class -> minimum fixed byte size per MS-FSCC
+ minimums = {
+ FS_VOLUME_INFORMATION: 18,
+ FS_SIZE_INFORMATION: 24,
+ FS_FULL_SIZE_INFORMATION: 32,
+ FS_DEVICE_INFORMATION: 8,
+ FS_ATTRIBUTE_INFORMATION: 12,
+ FS_SECTOR_SIZE_INFORMATION: 28,
+ }
+ for info_class, minimum in minimums.items():
+ out = _handle_fs_info(info_class, tmp_path)
+ assert out is not None, f"class {info_class} returned None"
+ assert len(out) >= minimum, (
+ f"FS info class {info_class} returned {len(out)} bytes, "
+ f"expected >= {minimum}"
+ )
+
+ def test_fs_sector_size_is_28_bytes(self, tmp_path):
+ from quicksand_smb._query import FS_SECTOR_SIZE_INFORMATION, _handle_fs_info
+
+ out = _handle_fs_info(FS_SECTOR_SIZE_INFORMATION, tmp_path)
+ assert out is not None
+ assert len(out) == 28
diff --git a/tests/unit/test_mounts.py b/tests/unit/test_mounts.py
index 0ace9a4..b269b48 100644
--- a/tests/unit/test_mounts.py
+++ b/tests/unit/test_mounts.py
@@ -363,12 +363,12 @@ class TestCifsOpts:
def test_cifs_opts_authenticated(self):
"""Test that cifs_opts produces NTLMSSP options when password is set."""
result = MountOptions.cifs_opts("myuser", "mypass")
- assert result == "username=myuser,password=mypass,sec=ntlmssp,vers=3.0"
+ assert result == "username=myuser,password=mypass,sec=ntlmssp,vers=3.0,nosharesock"
def test_cifs_opts_anonymous(self):
"""Test that cifs_opts produces sec=none for empty password."""
result = MountOptions.cifs_opts("guest", "")
- assert result == "username=guest,password=,sec=none,vers=3.0"
+ assert result == "username=guest,password=,sec=none,vers=3.0,nosharesock"
_PATHS_WITH_SPECIAL_CHARS = [