opendkim: heap-allocate keydata/tmpdata in dkimf_add_signrequest() (fixes #411) - #431
Merged
thegushi merged 1 commit intoJul 22, 2026
Conversation
Fixes issue trusteddomainproject#411. dkimf_add_signrequest() stack-allocated two MAXBUFRSZ+1 (65,537-byte) locals, keydata and tmpdata, totaling over 128 KB. Harmless on Linux (8 MB default pthread stack), but macOS ARM64 libmilter callback threads default to a 512 KB stack; combined with libmilter's own frames and the mlfi_eoh() -> dkimf_apply_signtable() call chain, an active KeyTable could overrun the stack during ordinary sign-mode operation. Both buffers are now malloc'd, with free() added on every return path (including the two new allocation-failure paths). No behavior change. Verified with a clang -Wall build (0 warnings/errors touching this function) and `make check` (207/207 passing, including t-sign-rs-tables and t-sign-rs-lua, the paths the issue calls out as exercising this code).
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.
Summary
Fixes #411.
dkimf_add_signrequest()stack-allocated twoMAXBUFRSZ + 1(65,537-byte) locals,keydataandtmpdata, totaling over 128 KB.mlfi_eoh()→dkimf_apply_signtable()→dkimf_add_signrequest()call chain, an active KeyTable could overrun the stack (SIGBUS,___chkstk_darwinin a crash trace) during completely ordinary sign-mode operation.Both buffers are now
malloc()'d, withfree()added on every return path (including the two new allocation-failure paths this introduces). No behavior change otherwise —sizeof keydata/sizeof tmpdatareferences were all converted to explicitMAXBUFRSZ/MAXBUFRSZ + 1since those would otherwise silently shrink tosizeof(char *)once the locals become pointers.The smaller locals in the same function (
domain,selector,signalgstr,err; ~3.3 KB total) are unchanged — they're not part of the reported overflow risk.Test plan
CC=clang ./configure --enable-lua CFLAGS="-g -O0 -Wall -Wno-pointer-sign"+make: 0 errors/warnings touching this function.make check: 207/207 passing, includingt-sign-rs-tablesandt-sign-rs-lua— the two paths the issue calls out as exercisingdkimf_add_signrequest()(viadkimf_apply_signtable()and the Luadkimf_xs_signfor()hook, respectively).build-test-macosGitHub Actions job (macos-latest,make check) should exercise this on the next push/PR run.