Skip to content

OpenSSL backend: incorrect RAND_load_file() return value check #18986

Closed

Description

@botovq

Description

OpenSSL documents the return value of RAND_load_file() as

RETURN VALUES
     RAND_load_file() returns the number of bytes read or -1 on error.

(from code inspection this happens to be correct).

The error check in php_openssl_load_rand_file() will however interpret an error as success. People relying on seeding the PRNG might therefore proceed without having added any entropy to the pool. These days the RAND(7) of OpenSSL is claimed to be robust enough without explicit seeding, so there should be no security impact to this, but it would probably still be good to fix it since it goes against expectations:

if (file == NULL || !RAND_load_file(file, -1)) {
if (RAND_status() == 0) {
php_openssl_store_errors();
php_error_docref(NULL, E_WARNING, "Unable to load random state; not enough random data!");
return FAILURE;
}
return FAILURE;
}
*seeded = 1;
return SUCCESS;

PHP Version

PHP 8.4

Operating System

No response

Activity

  1. ndossche commented on Jun 30, 2025

    @ndossche
    Member

    You appear to be correct, as that's also what my static analyzer inferred (albeit on an older openssl version) (https://raw.githubusercontent.com/csl-ugent/ESSS/refs/heads/main/evaluation/my-openssl-output, CTRL+F for RAND_load_file).
    Feel free to open a PR.

  2. ndossche commented on Jun 30, 2025

    @ndossche
    Member

    Same issue for RAND_write_file btw

  3. added a commit that references this issue on Jul 2, 2025
    01a4aa5
  4. added 2 commits that reference this issue on Jul 15, 2025
    a8086be
    f938f35
  5. added a commit that references this issue on Jul 15, 2025
    1089896
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions