Skip to content

storage: mount SMB ISO images with on-demand CIFS and hardware AES - #492

Open
dormancygrace wants to merge 7 commits into
codex/remote-http-isofrom
codex/remote-smb-iso
Open

dormancygrace wants to merge 7 commits into
codex/remote-http-isofrom
codex/remote-smb-iso

Conversation

@dormancygrace

@dormancygrace dormancygrace commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Adds read-only smb://server/share/path/image.iso mounting to the main server and the existing Images → From URL flow, without copying the ISO to the SD card. This PR is stacked on #491, which retains #486's browser prefetch implementation.

The Linux CIFS client ships as a module and loads when SMB is first requested. SMB2.1/3 uses NTLMv2 with required signing and supports shares requiring encryption. Credentials pass through private IPC and separate fsconfig values, never command arguments or credential files. The detached mount is read-only/noexec/nodev/nosuid; the ISO is opened beneath it with symlinks disabled. A bounded helper and a single-use splice TCP relay enforce the 10-second open/read deadline and cancellation. Disconnect releases the helper, connection and mount. Reads retain the adaptive 1 MiB RAM window and size/mtime checks.

SG2002 now supplies hardware AES-CMAC signing and full hardware CCM encryption through the Linux Crypto API. CMAC uses hardware subkey derivation and CBC; CCM uses hardware CBC-MAC and CTR. Both share the existing engine with GCM, limit DMA chunks to 4 KiB, and preserve the hardware-AES setting and software fallback. GCM continues to combine hardware CTR with optimized CPU GHASH. Cipher negotiation is unchanged.

CIFS CMAC calculations own their transform/key, allowing signing and verification to run concurrently without a key race. The kernel patch also preserves verification failures through synchronous and compound-response handling: an invalid metadata signature can no longer be overwritten by a successful wire status. SMB2.1 HMAC signing is unchanged. The accompanying NLS cleanup fix releases references after failed mounts.

Measured on SG2002, 100 Mbit/s Ethernet

Matched 64 MiB source and read pattern; hardware disabled for the first three rows:

Mode Go client Direct kernel CIFS
No signing or encryption 10.21–10.32 MiB/s 10.80 MiB/s
Software AES-128-CMAC signing 3.67–3.81 MiB/s 6.15–6.20 MiB/s
Software AES-128-GCM 1.91–1.93 MiB/s 5.18–5.24 MiB/s
Hardware CMAC signing — 9.27–9.60 MiB/s
Hardware GCM — 7.43–7.57 MiB/s
Hardware CCM (CBC-MAC + CTR) — 8.58–8.67 MiB/s

The complete server reader, including cancellation relay and IPC, reaches 8.65–8.72 MiB/s with hardware CMAC, versus about 5.8 MiB/s with software signing (about 50% faster). For encrypted shares it reaches 7.97–8.03 MiB/s with CCM against 6.81–7.04 MiB/s with GCM (about 15% faster).

Software/hardware sessions were alternated, with two sequential rounds each. All full-image SHA-256 checks match. Samba negotiation confirms the intended signing/encryption; DMA counters confirm hardware CMAC use and no DMA in software controls. Raw 64 KiB CMAC measures 131.4 versus 15.0 MiB/s; CCM/GCM decryption measures 61.8 versus 28.9 MiB/s. At 64-byte CMAC messages DMA overhead makes hardware slower than software. Random-read latency varied, so no latency improvement is claimed.

These are source measurements, not USB throughput guarantees. Unsigned mode is benchmark-only; production requires signing/authenticated encryption. Reproduction details and limits are in platform/modules/sg2002-aes/test/README.md.

A three-run CMAC crossover sweep finds the first consistent DMA win at 304 bytes including a new transform/key per message as in CIFS. CIFS now selects CPU CMAC below 320 bytes and the highest-priority provider (normally SG2002 DMA) from 320 bytes upwards. It counts every header vector and payload byte, and selects before key setup so short signatures submit no DMA. Larger messages still work on software when hardware AES is disabled.

The actual production selector passed fragmented-message/tag, length-overflow and provider-boundary tests with and without hardware. Isolated 319-byte signatures submit zero DMA operations; 320-byte signatures submit three. In three matched sessions per implementation, automatic selection reduced AES submissions from 51,374 to 50,258 (about 2.2%); all six full-image checksums match. Median sequential reader throughput is unchanged within measurement noise: 8.72 MiB/s before versus 8.71 MiB/s after. The real SMB suite, including corrupted READ and metadata signatures, passes with automatic selection.

Validation

  • CMAC: RFC 4493 in 32 request modes, 2000 differential cases, AES-128/192/256, invalid keys/state, streaming/final/finup, export/import, virtual/chained scatterlist input, DMA boundaries and four concurrent streams with different keys.
  • A separate RAM-only fault build fails its second completed CBC operation. The failed request cannot emit a tag/export state; an unfailed request continues correctly from its saved CBC chain. Vectors, 300 differential cases and concurrency then pass without further DMA. Production has no fault-injection switch.
  • CCM: RFC 3610, 3000 differential/tamper cases, all tags and nonce lengths, invalid requests, AAD/DMA boundaries, sync/queued requests and concurrent CCM/GCM streams. Existing GCM: 1000 cases, zero failures. CMAC/CCM/GCM regressions repeated after the CMAC change.
  • Real device signed/encrypted SMB suite passes, including READ and QUERY_INFO signature corruption, deadlines, cancellation/reaping, private read-only mounts, bounds, metadata changes, wrong credentials and NLS cleanup. The original CIFS module fails the corrupted-metadata negative control as expected.
  • Native Go tests/vet and real Samba source/service tests with the race detector pass. The strict-signature check is opt-in for NanoKVM's patched kernel.
  • Driver, qualification modules and CIFS cross-build; zero-fuzz kernel patch application matches the tested sources; production Kconfig gate, startup-AES policy and platform build/config checks pass.
  • Earlier stack validation: complete production server cross-build, on-demand CIFS loading, real read-only NBD full-image checksum, UI typecheck/lint/format/build and 339 web tests. The complete PR includes server runtime and web UI changes.

