Bug in find_vma_prev - mmap.c



This code returns vma (mm->mmap) if it sees that addr is lower than first VMA.
However, I think it falsely returns vma (mm->mmap) on the case where
addr is in the first VMA.

If it is the first VMA region:
- *pprev should be set to NULL
- implying prev is NULL
- and should therefore return vma (so in this case, I just added if
it's the first VMA and it's within range)

/* Same as find_vma, but also return a pointer to the previous VMA in *pprev. */
struct vm_area_struct *
find_vma_prev(struct mm_struct *mm, unsigned long addr,
            struct vm_area_struct **pprev)
{
    struct vm_area_struct *vma = NULL, *prev = NULL;
    struct rb_node *rb_node;
    if (!mm)
        goto out;

    /* Guard against addr being lower than the first VMA */
    vma = mm->mmap;

    /* Go through the RB tree quickly. */
    rb_node = mm->mm_rb.rb_node;

    while (rb_node) {
        struct vm_area_struct *vma_tmp;
        vma_tmp = rb_entry(rb_node, struct vm_area_struct, vm_rb);

        if (addr < vma_tmp->vm_end) {
            // TONY: if (vma_tmp->vm_start <= addr) vma = vma_tmp; //
this returns the correct 'vma' when vma is the first node (i.e., no
prev)
            rb_node = rb_node->rb_left;
        } else {
            prev = vma_tmp;
            if (!prev->vm_next || (addr < prev->vm_next->vm_end))
                break;
            rb_node = rb_node->rb_right;
        }
    }

out:
    *pprev = prev;
    return prev ? prev->vm_next : vma;
}

Is this a known issue and/or has this problem been addressed?
Also, please CC my email address with responses.

Thanks,
--tony

--
Aim for Perfection!
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: Bug in find_vma_prev - mmap.c
    ... that addr is not in the list (but is greater than ... you appeared to be talking about a discrepancy with the first ... vma; now you're talking about a discrepancy with the last vma? ... Or a discrepancy when the first vma is the last vma? ...
    (Linux-Kernel)
  • Re: Bug in find_vma_prev - mmap.c
    ... addr is in the first VMA. ... If it is the first VMA region: ...     if ...
    (Linux-Kernel)
  • Re: Bug in find_vma_prev - mmap.c
    ... addr is in the first VMA. ... If it is the first VMA region: ... *pprev should be set to NULL ... implying prev is NULL ...
    (Linux-Kernel)
  • [PATCH 1/2] mm: use list.h for vma list
    ... addr = PAGE_ALIGN; ... iterate through the VMA list and take care of any aliases. ... goto out; ... struct mmu_gather *tlb; ...
    (Linux-Kernel)
  • [PATCH 24/25] mm: Remove i_mmap_mutex lockbreak
    ... "The only significant loser, I think, would be page reclaim (when ... unsigned long addr, unsigned long end, ... struct vm_area_struct *vma, ...
    (Linux-Kernel)