Andrew Kryczka
04623e7cd4
Fix GetMergeOperands() heap-use-after-free on flushed memtable (#9805)
Summary:
Fixes https://github.com/facebook/rocksdb/issues/9066.
Prior to the fix in this PR, this PR's unit test reported the following error under ASAN:
```
==2175705==ERROR: AddressSanitizer: heap-use-after-free on address 0x61f0000012a5 at pc 0x7f0fc36e76ce bp 0x7ffc103e9ca0 sp 0x7ffc103e9450
READ of size 5 at 0x61f0000012a5 thread T0
#0 0x7f0fc36e76cd in __interceptor_memcpy /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:790
https://github.com/facebook/rocksdb/issues/1 0x7f0fc35a207e in std::char_traits<char>::copy(char*, char const*, unsigned long) /home/engshare/third-party2/libgcc/9.x/src/gcc-9.x/x86_64-facebook-linux/libstdc++-v3/include/bits/char_traits.h:365
https://github.com/facebook/rocksdb/issues/2 0x7f0fc35a207e in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_S_copy(char*, char const*, unsigned long) /home/engshare/third-party2/libgcc/9.x/src/gcc-9.x/x86_64-facebook-linux/libstdc++-v3/include/bits/basic_string.h:351
https://github.com/facebook/rocksdb/issues/3 0x7f0fc35a207e in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long) /home/engshare/third-party2/libgcc/9.x/src/gcc-9.x/x86_64-facebook-linux/libstdc++-v3/include/bits/basic_string.tcc:440
https://github.com/facebook/rocksdb/issues/4 0x8679ca in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::assign(char const*, unsigned long) /mnt/gvfs/third-party2/libgcc/4959b39cfbe5965a37c861c4c327fa7c5c759b87/9.x/platform009/9202ce7/include/c++/9.3.0/bits/basic_string.h:1422
https://github.com/facebook/rocksdb/issues/5 0x8679ca in rocksdb::PinnableSlice::PinSelf(rocksdb::Slice const&) include/rocksdb/slice.h:171
https://github.com/facebook/rocksdb/issues/6 0x8679ca in rocksdb::DBImpl::GetImpl(rocksdb::ReadOptions const&, rocksdb::Slice const&, rocksdb::DBImpl::GetImplOptions&) db/db_impl/db_impl.cc:1930
https://github.com/facebook/rocksdb/issues/7 0x547324 in rocksdb::DBImpl::GetMergeOperands(rocksdb::ReadOptions const&, rocksdb::ColumnFamilyHandle*, rocksdb::Slice const&, rocksdb::PinnableSlice*, rocksdb::GetMergeOperandsOptions*, int*) db/db_impl/db_impl.h:203
https://github.com/facebook/rocksdb/issues/8 0x547324 in rocksdb::DBMergeOperandTest_FlushedMergeOperandReadAfterFreeBug_Test::TestBody() db/db_merge_operand_test.cc:117
https://github.com/facebook/rocksdb/issues/9 0x7241da in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:3899
https://github.com/facebook/rocksdb/issues/10 0x7241da in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:3935
https://github.com/facebook/rocksdb/issues/11 0x701a47 in testing::Test::Run() third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:3973
https://github.com/facebook/rocksdb/issues/12 0x702040 in testing::Test::Run() third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:3965
https://github.com/facebook/rocksdb/issues/13 0x702040 in testing::TestInfo::Run() third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:4149
https://github.com/facebook/rocksdb/issues/14 0x7025f7 in testing::TestInfo::Run() third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:4124
https://github.com/facebook/rocksdb/issues/15 0x7025f7 in testing::TestCase::Run() third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:4267
https://github.com/facebook/rocksdb/issues/16 0x704217 in testing::TestCase::Run() third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:4253
https://github.com/facebook/rocksdb/issues/17 0x704217 in testing::internal::UnitTestImpl::RunAllTests() third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:6633
https://github.com/facebook/rocksdb/issues/18 0x72505a in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:3899
https://github.com/facebook/rocksdb/issues/19 0x72505a in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:3935
https://github.com/facebook/rocksdb/issues/20 0x704aa1 in testing::UnitTest::Run() third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:6242
https://github.com/facebook/rocksdb/issues/21 0x4c4aff in RUN_ALL_TESTS() third-party/gtest-1.8.1/fused-src/gtest/gtest.h:22110
https://github.com/facebook/rocksdb/issues/22 0x4c4aff in main db/db_merge_operand_test.cc:404
https://github.com/facebook/rocksdb/issues/23 0x7f0fc3108dc4 in __libc_start_main ../csu/libc-start.c:308
https://github.com/facebook/rocksdb/issues/24 0x5445fd in _start (/data/users/andrewkr/rocksdb/db_merge_operand_test+0x5445fd)
0x61f0000012a5 is located 1061 bytes inside of 3264-byte region [0x61f000000e80,0x61f000001b40)
freed by thread T0 here:
#0 0x7f0fc375b6af in operator delete(void*, unsigned long) /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/libsanitizer/asan/asan_new_delete.cc:177
https://github.com/facebook/rocksdb/issues/1 0x743be8 in rocksdb::SuperVersion::~SuperVersion() db/column_family.cc:432
https://github.com/facebook/rocksdb/issues/2 0x8052aa in rocksdb::DBImpl::CleanupSuperVersion(rocksdb::SuperVersion*) db/db_impl/db_impl.cc:3534
https://github.com/facebook/rocksdb/issues/3 0x8676c2 in rocksdb::DBImpl::ReturnAndCleanupSuperVersion(rocksdb::ColumnFamilyData*, rocksdb::SuperVersion*) db/db_impl/db_impl.cc:3544
https://github.com/facebook/rocksdb/issues/4 0x8676c2 in rocksdb::DBImpl::GetImpl(rocksdb::ReadOptions const&, rocksdb::Slice const&, rocksdb::DBImpl::GetImplOptions&) db/db_impl/db_impl.cc:1911
https://github.com/facebook/rocksdb/issues/5 0x547324 in rocksdb::DBImpl::GetMergeOperands(rocksdb::ReadOptions const&, rocksdb::ColumnFamilyHandle*, rocksdb::Slice const&, rocksdb::PinnableSlice*, rocksdb::GetMergeOperandsOptions*, int*) db/db_impl/db_impl.h:203
https://github.com/facebook/rocksdb/issues/6 0x547324 in rocksdb::DBMergeOperandTest_FlushedMergeOperandReadAfterFreeBug_Test::TestBody() db/db_merge_operand_test.cc:117
https://github.com/facebook/rocksdb/issues/7 0x7241da in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:3899
https://github.com/facebook/rocksdb/issues/8 0x7241da in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:3935
https://github.com/facebook/rocksdb/issues/9 0x701a47 in testing::Test::Run() third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:3973
https://github.com/facebook/rocksdb/issues/10 0x702040 in testing::Test::Run() third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:3965
https://github.com/facebook/rocksdb/issues/11 0x702040 in testing::TestInfo::Run() third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:4149
https://github.com/facebook/rocksdb/issues/12 0x7025f7 in testing::TestInfo::Run() third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:4124
https://github.com/facebook/rocksdb/issues/13 0x7025f7 in testing::TestCase::Run() third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:4267
https://github.com/facebook/rocksdb/issues/14 0x704217 in testing::TestCase::Run() third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:4253
https://github.com/facebook/rocksdb/issues/15 0x704217 in testing::internal::UnitTestImpl::RunAllTests() third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:6633
https://github.com/facebook/rocksdb/issues/16 0x72505a in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:3899
https://github.com/facebook/rocksdb/issues/17 0x72505a in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:3935
https://github.com/facebook/rocksdb/issues/18 0x704aa1 in testing::UnitTest::Run() third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc:6242
https://github.com/facebook/rocksdb/issues/19 0x4c4aff in RUN_ALL_TESTS() third-party/gtest-1.8.1/fused-src/gtest/gtest.h:22110
https://github.com/facebook/rocksdb/issues/20 0x4c4aff in main db/db_merge_operand_test.cc:404
https://github.com/facebook/rocksdb/issues/21 0x7f0fc3108dc4 in __libc_start_main ../csu/libc-start.c:308
https://github.com/facebook/rocksdb/issues/22 0x5445fd in _start (/data/users/andrewkr/rocksdb/db_merge_operand_test+0x5445fd)
...
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9805
Test Plan: following the fix in this PR, the new unit test passes
Reviewed By: jay-zhuang
Differential Revision: D35388415
Pulled By: ajkr
fbshipit-source-id: b39c5d002155906c8abc4a3429eca696dbf916d0
2022-04-05 12:26:36 -07:00
..
2022-02-16 23:18:14 -08:00
2022-03-21 16:11:02 -07:00
2022-04-05 12:26:36 -07:00
2022-03-15 09:50:21 -07:00
2021-09-29 04:04:40 -07:00
2022-03-15 14:45:34 -07:00
2021-09-16 17:23:36 -07:00
2022-04-05 09:52:33 -07:00
2022-03-23 10:00:54 -07:00
2021-12-10 08:13:26 -08:00
2022-03-24 13:05:17 -07:00
2022-03-24 13:05:17 -07:00
2022-02-22 12:23:00 -08:00
2021-12-10 08:13:26 -08:00
2022-02-16 23:18:14 -08:00
2022-01-04 16:45:49 -08:00
2021-10-18 23:32:01 -07:00
2022-02-17 16:31:41 -08:00
2022-02-04 14:15:58 -08:00
2022-03-23 10:00:54 -07:00
2021-07-23 08:38:45 -07:00
2022-03-15 12:31:14 -07:00
2022-01-27 13:01:09 -08:00
2021-07-23 08:38:45 -07:00
2022-04-01 16:06:14 -07:00
2022-03-31 20:00:52 -07:00
2021-07-30 12:16:44 -07:00
2020-06-15 10:47:02 -07:00
2022-03-21 12:04:33 -07:00
2021-11-08 11:05:59 -08:00
2021-05-05 14:00:17 -07:00
2022-01-28 13:28:38 -08:00
2022-01-28 13:28:38 -08:00
2021-09-29 04:04:40 -07:00
2021-07-23 08:38:45 -07:00
2022-02-01 22:19:01 -08:00
2021-08-10 11:10:07 -07:00
2022-03-04 11:35:28 -08:00
2021-07-23 08:38:45 -07:00
2022-04-05 12:26:36 -07:00
2021-07-23 08:38:45 -07:00
2022-02-08 19:31:28 -08:00
2022-03-07 18:06:19 -08:00
2022-03-15 09:50:21 -07:00
2022-03-08 13:19:39 -08:00
2022-01-04 16:45:49 -08:00
2022-01-04 16:45:49 -08:00
2021-09-07 13:28:29 -07:00
2021-11-19 17:31:01 -08:00
2021-07-23 08:38:45 -07:00
2022-03-18 16:35:51 -07:00
2022-02-09 12:36:43 -08:00
2022-03-22 10:22:18 -07:00
2022-03-29 14:36:35 -07:00
2021-11-18 17:31:50 -08:00
2022-03-23 19:41:31 -07:00
2022-03-11 16:13:23 -08:00
2022-02-08 12:15:35 -08:00
2021-11-08 11:05:59 -08:00
2021-11-08 11:05:59 -08:00
2021-11-08 11:05:59 -08:00
2021-11-10 10:49:04 -08:00
2022-03-11 16:13:23 -08:00
2021-11-08 11:05:59 -08:00
2022-03-15 14:45:34 -07:00
2022-03-15 14:45:34 -07:00
2022-03-15 14:45:34 -07:00
2022-03-23 19:41:31 -07:00
2021-12-08 14:30:57 -08:00
2022-03-18 16:35:51 -07:00
2021-11-08 11:05:59 -08:00
2022-03-02 17:41:02 -08:00
2021-12-16 17:15:13 -08:00
2022-01-04 16:45:49 -08:00
2021-12-13 09:00:36 -08:00
2020-02-20 12:09:57 -08:00
2020-02-20 12:09:57 -08:00
2020-02-20 12:09:57 -08:00
2022-03-30 15:55:31 -07:00
2022-02-08 12:15:35 -08:00
2022-03-21 16:11:02 -07:00
2022-03-15 14:45:34 -07:00
2020-02-20 12:09:57 -08:00
2021-03-19 12:09:47 -07:00
2022-01-12 09:31:12 -08:00
2022-01-21 11:37:46 -08:00
2022-01-21 11:37:46 -08:00
2022-03-11 16:13:23 -08:00
2022-02-18 18:23:07 -08:00
2021-12-16 17:15:13 -08:00
2021-07-23 08:38:45 -07:00
2022-03-18 16:35:51 -07:00
2021-10-20 13:17:00 -07:00
2022-03-18 16:35:51 -07:00
2021-11-16 10:20:50 -08:00
2022-02-22 12:23:00 -08:00
2022-02-17 16:19:31 -08:00
2022-03-09 15:49:53 -08:00
2022-03-09 15:49:53 -08:00
2022-03-09 15:49:53 -08:00
2022-03-09 15:49:53 -08:00
2022-03-09 15:49:53 -08:00
2020-02-20 12:09:57 -08:00
2021-03-19 12:09:47 -07:00
2021-09-29 04:04:40 -07:00
2021-09-07 11:31:59 -07:00
2020-02-20 12:09:57 -08:00
2022-01-12 09:31:12 -08:00
2022-03-15 14:45:34 -07:00
2022-03-31 20:00:52 -07:00
2022-03-15 14:45:34 -07:00
2022-01-27 14:55:04 -08:00
2022-01-27 14:55:04 -08:00
2021-05-10 12:50:25 -07:00
2021-11-19 17:53:47 -08:00
2021-11-19 17:53:47 -08:00
2021-11-19 17:53:47 -08:00
2020-02-20 12:09:57 -08:00
2022-01-04 16:45:49 -08:00
2021-12-10 11:05:35 -08:00
2020-12-23 16:55:53 -08:00
2021-09-29 04:04:40 -07:00
2021-09-29 04:04:40 -07:00
2021-03-15 04:34:11 -07:00
2021-07-23 08:38:45 -07:00
2022-03-12 11:45:56 -08:00
2022-03-12 11:45:56 -08:00
2021-09-07 11:31:59 -07:00
2022-01-21 11:37:46 -08:00
2021-09-10 10:00:26 -07:00
2021-03-15 04:34:11 -07:00
2021-10-06 07:48:31 -07:00
2021-10-06 07:48:31 -07:00
2020-10-28 10:12:58 -07:00
2021-03-25 21:18:08 -07:00
2021-10-06 07:48:31 -07:00
2021-06-18 04:57:27 -07:00
2021-06-18 04:57:27 -07:00
2021-09-10 10:00:26 -07:00
2021-07-28 16:44:14 -07:00
2022-01-21 11:37:46 -08:00
2020-02-20 12:09:57 -08:00
2020-02-20 12:09:57 -08:00
2021-09-10 10:00:26 -07:00
2022-03-15 09:55:49 -07:00
2022-01-21 11:37:46 -08:00
2021-11-18 11:43:44 -08:00
2021-03-25 15:00:45 -07:00
2021-11-19 11:37:06 -08:00
2021-12-10 11:05:35 -08:00
2021-09-29 04:04:40 -07:00
2020-02-20 12:09:57 -08:00
2020-02-20 12:09:57 -08:00
2022-02-09 12:36:43 -08:00
2022-02-09 12:36:43 -08:00
2022-01-21 11:37:46 -08:00
2022-03-23 19:41:31 -07:00
2021-06-10 12:55:20 -07:00
2021-12-03 14:43:14 -08:00
2022-03-31 20:00:52 -07:00
2022-02-04 08:19:20 -08:00
2022-03-23 19:41:31 -07:00
2022-03-29 14:36:35 -07:00
2022-03-24 13:05:17 -07:00
2022-03-18 16:35:51 -07:00
2020-12-09 16:02:12 -08:00
2020-12-09 16:02:12 -08:00
2020-12-09 16:02:12 -08:00
2021-09-21 09:23:48 -07:00
2021-07-30 12:16:44 -07:00
2021-07-30 12:16:44 -07:00
2020-02-20 12:09:57 -08:00
2022-02-22 14:23:01 -08:00
2022-02-22 14:23:01 -08:00
2022-04-01 10:30:17 -07:00
2021-07-07 11:14:05 -07:00
2020-02-20 12:09:57 -08:00
2021-03-18 09:47:31 -07:00
2021-03-18 09:47:31 -07:00
2021-03-18 09:47:31 -07:00
2022-03-08 13:19:39 -08:00
2022-03-08 13:19:39 -08:00