linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] Revert "selinux: use vma_is_initial_stack() and vma_is_initial_heap()"
       [not found] ` <CAEjxPJ4b2Xcptmi2cJNyh=N=1ky=yfg_wVB1yDLwr8uuhujxew@mail.gmail.com>
@ 2024-08-08 15:48   ` Paul Moore
  2024-08-08 18:54     ` Stephen Smalley
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Moore @ 2024-08-08 15:48 UTC (permalink / raw)
  To: Stephen Smalley
  Cc: Kefeng Wang, Ondrej Mosnacek, selinux, Marc Reisner, david,
	Vlastimil Babka, Liam R . Howlett, Lorenzo Stoakes, linux-mm

On Thu, Aug 8, 2024 at 9:40 AM Stephen Smalley
<stephen.smalley.work@gmail.com> wrote:
>
> On Thu, Aug 8, 2024 at 9:09 AM Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
> >
> > This reverts commit 68df1baf158fddc07b6f0333e4c81fe1ccecd6ff.
> >
> > The selinux only want to check whether the VMA range is within the heap
> > range or not, but vma_is_initial_heap() helper will check the intersection
> > between the two ranges, which leads to some issue, let's turn back to the
> > original validation.
> >
> > Reported-by: Marc Reisner <reisner.marc@gmail.com>
> > Closes: https://lore.kernel.org/all/ZrPmoLKJEf1wiFmM@marcreisner.com/
> > Fixes: 68df1baf158f ("selinux: use vma_is_initial_stack() and vma_is_initial_heap()")
> > Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
>
> I was only going to recommend reverting the change to the heap check
> but in case Paul is fine with a straight revert,
> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>

I was hoping that the mm folks would put together a quick patch to fix
what looks like a problem with the helper, but I'm not sure when that
is going to happen and with other callers I don't want to change the
helper and break a different part of the kernel.  Unfortunately that
leaves us with needing a revert, but like Stephen said, I think
reverting just the heap helper is the right thing to do right now; I
also want to put a comment in there for the next time someone tries to
re-add the vma_is_initial_heap().  Give me some time, I'll have a
patch out for this later today.

> > ---
> >  security/selinux/hooks.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> > index 81fbfa5b80d4..f5805d4b0aec 100644
> > --- a/security/selinux/hooks.c
> > +++ b/security/selinux/hooks.c
> > @@ -3845,10 +3845,13 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
> >         if (default_noexec &&
> >             (prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
> >                 int rc = 0;
> > -               if (vma_is_initial_heap(vma)) {
> > +               if (vma->vm_start >= vma->vm_mm->start_brk &&
> > +                   vma->vm_end <= vma->vm_mm->brk) {
> >                         rc = avc_has_perm(sid, sid, SECCLASS_PROCESS,
> >                                           PROCESS__EXECHEAP, NULL);
> > -               } else if (!vma->vm_file && (vma_is_initial_stack(vma) ||
> > +               } else if (!vma->vm_file &&
> > +                          ((vma->vm_start <= vma->vm_mm->start_stack &&
> > +                            vma->vm_end >= vma->vm_mm->start_stack) ||
> >                             vma_is_stack_for_current(vma))) {
> >                         rc = avc_has_perm(sid, sid, SECCLASS_PROCESS,
> >                                           PROCESS__EXECSTACK, NULL);
> > --
> > 2.41.0

--
paul-moore.com


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

* Re: [PATCH] Revert "selinux: use vma_is_initial_stack() and vma_is_initial_heap()"
  2024-08-08 15:48   ` [PATCH] Revert "selinux: use vma_is_initial_stack() and vma_is_initial_heap()" Paul Moore
@ 2024-08-08 18:54     ` Stephen Smalley
  2024-08-08 20:43       ` Paul Moore
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Smalley @ 2024-08-08 18:54 UTC (permalink / raw)
  To: Paul Moore
  Cc: Kefeng Wang, Ondrej Mosnacek, selinux, Marc Reisner, david,
	Vlastimil Babka, Liam R . Howlett, Lorenzo Stoakes, linux-mm

