ucx icon indicating copy to clipboard operation
ucx copied to clipboard

UCS/GTEST: fixed uninitialized value access

Open iyastreb opened this issue 1 year ago • 0 comments

What

This is fix for RM#3919044 There are multiple test failures reported as:

==54391== Conditional jump or move depends on uninitialised value(s)
==54391==    at 0x50AE1A2: ucs_rcache_check_overlap (rcache.c:860)
==54391==    by 0x50AE1A2: ucs_rcache_create_region (rcache.c:952)
==54391==    by 0x50AE9AB: ucs_rcache_get (rcache.c:1108)
==54391==    by 0xBE26F4: test_rcache::get(void*, unsigned long, int, unsigned long) (test_rcache.cc:109)
==54391==    by 0xBD33E1: test_rcache_basic_Test::test_body() (test_rcache.cc:276)
==54391==    by 0x637499: ucs::test_base::thread_func(void*) (test.cc:397)
==54391==    by 0x995ADD4: start_thread (in /usr/lib64/libpthread-2.17.so)
==54391==  Uninitialised value was created by a stack allocation

Why ?

Function ucs_rcache_check_overlap was modified in https://github.com/openucx/ucx/pull/9441, with additional check whether found region is the only element in the list. The issue reported by ASAN and valgrind happens when returned region list is empty. In this case we access some uninitialized data on the stack:

    ucs_list_link_t region_list;
    ucs_list_head_init(&region_list);
    ucs_rcache_find_regions(rcache, *start, *end - 1, &region_list); << returns empty list

    region = ucs_list_next(&region_list, ucs_rcache_region_t, tmp_list); << access non-existing region by offset on the stack

How ?

Added check that returned list is not empty

iyastreb avatar May 30 '24 13:05 iyastreb