X41 D-Sec GmbH Security Advisory: X41-2018-001

Multiple Vulnerabilities in Yubico Piv

Overview

Summary and Impact

A buffer overflow and an out of bounds memory read were identified in the yubico-piv-tool-1.5.0, these can be triggered by a malicious token.

X41 did not perform a full test or audit of the software.

Product Description

YubiKey 4, YubiKey 4 Nano, YubiKey 4C, YubiKey 4C Nano, and YubiKey NEO provide Smart Card functionality based on the Personal Identity Verification (PIV) interface specified in NIST SP 800-73, “Cryptographic Algorithms and Key Sizes for PIV.”

Out of Bounds Write via Malicious APDU

Summary and Impact

File lib/ykpiv.c contains the following code in function ykpiv_transfer_data()

    if(*out_len + recv_len - 2 > max_out) {                                     
      fprintf(stderr, "Output buffer to small, wanted to write %lu, max was %lu.", *out_len + recv_len - 2, max_out);
    }                                                                           
    if(out_data) {                                                              
      memcpy(out_data, data, recv_len - 2);                                     
      out_data += recv_len - 2;                                                 
      *out_len += recv_len - 2;                                                 
    }   

It is clearly checked whether the buffer is big enough to hold the data copied using memcpy(), but no error handling happens to avoid the memcpy() in such cases. This code path can be triggered with malicious data coming from a smartcard.

Workarounds

None

Out of Bounds Read via malicious APDU

Summary and Impact

File lib/ykpiv.c contains the following code in function _ykpiv_fetch_object()

if(sw == SW_SUCCESS) {
  size_t outlen;
  int offs = _ykpiv_get_length(data + 1, &outlen);
  if(offs == 0) {
    return YKPIV_SIZE_ERROR;
  }
  memmove(data, data + 1 + offs, outlen);
  *len = outlen;
  return YKPIV_OK;
} else {
  return YKPIV_GENERIC_ERROR;
}

In the end, a memmove() occurs with a length retrieved from APDU data. This length is not checked if it is outside of the APDU data retrieved. Therefore the memmove() could copy bytes behind the allocated data buffer into this buffer.

Workarounds

None

Timeline