Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asan: leak at unit:swim.test:swim_test_encryption #5283

Closed
avtikhon opened this issue Sep 9, 2020 · 0 comments
Closed

asan: leak at unit:swim.test:swim_test_encryption #5283

avtikhon opened this issue Sep 9, 2020 · 0 comments
Assignees
Labels
asan qa Issues related to tests or testing subsystem

Comments

@avtikhon
Copy link
Contributor

avtikhon commented Sep 9, 2020

Tarantool version:
2.6.0-57-g2a01ce912
OS version:
Linux

Bug description:
Found memory leak in test:
test/unit/swim.test (sub-test: swim_test_encryption)
located at:
test/unit/swim.c:swim_test_encryption()

Issue:

[001] --- unit/swim.result      Wed Sep  9 12:10:51 2020
[001] +++ unit/swim.reject      Wed Sep  9 12:20:37 2020
[001] @@ -1,10 +1,15 @@
[001] - *** main_f ***
[001] -1..1
[001] - *** swim_test_encryption ***
[001] -    1..3
[001] -    ok 1 - cluster works with encryption
[001] -    ok 2 - different encryption keys - can't interact
[001] -    ok 3 - cluster works after encryption has been disabled
[001] -ok 1 - subtests
[001] - *** swim_test_encryption: done ***
[001] - *** main_f: done ***
[001] +
[001] +=================================================================
[001] +==41031==ERROR: LeakSanitizer: detected memory leaks
[001] +
[001] +Direct leak of 96 byte(s) in 2 object(s) allocated from:
[001] +    #0 0x4d8e53 in __interceptor_malloc (/tnt/test/unit/swim.test+0x4d8e53)
[001] +    #1 0x53560f in crypto_codec_new /source/src/lib/crypto/crypto.c:239:51
[001] +    #2 0x5299c4 in swim_scheduler_set_codec /source/src/lib/swim/swim_io.c:700:30
[001] +    #3 0x511fe6 in swim_cluster_set_codec /source/test/unit/swim_test_utils.c:251:2
[001] +    #4 0x50b3ae in swim_test_encryption /source/test/unit/swim.c:767:2
[001] +    #5 0x50b3ae in main_f /source/test/unit/swim.c:1123
[001] +    #6 0x544a3b in fiber_loop /source/src/lib/core/fiber.c:869:18
[001] +    #7 0x5a13d0 in coro_init /source/third_party/coro/coro.c:110:3
[001] +
[001] +SUMMARY: AddressSanitizer: 96 byte(s) leaked in 2 allocation(s).

Sub-test is:

static void
swim_test_encryption(void)
{
        swim_start_test(3);
        struct swim_cluster *cluster = swim_cluster_new(2);
        const char *key = "1234567812345678";
        swim_cluster_set_codec(cluster, CRYPTO_ALGO_AES128, CRYPTO_MODE_CBC,
                               key, CRYPTO_AES128_KEY_SIZE);
        swim_cluster_add_link(cluster, 0, 1);

        is(swim_cluster_wait_fullmesh(cluster, 2), 0,
           "cluster works with encryption");
        swim_cluster_delete(cluster);
        /*
         * Test that the instances can not interact with different
         * encryption keys.
         */
        cluster = swim_cluster_new(2);
        struct swim *s1 = swim_cluster_member(cluster, 0);
        int rc = swim_set_codec(s1, CRYPTO_ALGO_AES128, CRYPTO_MODE_CBC,
                                key, CRYPTO_AES128_KEY_SIZE);
        fail_if(rc != 0);
        struct swim *s2 = swim_cluster_member(cluster, 1);
        key = "8765432187654321";
        rc = swim_set_codec(s2, CRYPTO_ALGO_AES128, CRYPTO_MODE_CBC,
                            key, CRYPTO_AES128_KEY_SIZE);
        fail_if(rc != 0);
        swim_cluster_add_link(cluster, 0, 1);
        swim_run_for(2);
        ok(! swim_cluster_is_fullmesh(cluster),
           "different encryption keys - can't interact");

        rc = swim_set_codec(s1, CRYPTO_ALGO_NONE, CRYPTO_MODE_ECB, NULL, 0);
        fail_if(rc != 0);
        rc = swim_set_codec(s2, CRYPTO_ALGO_NONE, CRYPTO_MODE_ECB, NULL, 0);
        fail_if(rc != 0);
        is(swim_cluster_wait_fullmesh(cluster, 2), 0,
           "cluster works after encryption has been disabled");

        swim_cluster_delete(cluster);

        swim_finish_test();
}

