Message ID | 20231207152525.2607420-1-wangkefeng.wang@huawei.com (mailing list archive) |
---|---|
State | Handled Elsewhere |
Delegated to: | Paul Moore |
Headers | show |
Series | mm: fix VMA heap bounds checking | expand |
On Thu, 7 Dec 2023 23:25:25 +0800 Kefeng Wang <wangkefeng.wang@huawei.com> wrote: > After selinux converting to VMA heap check helper, the gcl triggers > an execheap SELinux denial, which caused by different check logical. > > The old from selinux only check VMA range within VMA heap range, and > the new will check the intersects between the two ranges, but the corner > cases(vm_end=start_brk, brk=vm_start) doesn't be handled correctly. > > Since commit 11250fd12eb8 ("mm: factor out VMA stack and heap checks") > only a function extraction, it seems that the issue introduced from > commit 0db0c01b53a1 ("procfs: fix /proc/<pid>/maps heap check"), let's > fix above corner cases, meanwhile, corrent the wrong indentation of the > stack and heap check helpers. > > Reported-and-tested-by: Ondrej Mosnacek <omosnace@redhat.com> > Closes: https://lore.kernel.org/selinux/CAFqZXNv0SVT0fkOK6neP9AXbj3nxJ61JAY4+zJzvxqJaeuhbFw@mail.gmail.com/ > Fixes: 0db0c01b53a1 ("procfs: fix /proc/<pid>/maps heap check") I suggest this should be Fixes: 11250fd12eb8 ("mm: factor out VMA stack and heap checks"). Sure, 0db0c01b53a1 may have been wrong, but is there any point in suggesting to people that they backport this fix over 12 years worth of kernels? Or is it the case that only kernels which contain 11250fd12eb8 need this change?
On 2023/12/8 6:16, Andrew Morton wrote: > On Thu, 7 Dec 2023 23:25:25 +0800 Kefeng Wang <wangkefeng.wang@huawei.com> wrote: > >> After selinux converting to VMA heap check helper, the gcl triggers >> an execheap SELinux denial, which caused by different check logical. >> >> The old from selinux only check VMA range within VMA heap range, and >> the new will check the intersects between the two ranges, but the corner >> cases(vm_end=start_brk, brk=vm_start) doesn't be handled correctly. >> >> Since commit 11250fd12eb8 ("mm: factor out VMA stack and heap checks") >> only a function extraction, it seems that the issue introduced from >> commit 0db0c01b53a1 ("procfs: fix /proc/<pid>/maps heap check"), let's >> fix above corner cases, meanwhile, corrent the wrong indentation of the >> stack and heap check helpers. >> >> Reported-and-tested-by: Ondrej Mosnacek <omosnace@redhat.com> >> Closes: https://lore.kernel.org/selinux/CAFqZXNv0SVT0fkOK6neP9AXbj3nxJ61JAY4+zJzvxqJaeuhbFw@mail.gmail.com/ >> Fixes: 0db0c01b53a1 ("procfs: fix /proc/<pid>/maps heap check") > > I suggest this should be Fixes: 11250fd12eb8 ("mm: factor out VMA stack and > heap checks"). Sure, 0db0c01b53a1 may have been wrong, but is there > any point in suggesting to people that they backport this fix over 12 years > worth of kernels? Or is it the case that only kernels which contain > 11250fd12eb8 need this change? Fair enough, also thanks for updating the commit message. >
diff --git a/include/linux/mm.h b/include/linux/mm.h index 1be544664f92..2bea89dc0bdf 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -886,8 +886,8 @@ static inline bool vma_is_anonymous(struct vm_area_struct *vma) */ static inline bool vma_is_initial_heap(const struct vm_area_struct *vma) { - return vma->vm_start <= vma->vm_mm->brk && - vma->vm_end >= vma->vm_mm->start_brk; + return vma->vm_start < vma->vm_mm->brk && + vma->vm_end > vma->vm_mm->start_brk; } /* @@ -901,8 +901,8 @@ static inline bool vma_is_initial_stack(const struct vm_area_struct *vma) * its "stack". It's not even well-defined for programs written * languages like Go. */ - return vma->vm_start <= vma->vm_mm->start_stack && - vma->vm_end >= vma->vm_mm->start_stack; + return vma->vm_start <= vma->vm_mm->start_stack && + vma->vm_end >= vma->vm_mm->start_stack; } static inline bool vma_is_temporary_stack(struct vm_area_struct *vma)
After selinux converting to VMA heap check helper, the gcl triggers an execheap SELinux denial, which caused by different check logical. The old from selinux only check VMA range within VMA heap range, and the new will check the intersects between the two ranges, but the corner cases(vm_end=start_brk, brk=vm_start) doesn't be handled correctly. Since commit 11250fd12eb8 ("mm: factor out VMA stack and heap checks") only a function extraction, it seems that the issue introduced from commit 0db0c01b53a1 ("procfs: fix /proc/<pid>/maps heap check"), let's fix above corner cases, meanwhile, corrent the wrong indentation of the stack and heap check helpers. Reported-and-tested-by: Ondrej Mosnacek <omosnace@redhat.com> Closes: https://lore.kernel.org/selinux/CAFqZXNv0SVT0fkOK6neP9AXbj3nxJ61JAY4+zJzvxqJaeuhbFw@mail.gmail.com/ Fixes: 0db0c01b53a1 ("procfs: fix /proc/<pid>/maps heap check") Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> --- include/linux/mm.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)