[PATCH hotfix 6.12 v2 4/8] mm: resolve faulty mmap_region() error path behaviour
Lorenzo Stoakes
lorenzo.stoakes at oracle.com
Mon Oct 28 14:28:14 PDT 2024
On Mon, Oct 28, 2024 at 09:05:33PM +0000, Mark Brown wrote:
> On Mon, Oct 28, 2024 at 08:43:08PM +0000, Lorenzo Stoakes wrote:
>
> > +/*
> > + * We check VMA flag validity early in the mmap() process, however this can
> > + * cause issues for arm64 when using MTE, which requires that it be used with
> > + * shmem and in this instance and only then is VM_MTE_ALLOWED set permitting
> > + * this operation.
> > + *
> > + * To avoid having to tear down a partially complete mapping we do this ahead of
> > + * time.
> > + */
> > +static vm_flags_t arch_adjust_flags(struct file *file, vm_flags_t vm_flags)
> > +{
> > + if (!IS_ENABLED(CONFIG_ARM64))
> > + return vm_flags;
> > +
> > + if (shmem_file(file))
> > + return vm_flags | VM_MTE_ALLOWED;
> > +}
>
> This doesn't build:
>
> mm/mmap.c:1595:1: error: non-void function does not return a value in all control paths [-Werror,-Wreturn-type]
> 1595 | }
> | ^
Doh that'll teach me for rushing this...
>
> with that corrected:
>
> diff --git a/mm/mmap.c b/mm/mmap.c
> index d1ab4301c671..cea051c5fef3 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -1587,11 +1587,10 @@ static unsigned long __mmap_region(struct file *file, unsigned long addr,
> */
> static vm_flags_t arch_adjust_flags(struct file *file, vm_flags_t vm_flags)
> {
> - if (!IS_ENABLED(CONFIG_ARM64))
> - return vm_flags;
> + if (IS_ENABLED(CONFIG_ARM64) && shmem_file(file))
> + vm_flags |= VM_MTE_ALLOWED;
>
> - if (shmem_file(file))
> - return vm_flags | VM_MTE_ALLOWED;
> + return vm_flags;
> }
>
> unsigned long mmap_region(struct file *file, unsigned long addr,
>
> the relevant tests all pass for me.
>
> Tested-by: Mark Brown <broonie at kernel.org>
Thanks!
>
> I'd have expected arch_adjust_flags() to be something overridden by the
> arch headers (probably like arch_calc_vm_prot_bits() and friends), but
> if this is juat a short lived fix it's probably not worth the trouble.
Yeah this is just a sample solution that I had put together when Linus
suggested a sensible alternative which I'll code up...
Good to confirm this is definitely the issue thanks for testing!
More information about the linux-arm-kernel
mailing list