RSA-PSS verification copies a full digest from an unchecked short opaque MPI
Testing, NormalPublic

Assigned To
Authored By
werner
Tue, Aug 4, 5:05 PM
Subscribers

Description

RSA-PSS verification copies a full digest from an unchecked short opaque MPI

When RSA-PSS verification is told that the message is already hashed, it obtains an opaque MPI pointer but does not compare the MPI's bit length with the selected digest length. It unconditionally copies hlen bytes. A caller-supplied short opaque value therefore causes an out-of-bounds read before signature verification fails or continues with adjacent bytes.

Vulnerable code

In cipher/rsa-common.c, function _gcry_rsa_pss_verify:

if (!hashed_already)
  {
    _gcry_md_write (hd, p, (input_nbits+7)/8);
    digest = _gcry_md_read (hd, 0);
    memcpy (mhash, digest, hlen);
    _gcry_md_reset (hd);
  }
else
  memcpy (mhash, p, hlen);

Why it matters

The ASan reproducer selected SHA-512 and supplied a one-byte opaque hash; verification performed a 64-byte read past that allocation. An exact input-length check made the same case return an error. The caller must reach the low-level verification path with hashed_already and malformed MPI input, so the demonstrated impact is a reliable memory-safety violation and likely denial of service, not proven disclosure.

Proposed fix

For prehashed input, require input_nbits to represent exactly hlen bytes and reject non-byte-aligned or otherwise noncanonical lengths before memcpy. Keep the ordinary unhashed-message path unchanged. Add ASan tests for zero-length, one-byte, hlen-minus-one, exact, and hlen-plus-one opaque MPIs for every supported PSS digest size, plus a valid signature regression.

Related Objects

Event Timeline

werner triaged this task as Normal priority.Tue, Aug 4, 5:05 PM
werner created this task.
werner created this object with visibility "Public (No Login Required)".
werner created this object with edit policy "Contributor (Project)".
gniibe changed the task status from Open to Testing.Fri, Aug 28, 3:55 AM
gniibe shifted this object from the Restricted Space space to the S1 Public space.
gniibe mentioned this in Unknown Object (Maniphest Task).Mon, Aug 31, 2:58 AM