Skip to content

Add userspace pcbc(fcrypt) fallback and nscd invalidation for AF_ALG-blocked environments#70

Open
0oAstro wants to merge 1 commit into
V4bel:masterfrom
0oAstro:fix/afalg-bypass-nscd-fallback
Open

Add userspace pcbc(fcrypt) fallback and nscd invalidation for AF_ALG-blocked environments#70
0oAstro wants to merge 1 commit into
V4bel:masterfrom
0oAstro:fix/afalg-bypass-nscd-fallback

Conversation

@0oAstro

@0oAstro 0oAstro commented May 22, 2026

Copy link
Copy Markdown

Summary

Three fixes for Dirty Frag RxRPC variant when AF_ALG is blacklisted or nscd caches stale passwd entries.

Changes

1. Userspace pcbc(fcrypt) fallback

The cksum computation (compute_csum_iv, compute_cksum) needs socket(AF_ALG) + bind("pcbc(fcrypt)"). Systems with af_alg blacklisted fail here.

Added fcrypt_user_encrypt() and pcbc_fcrypt_encrypt_userspace() so both functions fall back to pure userspace crypto when AF_ALG is unavailable.

The encrypt round argument order is SWAPPED vs fcrypt_user_decrypt — matching the kernel F_ENCRYPT(R, L, k) convention. A naive copy of decrypt produces wrong output.

2. nscd invalidation before STAGE 4

On nscd-active systems (Ubuntu 24.04 default), PAM reads cached passwd, sees original root:x:... line, defers to shadow — blank password fails despite corrupted page cache and nullok.

Added nscd --invalidate passwd before su PTY, forcing PAM to read the actual corrupted file.

3. Forward declaration

Added forward decl for pcbc_fcrypt_encrypt_userspace() to fix implicit declaration warning.

Testing

  • compute_csum_iv / compute_cksum produce bit-exact output vs kernel AF_ALG pcbc(fcrypt) (verified via test harness)
  • Successfully exploited Ubuntu 24.04 with af_alg blacklisted AND nscd active
  • Compiles cleanly: gcc -O0 -Wall -o exp exp.c -lutil

Three fixes for AF_ALG-blocked and nscd-active environments:

1. Add fcrypt_user_encrypt() — userspace encrypt counterpart to
   fcrypt_user_decrypt(), with corrected round argument order.
   Kernel's F_ENCRYPT(R,L,k) swaps args vs naive port of decrypt.

2. Add pcbc_fcrypt_encrypt_userspace() — full PCBC mode encrypt
   using userspace fcrypt, so compute_csum_iv() and compute_cksum()
   fall back when AF_ALG is unavailable (blacklisted/blocked).

3. Add nscd passwd cache invalidation before STAGE 4 su PTY.
   Without this, PAM reads stale nscd entries and su fails despite
   corrupted /etc/passwd page cache and nullok.
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