Skip to content

Read secret files through unbuffered streams - #1365

Open
ejohnstown wants to merge 1 commit into
wolfSSL:masterfrom
ejohnstown:stdio-buffers
Open

ejohnstown wants to merge 1 commit into
wolfSSL:masterfrom
ejohnstown:stdio-buffers

Conversation

@ejohnstown

Copy link
Copy Markdown
Contributor

Private keys and /etc/shadow are read with stdio buffering off, so the
secrets are not left in a libc FILE buffer that fclose frees unwiped.

  • port.h: add WFSETNOBUF, a no-op on non-stdio ports
  • wolfsshd: wolfSSHD_OpenSecretFile for host keys and shadow, with
    test_configuration coverage

Issue: F-14689, F-14690

ReadFileIntoBuffer and the wolfsshd host-key and /etc/shadow readers
turn off stdio buffering right after open, so those secrets are read
straight into wolfSSH's own buffers instead of being staged in a libc
FILE buffer that fclose frees without wiping. Public-key lists stay
buffered.

- port.h: add WFSETNOBUF, setvbuf(_IONBF) for stdio ports, a no-op
  elsewhere
- wolfsshd: add wolfSSHD_OpenSecretFile, the unbuffered secure open
- test_configuration: the secret open reads no further than asked,
  the secure open reads ahead

Issue: F-14689, F-14690
Copilot AI balanced review requested due to automatic review settings November 2, 2026 18:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the secret-file buffering changes.

No open issues 🎉

What changed in this PR

This PR disables stdio buffering when wolfSSH reads secret files, reducing the risk of leaving secret data in libc buffers freed without wiping.

Changes:

  • Adds WFSETNOBUF, with a no-op fallback for non-stdio ports.
  • Uses unbuffered streams for library file loading, daemon host private keys, and /etc/shadow.
  • Adds tests verifying that secret streams avoid read-ahead while public-file streams retain buffering.
File Description
wolfssh/​port.h Adds the portable WFSETNOBUF macro.
src/​ssh.c Disables buffering before reading files into memory.
apps/​wolfsshd/​wolfsshd.c Routes host private keys through the secret-file opener.
apps/​wolfsshd/​test/​test_configuration.c Tests secret and public stream read-ahead behavior.
apps/​wolfsshd/​auth.h Declares the secret-file opening helper.
apps/​wolfsshd/​auth.c Implements the helper and uses it for shadow-file reads.

Review effort: Balanced

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #1365

Scan targets checked: wolfssh-src, wolfssh-bugs
Not reviewed (no scan target covers them): apps/wolfsshd/auth.h
Coverage: 4 of 5 in-scope changed file(s) opened by the reviewer; not opened: apps/wolfsshd/test/test_configuration.c

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

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.

4 participants