aws-sdk-cpp icon indicating copy to clipboard operation
aws-sdk-cpp copied to clipboard

Segmentation fault in S3EncryptionClient.PutObject()

Open claw-j opened this issue 8 years ago • 6 comments

Hello, I encountered a segmentation fault while i was running the example code in https://aws.amazon.com/blogs/developer/amazon-s3-encryption-client-is-now-available-for-c/

My code is as the following: https://pastebin.com/jad8QdKf Where the constants KEY is the KMS key for the S3 bucket, BUCKET is the bucket name, FILE_NAME is the path to local file.

Thank you for your help! ;)

What platform/OS are you using?

Amazon Linux 2 LTS Candidate AMI 2017.12.0.20180115 x86_64 HVM GP2

What compiler are you using? what version?

gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2)

What's your CMake arguments?

cmake -Daws-sdk-cpp_DIR=~/sdk_build ../s3encryption/

Can you provide a TRACE level log? (sanitize any sensitive information)

Here's the debug log from GNU gdb (GDB) Red Hat Enterprise Linux 8.0.1-30.amzn2.0.1 https://pastebin.com/WpnFhF2x Thread 1 "s3_encrypt_clie" received signal SIGSEGV, Segmentation fault. 0x00007ffff5f24ca6 in EVP_EncryptFinal_ex (ctx=0x67eba0, out=0x67f2e0 "0\352g", outl=0x7fffffffc4fc) at evp_enc.c:456 456 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) { (gdb) bt #0 0x00007ffff5f24ca6 in EVP_EncryptFinal_ex (ctx=0x67eba0, out=0x67f2e0 "0\352g", outl=0x7fffffffc4fc) at evp_enc.c:456 #1 0x00007ffff6b690ba in Aws::Utils::Crypto::OpenSSLCipher::FinalizeEncryption() () from /home/ec2-user/sdk_build/aws-cpp-sdk-core/libaws-cpp-sdk-core.so #2 0x00007ffff6b69bdc in Aws::Utils::Crypto::AES_GCM_Cipher_OpenSSL::FinalizeEncryption() () from /home/ec2-user/sdk_build/aws-cpp-sdk-core/libaws-cpp-sdk-core.so #3 0x00007ffff7bb0bd0 in Aws::S3Encryption::Modules::AES_GCM_AppendedTag::FinalizeEncryption() () from /home/ec2-user/sdk_build/aws-cpp-sdk-s3-encryption/libaws-cpp-sdk-s3-encryption.so #4 0x00007ffff6b5154d in Aws::Utils::Crypto::SymmetricCryptoBufSrc::FinalizeCipher() () from /home/ec2-user/sdk_build/aws-cpp-sdk-core/libaws-cpp-sdk-core.so #5 0x00007ffff6b52072 in Aws::Utils::Crypto::SymmetricCryptoBufSrc::Finalize() () from /home/ec2-user/sdk_build/aws-cpp-sdk-core/libaws-cpp-sdk-core.so #6 0x00007ffff6b53751 in Aws::Utils::Crypto::SymmetricCryptoStream::Finalize() () from /home/ec2-user/sdk_build/aws-cpp-sdk-core/libaws-cpp-sdk-core.so #7 0x00007ffff6b53685 in Aws::Utils::Crypto::SymmetricCryptoStream::~SymmetricCryptoStream() () from /home/ec2-user/sdk_build/aws-cpp-sdk-core/libaws-cpp-sdk-core.so #8 0x00007ffff7bb50c1 in void __gnu_cxx::new_allocator<Aws::Utils::Crypto::SymmetricCryptoStream>::destroy<Aws::Utils::Crypto::SymmetricCryptoStream>(Aws::Utils::Crypto::SymmetricCryptoStream*) () from /home/ec2-user/sdk_build/aws-cpp-sdk-s3-encryption/libaws-cpp-sdk-s3-encryption.so #9 0x00007ffff7bb5074 in decltype (({parm#1}.destroy)({parm#2})) std::allocator_traits<Aws::Allocator<Aws::Utils::Crypto::SymmetricCryptoStream> >::_S_destroy<Aws::Allocator<Aws::Utils::Crypto::SymmetricCryptoStream>, Aws::Utils::Crypto::SymmetricCryptoStream>(Aws::Allocator<Aws::Utils::Crypto::SymmetricCryptoStream>&, Aws::Utils::Crypto::SymmetricCryptoStream*, int) () from /home/ec2-user/sdk_build/aws-cpp-sdk-s3-encryption/libaws-cpp-sdk-s3-encryption.so #10 0x00007ffff7bb5006 in void std::allocator_traits<Aws::Allocator<Aws::Utils::Crypto::SymmetricCryptoStream> >::destroy<Aws::Utils::Crypto::SymmetricCryptoStream>(Aws::Allocator<Aws::Utils::Crypto::SymmetricCryptoStream>&, Aws::Utils::Crypto::SymmetricCryptoStream*) () from /home/ec2-user/sdk_build/aws-cpp-sdk-s3-encryption/libaws-cpp-sdk-s3-encryption.so #11 0x00007ffff7bb4ec9 in std::_Sp_counted_ptr_inplace<Aws::Utils::Crypto::SymmetricCryptoStream, Aws::Allocator<Aws::Utils::Crypto::SymmetricCryptoStream>, (__gnu_cxx::_Lock_policy)2>::_M_dispose() () from /home/ec2-user/sdk_build/aws-cpp-sdk-s3-encryption/libaws-cpp-sdk-s3-encryption.so #12 0x000000000041e594 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() () #13 0x000000000041d50b in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() () #14 0x000000000041c560 in std::__shared_ptr<std::iostream, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() () #15 0x000000000041c57c in std::shared_ptr<std::iostream>::~shared_ptr() () #16 0x00007ffff6b19544 in Aws::AmazonStreamingWebServiceRequest::~AmazonStreamingWebServiceRequest() () from /home/ec2-user/sdk_build/aws-cpp-sdk-core/libaws-cpp-sdk-core.so #17 0x0000000000421de0 in Aws::S3::Model::PutObjectRequest::~PutObjectRequest() () #18 0x00007ffff7bae44e in Aws::S3Encryption::Modules::CryptoModule::PutObjectSecurely(Aws::S3::Model::PutObjectRequest const&, std::function<Aws::Utils::Outcome<Aws::S3::Model::PutObjectResult, Aws::Client::AWSError<Aws::S3::S3Errors> > (Aws::S3::Model::PutObjectRequest const&)> const&) () from /home/ec2-user/sdk_build/aws-cpp-sdk-s3-encryption/libaws-cpp-sdk-s3-encryption.so #19 0x00007ffff7b9bfcb in Aws::S3Encryption::S3EncryptionClient::PutObject(Aws::S3::Model::PutObjectRequest const&) const () from /home/ec2-user/sdk_build/aws-cpp-sdk-s3-encryption/libaws-cpp-sdk-s3-encryption.so #20 0x000000000041b675 in main ()

claw-j avatar Jan 25 '18 13:01 claw-j

From frame 0, It seems the ctx is still valid, but ctx->cipher is not, which caused memory access violation when calling ctx->cipher->flag. Is that possible for you to verify that?

singku avatar Jan 25 '18 23:01 singku

BTW, line 22 of the code should be updated to: auto simpleMaterials = Aws::MakeShared<SimpleEncryptionMaterials>("s3Encryption", masterKey);

singku avatar Jan 25 '18 23:01 singku

Thanks for the reminder, I made a mistake when I was pasting the code, I was using this code in line 22 auto simpleMaterials = Aws::MakeShared<Aws::S3Encryption::Materials::SimpleEncryptionMaterials>("s3Encryption", masterKey);

claw-j avatar Jan 26 '18 01:01 claw-j

Sorry for the inconvenience, how do I verify the

ctx->cipher is not valid

?

Do I use GDB or any recommended tools? Thanks!

claw-j avatar Jan 26 '18 08:01 claw-j

Yes, gdb is recommended.

singku avatar Jan 29 '18 06:01 singku

it is the ctx-cipher issue. You can see it in the call stack. #841 should fix it.

cedral avatar Apr 11 '18 16:04 cedral