All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: <paul@paul-moore.com>, <stephen.smalley.work@gmail.com>,
	<selinux@vger.kernel.org>, <linux-mm@kvack.org>,
	<david@redhat.com>, <peterz@infradead.org>,
	Kefeng Wang <wangkefeng.wang@huawei.com>,
	Ondrej Mosnacek <omosnace@redhat.com>
Subject: [PATCH] mm: fix VMA heap bounds checking
Date: Thu, 7 Dec 2023 23:25:25 +0800	[thread overview]
Message-ID: <20231207152525.2607420-1-wangkefeng.wang@huawei.com> (raw)

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


             reply	other threads:[~2023-12-07 15:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-07 15:25 Kefeng Wang [this message]
2023-12-07 22:16 ` [PATCH] mm: fix VMA heap bounds checking Andrew Morton
2023-12-08  1:20   ` Kefeng Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231207152525.2607420-1-wangkefeng.wang@huawei.com \
    --to=wangkefeng.wang@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=linux-mm@kvack.org \
    --cc=omosnace@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=peterz@infradead.org \
    --cc=selinux@vger.kernel.org \
    --cc=stephen.smalley.work@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.