Skip to content

smb3-seal: byte-swap SessionId for the wire in smb3_encrypt_pdu() - #478

Merged
sahlberg merged 1 commit into
sahlberg:masterfrom
watermark-hd:fix-sessionid-endian-in-transform-header
Aug 28, 2026
Merged

smb3-seal: byte-swap SessionId for the wire in smb3_encrypt_pdu()#478
sahlberg merged 1 commit into
sahlberg:masterfrom
watermark-hd:fix-sessionid-endian-in-transform-header

Conversation

@watermark-hd

Copy link
Copy Markdown
Contributor

Fixes #477.

Per your feedback there -- switched from the scoped-variable version to a direct pointer-cast assignment:

*(uint64_t *)(void *)&pdu->crypt[44] = htole64(smb2->session_id);

Re-tested on the same PPC hardware (Tiger iBook G4) with this exact form: smb2_set_seal(ctx, 1) connects successfully against both macOS's and Windows 11's standard SMB3 sharing.

The SMB2_TRANSFORM_HEADER's OriginalMessageSize and
EncryptionAlgorithm fields are explicitly converted with htole32/
htole16 before being written, but SessionId was copied via a raw
memcpy of the host-order value. A no-op bug on little-endian hosts,
where host order already equals wire order; on big-endian (PPC) it
produces a byte-reversed SessionId in every encrypted PDU, which a
server has no reason to accept -- confirmed on a PPC Tiger iBook via
packet capture, where smb2_set_seal(ctx, 1) got rejected identically
by both macOS's and Windows 11's standard SMB3 sharing right after
the first TRANSFORM_HEADER-wrapped PDU.

Fixes sahlberg#477.
watermark-hd added a commit to watermark-hd/ppc-mac-modernization that referenced this pull request Aug 28, 2026
sahlberg confirmed the bug on Issue #477 and asked for a PR with a
different style (a direct pointer-cast assignment instead of a scoped
local variable + memcpy). Re-verified on real hardware with the new
form against both macOS's and Windows 11's SMB3 sharing. Sent as
sahlberg/libsmb2#478, and updated the PPCPorts patch (#236) to match.
watermark-hd added a commit to watermark-hd/powerpc-ports that referenced this pull request Aug 28, 2026
@sahlberg
sahlberg merged commit c8a2eeb into sahlberg:master Aug 28, 2026
15 checks passed
@sahlberg

Copy link
Copy Markdown
Owner

Awesome, thanks. Merged!

I will set up a Linux PPC environment under qemu. I should be able to reproduce the issue there and then I can try to wire it into my test environmet.

Thanks!

@watermark-hd
watermark-hd deleted the fix-sessionid-endian-in-transform-header branch August 28, 2026 02:40
@watermark-hd
watermark-hd restored the fix-sessionid-endian-in-transform-header branch August 28, 2026 02:40
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.

SMB3 encryption (seal) fails on big-endian hosts: SessionId not byte-swapped in transform header

2 participants