The function can be minimized with the same issue up to:

static void
swim_test_encryption(void)
{
        swim_start_test(3);

        struct swim_cluster *cluster = swim_cluster_new(2);
 
        swim_cluster_set_codec(cluster, CRYPTO_ALGO_AES128, CRYPTO_MODE_CBC,
                               "1234567812345678", CRYPTO_AES128_KEY_SIZE);

        swim_cluster_delete(cluster);

        swim_finish_test();
}

Seems that root issue in the swim_cluster_set_codec() function which uses resources that later not freed.
To fix in need to integrate:

  swim_cluster_delete_codec(codec)

Steps to reproduce:
Use the attached patch to reproduce:

diff --git a/asan/lsan.supp b/asan/lsan.supp
index 77b7c2cfc..9223b764c 100644
--- a/asan/lsan.supp
+++ b/asan/lsan.supp
@@ -52,9 +52,9 @@ leak:mh_i32ptr_new
 # source: src/lib/core/exception.cc
 leak:Exception::operator new
 
-# test: unit/swim.test.lua
+# test: unit/swim.test
 # source: src/lib/swim/swim_io.c
-leak:swim_scheduler_set_codec
+#leak:swim_scheduler_set_codec
 
 # test: vinyl/errinj.test.lua
 # source: src/lib/core/fiber.h
diff --git a/test/unit/swim.c b/test/unit/swim.c
index bb12baf8d..4b1739bff 100644
--- a/test/unit/swim.c
+++ b/test/unit/swim.c
@@ -1097,13 +1097,13 @@ swim_test_suspect_new_members(void)
 static int
 main_f(va_list ap)
 {
-       swim_start_test(23);
+       swim_start_test(1);
 
        (void) ap;
        swim_test_ev_init();
        swim_test_transport_init();
 
-       swim_test_one_link();
+       /*swim_test_one_link();
        swim_test_sequence();
        swim_test_uuid_update();
        swim_test_cfg();
@@ -1119,13 +1119,13 @@ main_f(va_list ap)
        swim_test_uri_update();
        swim_test_broadcast();
        swim_test_payload_basic();
-       swim_test_indirect_ping();
+       swim_test_indirect_ping();*/
        swim_test_encryption();
-       swim_test_slow_net();
+       /*swim_test_slow_net();
        swim_test_triggers();
        swim_test_generation();
        swim_test_dissemination_speed();
-       swim_test_suspect_new_members();
+       swim_test_suspect_new_members();*/
 
        swim_test_transport_free();
        swim_test_ev_free();
@@ -1140,4 +1140,4 @@ main()
 {
        swim_run_test("swim.txt", main_f);
        return test_result;
-}
\ No newline at end of file
+}

and run:

cd /source
(rm -rf /tnt ; mkdir /tnt ; cd /tnt ; make -f /source/.travis.mk test_asan_debian_no_deps)

ASAN=ON LSAN_OPTIONS=suppressions=/source/asan/lsan.supp ASAN_OPTIONS=heap_profile=0:unmap_shadow_on_exit=1:detect_invalid_pointer_pairs=1:symbolize=1:detect_leaks=1:dump_instruction_bytes=1:print_suppressions=0 /source/test/test-run.py --builddir /tnt --vardir /tnt/test/var --force unit/swim.test

Optional (but very desirable):

  • coredump
  • backtrace
  • netstat