SMB requires the accompanying kernel modules from an OS update; a server-only update on an older kernel reports unavailable CIFS support. No boot-time CIFS service is added.

Review corrections: actionable timeout/server errors; CMAC preload declaration; an optional-signing Samba fixture that verifies the client requirement and signed READ packets. Host race/vet, real Samba source/service tests and the signing negative control pass, as do web type/lint/error/lifecycle/i18n tests and zero-fuzz CIFS patch application.

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Build outputs

Compared with the build of main at 58bdc0d; codex/remote-http-iso is at 14f72ee, so outputs changed since then are listed too.

26 changed, 155 added, 144 removed of 581 outputs.

directory files
changed . Image
changed boot boot/alpha.sha256
boot/beta.sha256
boot/detect.sha256
boot/fit-template.sd
boot/fit.layout
boot/lite.sha256
boot/pcie.sha256
changed boot-fit boot-fit/alpha.sd
boot-fit/beta.sd
boot-fit/detect.sd
boot-fit/lite.sd
boot-fit/pcie.sd
changed lib lib/modules/7.3.0-nanokvm-os-r3/extra/sg2002_aes_probe.ko
lib/modules/7.3.0-nanokvm-os-r3/kernel/crypto/aes.ko
lib/modules/7.3.0-nanokvm-os-r3/kernel/lib/crypto/libaes.ko
lib/modules/7.3.0-nanokvm-os-r3/modules.alias
lib/modules/7.3.0-nanokvm-os-r3/modules.alias.bin
lib/modules/7.3.0-nanokvm-os-r3/modules.dep
lib/modules/7.3.0-nanokvm-os-r3/modules.dep.bin
lib/modules/7.3.0-nanokvm-os-r3/modules.order
lib/modules/7.3.0-nanokvm-os-r3/modules.softdep
lib/modules/7.3.0-nanokvm-os-r3/modules.symbols
lib/modules/7.3.0-nanokvm-os-r3/modules.symbols.bin
changed server server/NanoKVM-Server
changed web web/index.html
added lib lib/modules/7.3.0-nanokvm-os-r3/kernel/crypto/ccm.ko
lib/modules/7.3.0-nanokvm-os-r3/kernel/crypto/cmac.ko
lib/modules/7.3.0-nanokvm-os-r3/kernel/fs/netfs/netfs.ko
lib/modules/7.3.0-nanokvm-os-r3/kernel/fs/nls/nls_ucs2_utils.ko
lib/modules/7.3.0-nanokvm-os-r3/kernel/fs/nls/nls_utf8.ko
lib/modules/7.3.0-nanokvm-os-r3/kernel/fs/smb/client/cifs.ko
lib/modules/7.3.0-nanokvm-os-r3/kernel/fs/smb/common/cifs_md4.ko
lib/modules/7.3.0-nanokvm-os-r3/kernel/fs/smb/common/smb_compress.ko
lib/modules/7.3.0-nanokvm-os-r3/kernel/lib/crypto/libarc4.ko
lib/modules/7.3.0-nanokvm-os-r3/kernel/lib/crypto/libmd5.ko
lib/modules/7.3.0-nanokvm-os-r3/kernel/lib/crypto/libsha512.ko
added web 144 files
removed web 144 files
Hashes: outputs-sha256 artifact of this run.

@dormancygrace dormancygrace left a comment •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The security-relevant parts hold up.

  • Credentials: they travel over a socketpair and become separate fsconfig strings. They never appear in argv, the environment, a file or an API response, and an empty username is rejected.
  • No option injection: nothing goes through a comma-separated mount string. The path parser rejects .., \, : and control characters, and the file is opened with openat2(RESOLVE_BENEATH|RESOLVE_NO_SYMLINKS) on a read-only, nosuid, nodev, noexec detached mount.
  • Protocol: SMB1 is not built, and sec=ntlmsspi requires signing.
  • 0052 and 0053: both match v7.3, and the -EBADMSG handling is a real fix.

go vet and go test for ./remotemedia ./service/storage pass on the host.

Two general notes:

  • The description says this follow-up "changes no server runtime or web code", but against #491 it adds the SMB server and web code. Which commit does that sentence refer to, and was the full SMB path run on the device at this head?
  • #484 and #501/#503 also claim kernel patch numbers 0052/0053.

Comment thread server/remotemedia/smb.go
Comment thread web/src/pages/desktop/menu/image/remote.tsx Outdated
Comment thread platform/kernel/0053-cifs-crypto-api-cmac.patch
Comment thread tests/fixtures/remote-smb/smb.conf Outdated

@dormancygrace dormancygrace left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed source validation, private helper/relay lifetime, detached read-only mounts, required signing, CMAC/CCM request handling and CIFS signature-error propagation. Fixed deadline/UI diagnostics and added independent client signing-policy coverage in 143bad7, incorporating the HTTP and browser read fixes from #491/#486. Host Go race/vet, the real Samba source/service suite, signing negative control, web tests/typecheck/lint and zero-fuzz Linux 7.3 CIFS patch application pass. SG2002 crypto and patched-kernel signature-corruption qualification were not rerun here. Security regression coverage and inherited runtime fixes are substantive; this PR remains open.

This branch has not been deployed

No deployments
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