wolfsshd: fix uninitialized fileNames[] deref in HandleInclude#1029
Open
yosuke-wolfssl wants to merge 1 commit into
Open
wolfsshd: fix uninitialized fileNames[] deref in HandleInclude#1029yosuke-wolfssl wants to merge 1 commit into
yosuke-wolfssl wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens wolfsshd’s Include-directory wildcard handling to prevent an uninitialized-pointer dereference when the directory contents change between the “count” and “fill” readdir() passes in HandleInclude().
Changes:
- Track the number of entries actually populated during the second
readdir()pass (fileFilled) and bound the processing loop to that value. - Zero-initialize the
fileNamespointer array after allocation as defense-in-depth.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ce8a3af to
06215f8
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1029
Scan targets checked: none
Failed targets: wolfssh-bugs, wolfssh-src
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a TOCTOU-induced uninitialized-pointer dereference in
HandleInclude(
apps/wolfsshd/configuration.c) that can crashwolfsshdwith a SIGSEGV.HandleIncludewalks anIncludedirectory using two separatereaddirpasses split by
WREWINDDIR:fileCount.fileNamesis allocated withWMALLOC(fileCount * sizeof(char*))— withoutzero-initialization.
i < fileCount && (dir = WREADDIR(...)) != NULL, so it stops early ifreaddirreturnsNULL.fileCount, callingWSTRLEN(fileNames[i])/WSNPRINTF(...)on every slot.If the directory shrinks between the two passes (a local user removing files
from a writable
Includedirectory, e.g. a group-writable/etc/ssh/sshd_config.d/), the second pass fills fewer slots thanfileCount.The tail slots
[fileFilled .. fileCount-1]remain uninitialized, and theprocessing loop dereferences those garbage pointers, crashing the daemon at
start/restart. No SSH authentication is required to trigger it.
Fix
slots populated by the second pass (
fileFilled = i;) and iteratefor (i = 0; i < fileFilled; i++)instead ofi < fileCount. This is thefix that closes the uninitialized read.
WMEMSET(fileNames, 0, ...))as defense-in-depth, so any slot not reached by the second pass is
NULLrather than garbage and the code fails safe against future changes.
The opposite direction (more files appearing in pass 2) was already safe — the
i < fileCountguard stops the second pass at the allocated size.Testing
./configure --enable-sshd && make— clean build.apps/wolfsshd/test/test_configuration— allInclude/ wildcard cases pass,including
Include sshd_config.d/*.conf, which exercises this exact two-passpath and confirms no regression in the normal (
fileFilled == fileCount)case.