Skip to content

Cgo wrapper hardening: bounds, validation, missing stubs - #39

Open
JeremiahM37 wants to merge 4 commits into
wolfSSL:masterfrom
JeremiahM37:fenrir
Open

JeremiahM37 wants to merge 4 commits into
wolfSSL:masterfrom
JeremiahM37:fenrir

Conversation

@JeremiahM37

Copy link
Copy Markdown
Contributor

Fixes F-3021, F-1866, F-2546, F-1872, F-1875, F-2550, F-2553, F-2551, F-3023

Summary:

  • ChaCha20Poly1305 appended-tag encrypt: size the working buffer to exactly len(inPlain)+tag so oversized caller buffers don't leave garbage between cipher and tag.
  • Add NO_HMAC and NO_PWDBASED cgo stubs so builds without HMAC/HKDF/PBKDF2 compile.
  • Reject sizes >math.MaxInt32 before the C.int cast in WolfSSL_read/write, curve25519 make_pub/make_priv, BIO_new_mem_buf, and X509 buffer wrappers (BIO can wrap to -1, OpenSSL's strlen sentinel).
  • Reject iter <= 0 in Wc_PBKDF2 and require exactly CURVE25519_KEYSIZE on curve25519 export/shared_secret outputs.

@JeremiahM37 JeremiahM37 self-assigned this May 8, 2026
@JeremiahM37
JeremiahM37 force-pushed the fenrir branch 2 times, most recently from a457752 to 5a243d5 Compare May 11, 2026 06:14
@JeremiahM37
JeremiahM37 marked this pull request as ready for review May 11, 2026 06:20
@JeremiahM37 JeremiahM37 assigned lealem47 and unassigned JeremiahM37 May 11, 2026

@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 #39

Scan targets checked: go-wolfssl-bugs, go-wolfssl-src

No new issues found in the changed files. ✅

Copilot AI balanced review requested due to automatic review settings November 4, 2026 00:49

Copilot AI 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.

🟡 Changes recommended

HMAC-disabled builds still fail to compile or link because the PBKDF2 stub is skipped when NO_HMAC is defined without NO_PWDBASED, leaving wc_PBKDF2_Unlocked calling a missing function.

1 open issue
What changed in this PR

This PR hardens the Go cgo wrappers around wolfSSL by validating sizes before C conversions, correcting appended-tag buffer handling, and adding disabled-feature stubs.

Changes:

  • Add bounds checks for TLS I/O, X509/BIO buffers, Curve25519 buffers, and PBKDF2 arguments.
  • Correct ChaCha20-Poly1305 ciphertext/tag placement and clarify AES-GCM buffer sizing.
  • Add fallback stubs for disabled HMAC, HKDF, and password-based cryptography.
File Description
x509.go Guard certificate, public-key, and BIO sizes before C integer conversions.
ssl.go Reject oversized TLS read/write requests.
hmac.go Add disabled-feature HMAC and HKDF stubs.
curve25519.go Validate buffer sizes and pin output lengths to 32 bytes.
chacha_poly.go Place the appended tag directly after ciphertext in oversized buffers.
aes.go Add a PBKDF2 stub and argument checks; clarify AES-GCM buffer sizing.

Review effort: Balanced

Comment thread aes.go
// return -174;
// }
// #endif
// #ifdef NO_PWDBASED
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