On Thu, Aug 8, 2024 at 11:48 AM Paul Moore <paul@paul-moore.com> wrote:
>
> On Thu, Aug 8, 2024 at 9:40 AM Stephen Smalley
> <stephen.smalley.work@gmail.com> wrote:
> >
> > On Thu, Aug 8, 2024 at 9:09 AM Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
> > >
> > > This reverts commit 68df1baf158fddc07b6f0333e4c81fe1ccecd6ff.
> > >
> > > The selinux only want to check whether the VMA range is within the heap
> > > range or not, but vma_is_initial_heap() helper will check the intersection
> > > between the two ranges, which leads to some issue, let's turn back to the
> > > original validation.
> > >
> > > Reported-by: Marc Reisner <reisner.marc@gmail.com>
> > > Closes: https://lore.kernel.org/all/ZrPmoLKJEf1wiFmM@marcreisner.com/
> > > Fixes: 68df1baf158f ("selinux: use vma_is_initial_stack() and vma_is_initial_heap()")
> > > Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> >
> > I was only going to recommend reverting the change to the heap check
> > but in case Paul is fine with a straight revert,
> > Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
>
> I was hoping that the mm folks would put together a quick patch to fix
> what looks like a problem with the helper, but I'm not sure when that
> is going to happen and with other callers I don't want to change the
> helper and break a different part of the kernel.  Unfortunately that
> leaves us with needing a revert, but like Stephen said, I think
> reverting just the heap helper is the right thing to do right now; I
> also want to put a comment in there for the next time someone tries to
> re-add the vma_is_initial_heap().  Give me some time, I'll have a
> patch out for this later today.

FWIW, I tossed the reproducer code from Marc Reisner into a branch of
the SELinux testsuite and wrapped it up with an added test to the mmap
tests here:
https://github.com/stephensmalley/selinux-testsuite/tree/execheapregression

Passes with the revert, fails without.
Would need to be modified to be portable to actually be suitable for
inclusion though.


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

* Re: [PATCH] Revert "selinux: use vma_is_initial_stack() and vma_is_initial_heap()"
  2024-08-08 18:54     ` Stephen Smalley
@ 2024-08-08 20:43       ` Paul Moore
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Moore @ 2024-08-08 20:43 UTC (permalink / raw)
  To: Stephen Smalley
  Cc: Kefeng Wang, Ondrej Mosnacek, selinux, Marc Reisner, david,
	Vlastimil Babka, Liam R . Howlett, Lorenzo Stoakes, linux-mm

On Thu, Aug 8, 2024 at 2:54 PM Stephen Smalley
<stephen.smalley.work@gmail.com> wrote:
> On Thu, Aug 8, 2024 at 11:48 AM Paul Moore <paul@paul-moore.com> wrote:
> > On Thu, Aug 8, 2024 at 9:40 AM Stephen Smalley
> > <stephen.smalley.work@gmail.com> wrote:
> > >
> > > On Thu, Aug 8, 2024 at 9:09 AM Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
> > > >
> > > > This reverts commit 68df1baf158fddc07b6f0333e4c81fe1ccecd6ff.
> > > >
> > > > The selinux only want to check whether the VMA range is within the heap
> > > > range or not, but vma_is_initial_heap() helper will check the intersection
> > > > between the two ranges, which leads to some issue, let's turn back to the
> > > > original validation.
> > > >
> > > > Reported-by: Marc Reisner <reisner.marc@gmail.com>
> > > > Closes: https://lore.kernel.org/all/ZrPmoLKJEf1wiFmM@marcreisner.com/
> > > > Fixes: 68df1baf158f ("selinux: use vma_is_initial_stack() and vma_is_initial_heap()")
> > > > Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> > >
> > > I was only going to recommend reverting the change to the heap check
> > > but in case Paul is fine with a straight revert,
> > > Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
> >
> > I was hoping that the mm folks would put together a quick patch to fix
> > what looks like a problem with the helper, but I'm not sure when that
> > is going to happen and with other callers I don't want to change the
> > helper and break a different part of the kernel.  Unfortunately that
> > leaves us with needing a revert, but like Stephen said, I think
> > reverting just the heap helper is the right thing to do right now; I
> > also want to put a comment in there for the next time someone tries to
> > re-add the vma_is_initial_heap().  Give me some time, I'll have a
> > patch out for this later today.
>
> FWIW, I tossed the reproducer code from Marc Reisner into a branch of
> the SELinux testsuite and wrapped it up with an added test to the mmap
> tests here:
> https://github.com/stephensmalley/selinux-testsuite/tree/execheapregression
>
> Passes with the revert, fails without.
> Would need to be modified to be portable to actually be suitable for
> inclusion though.

Thanks Stephen.

FWIW, I think improving this test such that it could be included in
the test suite would be a very good thing to do.

-- 
paul-moore.com


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

end of thread, other threads:[~2024-08-08 20:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20240808130909.1027860-1-wangkefeng.wang@huawei.com>
     [not found] ` <CAEjxPJ4b2Xcptmi2cJNyh=N=1ky=yfg_wVB1yDLwr8uuhujxew@mail.gmail.com>
2024-08-08 15:48   ` [PATCH] Revert "selinux: use vma_is_initial_stack() and vma_is_initial_heap()" Paul Moore
2024-08-08 18:54     ` Stephen Smalley
2024-08-08 20:43       ` Paul Moore

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