Details
Description
There is a file descriptor leak in Env::NewRWFile() on an error path when encryption-at-rest is enabled.
In the code below, if ReadEncryptionHeader() or WriteEncryptionHeader() failed, the descriptor of the file opened by DoOpen() would be leaked.
RETURN_NOT_OK(DoOpen(fname, opts.mode, &fd)); EncryptionHeader eh; if (encrypt) { DCHECK(encryption_key_); if (size >= kEncryptionHeaderSize) { RETURN_NOT_OK(ReadEncryptionHeader(fd, fname, *encryption_key_, &eh)); } else { RETURN_NOT_OK(GenerateHeader(&eh)); RETURN_NOT_OK(WriteEncryptionHeader(fd, fname, *encryption_key_, eh)); } } result->reset(new PosixRWFile(fname, fd, opts.sync_on_close, encrypt, eh));
It's been evidenced in the wild when creating the metadata file for a tablet during tablet copying failed with the error like below:
Runtime error: Couldn't create tablet metadata: Failed to write tablet metadata d199a872b03848d695f067ed5c694835: Failed to initialize encryption: error:0607B083:digital envelope routines:EVP_CipherInit_ex:no cipher set:crypto/evp/evp_enc.c:170