@avtikhon avtikhon added qa Issues related to tests or testing subsystem asan labels Sep 9, 2020
@avtikhon avtikhon self-assigned this Sep 9, 2020
avtikhon added a commit that referenced this issue Sep 9, 2020
Found leak issue:

  [001] +==41031==ERROR: LeakSanitizer: detected memory leaks
  [001] +
  [001] +Direct leak of 96 byte(s) in 2 object(s) allocated from:
  [001] +    #0 0x4d8e53 in __interceptor_malloc (/tnt/test/unit/swim.test+0x4d8e53)
  [001] +    #1 0x53560f in crypto_codec_new /source/src/lib/crypto/crypto.c:239:51
  [001] +    #2 0x5299c4 in swim_scheduler_set_codec /source/src/lib/swim/swim_io.c:700:30
  [001] +    #3 0x511fe6 in swim_cluster_set_codec /source/test/unit/swim_test_utils.c:251:2
  [001] +    #4 0x50b3ae in swim_test_encryption /source/test/unit/swim.c:767:2
  [001] +    #5 0x50b3ae in main_f /source/test/unit/swim.c:1123
  [001] +    #6 0x544a3b in fiber_loop /source/src/lib/core/fiber.c:869:18
  [001] +    #7 0x5a13d0 in coro_init /source/third_party/coro/coro.c:110:3
  [001] +
  [001] +SUMMARY: AddressSanitizer: 96 byte(s) leaked in 2 allocation(s).

Prepared minimal issue reproducer:

  static void
  swim_test_encryption(void)
  {
          swim_start_test(3);
          struct swim_cluster *cluster = swim_cluster_new(2);
          swim_cluster_set_codec(cluster, CRYPTO_ALGO_AES128, CRYPTO_MODE_CBC,
                                 "1234567812345678", CRYPTO_AES128_KEY_SIZE);
          swim_cluster_delete(cluster);
          swim_finish_test();
  }

Found that memory allocated for codec creation at crypto_codec_new()
using swim_cluster_set_codec(). But there was no any memory free for
it. Decided to integrate at test utilities swim_cluster_delete_codec()
function for it available for tests.

After this fix removed susspencion on memory leak for unit/swin.test.

Closes #5283
avtikhon added a commit that referenced this issue Sep 9, 2020
Found leak issue:

  [001] +==41031==ERROR: LeakSanitizer: detected memory leaks
  [001] +
  [001] +Direct leak of 96 byte(s) in 2 object(s) allocated from:
  [001] +    #0 0x4d8e53 in __interceptor_malloc (/tnt/test/unit/swim.test+0x4d8e53)
  [001] +    #1 0x53560f in crypto_codec_new /source/src/lib/crypto/crypto.c:239:51
  [001] +    #2 0x5299c4 in swim_scheduler_set_codec /source/src/lib/swim/swim_io.c:700:30
  [001] +    #3 0x511fe6 in swim_cluster_set_codec /source/test/unit/swim_test_utils.c:251:2
  [001] +    #4 0x50b3ae in swim_test_encryption /source/test/unit/swim.c:767:2
  [001] +    #5 0x50b3ae in main_f /source/test/unit/swim.c:1123
  [001] +    #6 0x544a3b in fiber_loop /source/src/lib/core/fiber.c:869:18
  [001] +    #7 0x5a13d0 in coro_init /source/third_party/coro/coro.c:110:3
  [001] +
  [001] +SUMMARY: AddressSanitizer: 96 byte(s) leaked in 2 allocation(s).

Prepared minimal issue reproducer:

  static void
  swim_test_encryption(void)
  {
          swim_start_test(3);
          struct swim_cluster *cluster = swim_cluster_new(2);
          swim_cluster_set_codec(cluster, CRYPTO_ALGO_AES128, CRYPTO_MODE_CBC,
                                 "1234567812345678", CRYPTO_AES128_KEY_SIZE);
          swim_cluster_delete(cluster);
          swim_finish_test();
  }

Found that memory allocation for codec creation at crypto_codec_new()
using swim_cluster_set_codec() was not any freed at the test. Decided
to integrate into test utilities swim_cluster_delete_codec() function
which can be used for it in tests.

After this fix removed susspencion on memory leak for unit/swim.test.

