Skip to content

Security hardening: FFI validation, CI script injection fix, Dockerfile improvements - #6

Open
pavanchow wants to merge 1 commit into
NationalSecurityAgency:mainfrom
pavanchow:fix/security-hardening
Open

Security hardening: FFI validation, CI script injection fix, Dockerfile improvements#6
pavanchow wants to merge 1 commit into
NationalSecurityAgency:mainfrom
pavanchow:fix/security-hardening

Conversation

@pavanchow

@pavanchow pavanchow commented Aug 21, 2026

Copy link
Copy Markdown

Summary

This PR addresses three security issues identified during a review of the Foundation repository: unsafe FFI boundary handling in the AES Rust implementations, a shell injection vulnerability in the CI build scripts, and an overly broad file permission change in a Dockerfile.

1. FFI input validation (AES Cipher, InvCipher, KeyExpansion)

The k parameter in all AES FFI entrypoints was unchecked. Invalid values (e.g. k=0, k=999) cause out-of-bounds array access on w[64] in key_expansion and division by zero in i % nk. Since these are extern "C" functions, a panic is undefined behavior per Rust's FFI contract.

Fix: validate k is 128, 192, or 256 before proceeding. Add null pointer checks on all raw pointer arguments.

2. CI script shell injection and quoting

.ci/build-rust-saw-artifacts.sh line 9 used find -exec sh -c "mv '{}' ..." which embeds filenames directly into a shell command string. A filename containing shell metacharacters (e.g. single quotes with command substitution) achieves arbitrary command execution.

All four CI scripts also used unquoted $f in for loops, which breaks on paths containing spaces.

Fix: pass {} as a positional argument (sh -c '...' _ {}), use find -print0 with while read -d '' for safe iteration.

3. Dockerfile chmod scope

cryptol-tools.Dockerfile used chmod a+x /usr/local/bin/* which marks every file in the directory as executable. Narrowed to specific solver binaries.

Files changed

  • algorithms/AES/rust/Cipher/src/lib.rs - k validation + null checks in cipher_ffi, inv_cipher_ffi
  • algorithms/AES/rust/KeyExpansion/src/lib.rs - k validation + null checks in key_expansion_ffi
  • .ci/build-rust-saw-artifacts.sh - shell injection fix + safe quoting
  • .ci/build-rust-ffi.sh - safe quoting
  • .ci/run-saw-python-files.sh - safe quoting
  • .ci/run-top-level-saw-files.sh - safe quoting
  • .github/dockerfiles/cryptol-tools.Dockerfile - narrow chmod scope

…le improvements

1. Validate k parameter in AES FFI entrypoints (Cipher, InvCipher,
   KeyExpansion) to prevent OOB access and panic-across-FFI UB when
   k is not 128/192/256. Add null pointer checks.

2. Fix shell injection in CI scripts: replace find -exec sh -c with
   embedded {} (allows filename-based command injection) with safe
   positional argument passing. Quote all variable expansions.

3. Narrow chmod in cryptol-tools.Dockerfile to specific solver
   binaries instead of chmod a+x /usr/local/bin/*.
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