[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAG48ez0oqGgfF-UTOc9eWC_TrZ-pF1Ek_cUjzArxHEsM_TT2gg@mail.gmail.com>
Date: Tue, 22 Oct 2024 23:15:18 +0200
From: Jann Horn <jannh@...gle.com>
To: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>, "Liam R . Howlett" <Liam.Howlett@...cle.com>,
Vlastimil Babka <vbabka@...e.cz>, linux-kernel@...r.kernel.org, linux-mm@...ck.org,
Linus Torvalds <torvalds@...ux-foundation.org>, Peter Xu <peterx@...hat.com>
Subject: Re: [PATCH hotfix 6.12 3/8] mm: refactor map_deny_write_exec()
On Tue, Oct 22, 2024 at 10:41 PM Lorenzo Stoakes
<lorenzo.stoakes@...cle.com> wrote:
> Refactor the map_deny_write_exec() to not unnecessarily require a VMA
> parameter but rather to accept VMA flags parameters, which allows us to use
> this function early in mmap_region() in a subsequent commit.
>
> While we're here, we refactor the function to be more readable and add some
> additional documentation.
>
> Reported-by: Jann Horn <jannh@...gle.com>
> Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails")
> Cc: stable <stable@...nel.org>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
Reviewed-by: Jann Horn <jannh@...gle.com>
[..]
> -static inline bool map_deny_write_exec(struct vm_area_struct *vma, unsigned long vm_flags)
> +static inline bool map_deny_write_exec(unsigned long old, unsigned long new)
> {
> + /* If MDWE is disabled, we have nothing to deny. */
> if (!test_bit(MMF_HAS_MDWE, ¤t->mm->flags))
> return false;
>
> - if ((vm_flags & VM_EXEC) && (vm_flags & VM_WRITE))
> + /* If the new VMA is not executable, we have nothing to deny. */
> + if (!(new & VM_EXEC))
> + return false;
> +
> + /* Under MDWE we absolutely do not accept writably executable... */
> + if (new & VM_WRITE)
> return true;
>
> - if (!(vma->vm_flags & VM_EXEC) && (vm_flags & VM_EXEC))
> + /* ...nor newly executable VMAs. */
nit: maybe clarify this as "nor existing VMAs newly becoming
executable" or something like that
> + if (!(old & VM_EXEC))
> return true;
>
> return false;
Powered by blists - more mailing lists