Closes #5283
@avtikhon avtikhon added this to ON REVIEW in Quality Assurance Sep 9, 2020
avtikhon added a commit that referenced this issue Sep 10, 2020
Found leak issue:

  [001] +==41031==ERROR: LeakSanitizer: detected memory leaks
  [001] +
  [001] +Direct leak of 96 byte(s) in 2 object(s) allocated from:
  [001] +    #0 0x4d8e53 in __interceptor_malloc (/tnt/test/unit/swim.test+0x4d8e53)
  [001] +    #1 0x53560f in crypto_codec_new /source/src/lib/crypto/crypto.c:239:51
  [001] +    #2 0x5299c4 in swim_scheduler_set_codec /source/src/lib/swim/swim_io.c:700:30
  [001] +    #3 0x511fe6 in swim_cluster_set_codec /source/test/unit/swim_test_utils.c:251:2
  [001] +    #4 0x50b3ae in swim_test_encryption /source/test/unit/swim.c:767:2
  [001] +    #5 0x50b3ae in main_f /source/test/unit/swim.c:1123
  [001] +    #6 0x544a3b in fiber_loop /source/src/lib/core/fiber.c:869:18
  [001] +    #7 0x5a13d0 in coro_init /source/third_party/coro/coro.c:110:3
  [001] +
  [001] +SUMMARY: AddressSanitizer: 96 byte(s) leaked in 2 allocation(s).

Prepared minimal issue reproducer:

  static void
  swim_test_encryption(void)
  {
          swim_start_test(3);
          struct swim_cluster *cluster = swim_cluster_new(2);
          swim_cluster_set_codec(cluster, CRYPTO_ALGO_AES128, CRYPTO_MODE_CBC,
                                 "1234567812345678", CRYPTO_AES128_KEY_SIZE);
          swim_cluster_delete(cluster);
          swim_finish_test();
  }

Found that memory allocation for codec creation at crypto_codec_new()
using swim_cluster_set_codec() was not any freed at the test. Added
crypto_codec_delete() in swim_scheduler_destroy() function for it.

After this fix removed susspencion on memory leak for unit/swim.test.

Closes #5283
avtikhon added a commit that referenced this issue Sep 10, 2020
Found leak issue:

  [001] +==41031==ERROR: LeakSanitizer: detected memory leaks
  [001] +
  [001] +Direct leak of 96 byte(s) in 2 object(s) allocated from:
  [001] +    #0 0x4d8e53 in __interceptor_malloc (/tnt/test/unit/swim.test+0x4d8e53)
  [001] +    #1 0x53560f in crypto_codec_new /source/src/lib/crypto/crypto.c:239:51
  [001] +    #2 0x5299c4 in swim_scheduler_set_codec /source/src/lib/swim/swim_io.c:700:30
  [001] +    #3 0x511fe6 in swim_cluster_set_codec /source/test/unit/swim_test_utils.c:251:2
  [001] +    #4 0x50b3ae in swim_test_encryption /source/test/unit/swim.c:767:2
  [001] +    #5 0x50b3ae in main_f /source/test/unit/swim.c:1123
  [001] +    #6 0x544a3b in fiber_loop /source/src/lib/core/fiber.c:869:18
  [001] +    #7 0x5a13d0 in coro_init /source/third_party/coro/coro.c:110:3
  [001] +
  [001] +SUMMARY: AddressSanitizer: 96 byte(s) leaked in 2 allocation(s).

Prepared minimal issue reproducer:

  static void
  swim_test_encryption(void)
  {
          swim_start_test(3);
          struct swim_cluster *cluster = swim_cluster_new(2);
          swim_cluster_set_codec(cluster, CRYPTO_ALGO_AES128, CRYPTO_MODE_CBC,
                                 "1234567812345678", CRYPTO_AES128_KEY_SIZE);
          swim_cluster_delete(cluster);
          swim_finish_test();
  }

Found that memory allocation for codec creation at crypto_codec_new()
using swim_cluster_set_codec() was not any freed at the test. Added
crypto_codec_delete() in swim_scheduler_destroy() function for it.

After this fix removed susspencion on memory leak for unit/swim.test.

Closes #5283

Reviewed-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>

