Skip to content

Require librnp 0.18.1 (CVE-2025-13470), fix use-after-free, PHP 8.2-8.5 CI#14

Merged
ronaldtse merged 7 commits into
mainfrom
rnp-0.18.1-update
Jul 18, 2026
Merged

Require librnp 0.18.1 (CVE-2025-13470), fix use-after-free, PHP 8.2-8.5 CI#14
ronaldtse merged 7 commits into
mainfrom
rnp-0.18.1-update

Conversation

@ronaldtse

@ronaldtse ronaldtse commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Brings php-rnp up to date with the latest librnp release 0.18.1 (security release fixing CVE-2025-13470) and rnp's main, makes 0.18.1 the enforced minimum, and fixes a real memory-corruption bug exposed by testing against 0.18.x.

Bug fixes

  • Use-after-free in the FFI password callback (rnp.c): ZVAL_NEW_REF(&args[2], &passwordval) moves the zval (PHP 8.x uses ZVAL_COPY_VALUE, no addref), so the later zval_ptr_dtor(&passwordval) double-freed the string once the PHP callback reassigned $password. librnp 0.18's keygen/protect path invokes the password provider in more contexts ("protect"/"add subkey"), turning this latent heap corruption into a reliable zend_mm_heap corrupted crash (test 007). Fixed by dropping the extra dtor + an IS_STRING guard on read-back; verified crash-free under GuardMalloc. A plain-C reproducer confirmed librnp itself is not at fault.
  • 64-bit rnp_key_valid_till selection: switched the preprocessor selection to the documented, always-defined SIZEOF_ZEND_LONG >= 8 form (strictly more portable; no behavior change on 64-bit PHP >= 8.0).
  • Test expectations (006, 016): since Allow zero-length input in rnp_input_from_memory() rnp#2246 (v0.18.0) rnp_input_from_memory() accepts zero-length input — rnp_dump_packets('') and rnp_import_keys('') now return empty results instead of false. Expectations updated with comments pointing at the upstream change.

Requirements & CI

  • config.m4: PKG_CHECK_MODULES([LIBRNP], [librnp >= 0.18.1]) — builds against CVE-affected librnp are now rejected at configure time.
  • CI (test.yml): librnp matrix → v0.18.1 + main (matching the new minimum); PHP matrix 8.0–8.2 → 8.2/8.3/8.4/8.5; actions/checkout@v4; shivammathur/setup-php@v2.
  • README: librnp 0.18.1+ (CVE-2025-13470) and PHP 8.2+ requirements.

Verification (local, PHP 8.5.8 NTS, macOS arm64)

  • phpize && ./configure && make: clean, zero compiler warnings from rnp.c; rnp_arginfo.h needed no regeneration for 8.5
  • Against librnp v0.18.1: 18/18 phpt PASS; against librnp main (99c03f5): 18/18 PASS (loaded dylib verified via DYLD_PRINT_LIBRARIES)

Notes for maintainers

  • package.xml left at 0.2.0 (release action) — consider a version bump and PHP min 8.2 there at release time.
  • config.w32 (Windows) has no version constraint; pkg-config isn't used there.
  • New-in-0.18.0 FFI (rnp_signature_error_count/at, key certification API) not yet wrapped — potential follow-up.

Related PRs

The fixes here overlap with older open PRs: #13 (segfault in php_rnp_password_callback — same use-after-free fixed here with a GuardMalloc-verified, slightly different fix) and #11 (zero-length input handling for librnp 0.18 — also covered here). This PR likely supersedes both.

ZVAL_NEW_REF moves the zval into the new reference (ZVAL_COPY_VALUE
semantics) without increasing the refcount, so destroying passwordval
after the call operated on a dangling pointer as soon as the PHP
callback reassigned the by-ref $password argument. librnp 0.18
requests passwords during key generation/protection, which made this
reliably crash with "zend_mm_heap corrupted".

Also make sure the callback left a string in the by-ref argument
before reading it back.
SIZEOF_ZEND_LONG is the documented constant that is always defined by
Zend, making the 64-bit branch selection explicit and portable.
0.18.1 is the security baseline: it fixes CVE-2025-13470 (PKESK
session keys generated without cryptographically random values).
Since rnpgp/rnp#2246 (v0.18.0) rnp_input_from_memory() accepts
zero-length input, so rnp_dump_packets('') now returns the
":empty input" dump and rnp_import_keys('') returns an empty key
list instead of failing.
- rnp matrix: v0.16.2 -> v0.18.1 (the new minimum), keep main
- PHP matrix: 8.0/8.1/8.2 -> 8.2/8.3/8.4/8.5
- actions/checkout v3 -> v4
- shivammathur/setup-php 2.22.0 -> v2
Mention CVE-2025-13470 as the reason for the 0.18.1 baseline.
ubuntu-latest (24.04) no longer ships bzip2/zlib development files,
which made the rnp cmake configure step fail (Could NOT find BZip2).
@ronaldtse
ronaldtse merged commit c4d4192 into main Jul 18, 2026
12 checks passed
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