linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: fix VMA heap bounds checking
@ 2023-12-07 15:25 Kefeng Wang
  2023-12-07 22:16 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Kefeng Wang @ 2023-12-07 15:25 UTC (permalink / raw)
  To: Andrew Morton
  Cc: paul, stephen.smalley.work, selinux, linux-mm, david, peterz,
	Kefeng Wang, Ondrej Mosnacek

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(-)

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)
-- 
2.27.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: fix VMA heap bounds checking
  2023-12-07 15:25 [PATCH] mm: fix VMA heap bounds checking Kefeng Wang
@ 2023-12-07 22:16 ` Andrew Morton
  2023-12-08  1:20   ` Kefeng Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2023-12-07 22:16 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: paul, stephen.smalley.work, selinux, linux-mm, david, peterz,
	Ondrej Mosnacek

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?



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: fix VMA heap bounds checking
  2023-12-07 22:16 ` Andrew Morton
@ 2023-12-08  1:20   ` Kefeng Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Kefeng Wang @ 2023-12-08  1:20 UTC (permalink / raw)
  To: Andrew Morton
  Cc: paul, stephen.smalley.work, selinux, linux-mm, david, peterz,
	Ondrej Mosnacek



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.
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-08  1:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-07 15:25 [PATCH] mm: fix VMA heap bounds checking Kefeng Wang
2023-12-07 22:16 ` Andrew Morton
2023-12-08  1:20   ` Kefeng Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox