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

libsel4utils: load_segment memory leak bug #35

Closed
cloudsec opened this issue Jun 1, 2021 · 1 comment
Closed

libsel4utils: load_segment memory leak bug #35

cloudsec opened this issue Jun 1, 2021 · 1 comment
Labels

Comments

@cloudsec
Copy link

cloudsec commented Jun 1, 2021

hello:
i found a memory leak bug in libsel4utils/src/elf.c

static int load_segment(vspace_t *loadee_vspace, vspace_t *loader_vspace,
                        vka_t *loadee_vka, vka_t *loader_vka,
                        const char *src, size_t file_size, int num_regions,
                        sel4utils_elf_region_t regions[num_regions], int region_index)
{
    seL4_CPtr loader_slot;
    cspacepath_t loader_frame_cap;

    error = vka_cspace_alloc(loader_vka, &loader_slot);   // [1]
    while (pos < segment_size && error == seL4_NoError) {
        reservation_t reservation;
        if (loadee_vaddr < region.reservation_vstart) {
            if ((region_index - 1) < 0) {
                ZF_LOGE("Invalid regions: bad elf file.");
                return 1;                                                            // [2]
            }
}

if [2] happned, it not free the prev alloc memory, and then it's memory
will be leaked.
i think the correct way is invoke vka_cspace_free() before return.

@axel-h axel-h added the bug label Jun 1, 2021
@kent-mcleod
Copy link
Member

Thanks for reporting this.

Fixed by #36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants