Skip to content

smbserver: reply with SMB2 ERROR response on failed requests - #2380

Open
cielavenir wants to merge 1 commit into
fortra:masterfrom
cielavenir:fixsmb2error
Open

cielavenir wants to merge 1 commit into
fortra:masterfrom
cielavenir:fixsmb2error

Conversation

@cielavenir

@cielavenir cielavenir commented Nov 17, 2026 •

Copy link
Copy Markdown

Problem

smbserver answers failed SMB2 requests with the command's own (mostly empty) response structure
instead of an SMB2 ERROR Response. For example:

  • SMB2 CREATE for a missing file returns an SMB2Create_Response body with
    STATUS_OBJECT_NAME_NOT_FOUND.
  • SMB2 TREE_CONNECT to an unknown share returns an SMB2TreeConnect_Response body with
    STATUS_OBJECT_PATH_NOT_FOUND.

[MS-SMB2] 3.3.4.4 requires failed requests to be answered with an SMB2 ERROR Response
(StructureSize = 9). Strict clients reject the reply. For example, libsmb2
fails with Unexpected size of Error reply. Expected 9, got 8 (or Failed to decrypt pdu on newer
dialects) and drops the connection, so a plain stat of a missing file breaks the whole session
instead of returning ENOENT.

Fix

  • In SMBSERVER.processRequest, when building an SMB2 response whose status is not
    STATUS_SUCCESS, STATUS_MORE_PROCESSING_REQUIRED or STATUS_BUFFER_OVERFLOW (the statuses
    that carry the command's own response body), send SMB2Error() as the body.
  • smb2TreeConnect builds its own packet, so it gets the same treatment for an unknown share.

Testing

  • tests/SMB_RPC/test_smbserver.py: 45 passed, 3 skipped.

  • A libsmb2 6.x client against SimpleSMBServer with SMB2 enabled:

    Request Before After
    stat of a missing file -1, connection dropped -ENOENT, connection stays up
    stat of a file in a missing directory -1, connection dropped -ENOENT
    stat of an existing file or directory OK OK
    tree connect to an unknown share unparseable reply clean STATUS_OBJECT_PATH_NOT_FOUND

🤖 Generated with Claude Code

[MS-SMB2] 3.3.4.4 requires failed requests to be answered with an
SMB2 ERROR Response (StructureSize 9). The server sent the command's
own empty response structure instead (e.g. SMB2 CREATE response with
STATUS_OBJECT_NAME_NOT_FOUND, TREE_CONNECT response for an unknown
share). Strict clients like libsmb2 fail to parse it ("Unexpected
size of Error reply") and drop the connection.

STATUS_MORE_PROCESSING_REQUIRED and STATUS_BUFFER_OVERFLOW keep the
command response body as the spec allows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cielavenir
cielavenir marked this pull request as ready for review November 17, 2026 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant