Re: [PATCH hotfix 6.12 v2 4/8] mm: resolve faulty mmap_region() error path behaviour
From: Mark Brown
Date: Mon Oct 28 2024 - 17:05:48 EST
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 | }
| ^
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@xxxxxxxxxx>
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.
Attachment:
signature.asc
Description: PGP signature