Co-authored-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
kyukhin pushed a commit that referenced this issue Sep 11, 2020
Found leak issue:

  [001] +==41031==ERROR: LeakSanitizer: detected memory leaks
  [001] +
  [001] +Direct leak of 96 byte(s) in 2 object(s) allocated from:
  [001] +    #0 0x4d8e53 in __interceptor_malloc (/tnt/test/unit/swim.test+0x4d8e53)
  [001] +    #1 0x53560f in crypto_codec_new /source/src/lib/crypto/crypto.c:239:51
  [001] +    #2 0x5299c4 in swim_scheduler_set_codec /source/src/lib/swim/swim_io.c:700:30
  [001] +    #3 0x511fe6 in swim_cluster_set_codec /source/test/unit/swim_test_utils.c:251:2
  [001] +    #4 0x50b3ae in swim_test_encryption /source/test/unit/swim.c:767:2
  [001] +    #5 0x50b3ae in main_f /source/test/unit/swim.c:1123
  [001] +    #6 0x544a3b in fiber_loop /source/src/lib/core/fiber.c:869:18
  [001] +    #7 0x5a13d0 in coro_init /source/third_party/coro/coro.c:110:3
  [001] +
  [001] +SUMMARY: AddressSanitizer: 96 byte(s) leaked in 2 allocation(s).

Prepared minimal issue reproducer:

  static void
  swim_test_encryption(void)
  {
          swim_start_test(3);
          struct swim_cluster *cluster = swim_cluster_new(2);
          swim_cluster_set_codec(cluster, CRYPTO_ALGO_AES128, CRYPTO_MODE_CBC,
                                 "1234567812345678", CRYPTO_AES128_KEY_SIZE);
          swim_cluster_delete(cluster);
          swim_finish_test();
  }

Found that memory allocation for codec creation at crypto_codec_new()
using swim_cluster_set_codec() was not any freed at the test. Added
crypto_codec_delete() in swim_scheduler_destroy() function for it.

After this fix removed susspencion on memory leak for unit/swim.test.

Closes #5283

Reviewed-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>

Co-authored-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
(cherry picked from commit ee9e3ae)
kyukhin pushed a commit that referenced this issue Sep 11, 2020
Found leak issue:

  [001] +==41031==ERROR: LeakSanitizer: detected memory leaks
  [001] +
  [001] +Direct leak of 96 byte(s) in 2 object(s) allocated from:
  [001] +    #0 0x4d8e53 in __interceptor_malloc (/tnt/test/unit/swim.test+0x4d8e53)
  [001] +    #1 0x53560f in crypto_codec_new /source/src/lib/crypto/crypto.c:239:51
  [001] +    #2 0x5299c4 in swim_scheduler_set_codec /source/src/lib/swim/swim_io.c:700:30
  [001] +    #3 0x511fe6 in swim_cluster_set_codec /source/test/unit/swim_test_utils.c:251:2
  [001] +    #4 0x50b3ae in swim_test_encryption /source/test/unit/swim.c:767:2
  [001] +    #5 0x50b3ae in main_f /source/test/unit/swim.c:1123
  [001] +    #6 0x544a3b in fiber_loop /source/src/lib/core/fiber.c:869:18
  [001] +    #7 0x5a13d0 in coro_init /source/third_party/coro/coro.c:110:3
  [001] +
  [001] +SUMMARY: AddressSanitizer: 96 byte(s) leaked in 2 allocation(s).

Prepared minimal issue reproducer:

  static void
  swim_test_encryption(void)
  {
          swim_start_test(3);
          struct swim_cluster *cluster = swim_cluster_new(2);
          swim_cluster_set_codec(cluster, CRYPTO_ALGO_AES128, CRYPTO_MODE_CBC,
                                 "1234567812345678", CRYPTO_AES128_KEY_SIZE);
          swim_cluster_delete(cluster);
          swim_finish_test();
  }

Found that memory allocation for codec creation at crypto_codec_new()
using swim_cluster_set_codec() was not any freed at the test. Added
crypto_codec_delete() in swim_scheduler_destroy() function for it.

After this fix removed susspencion on memory leak for unit/swim.test.

Closes #5283

Reviewed-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>

Co-authored-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
(cherry picked from commit ee9e3ae)
avtikhon added a commit that referenced this issue Sep 11, 2020
Removed susspencion on memory leak for unit/swim.test test.

Closes #5283
kyukhin pushed a commit that referenced this issue Sep 11, 2020
Removed susspencion on memory leak for unit/swim.test test.

Closes #5283
@avtikhon avtikhon moved this from ON REVIEW to DONE in Quality Assurance Sep 11, 2020
@avtikhon avtikhon removed this from DONE in Quality Assurance Sep 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
asan qa Issues related to tests or testing subsystem
Projects
None yet
Development

No branches or pull requests

1 participant