On Tue, Oct 22, 2024 at 11:15:18PM +0200, Jann Horn wrote: > On Tue, Oct 22, 2024 at 10:41 PM Lorenzo Stoakes > <lorenzo.stoakes@xxxxxxxxxx> 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@xxxxxxxxxx> > > Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") > > Cc: stable <stable@xxxxxxxxxx> > > Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx> > > Reviewed-by: Jann Horn <jannh@xxxxxxxxxx> Thanks! > > [..] > > -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 Ack > > > > + if (!(old & VM_EXEC)) > > return true; > > > > return false;