On Thu, Sep 24, 2026 at 02:00:18PM -0400, Gregory Price wrote: > On Thu, Sep 17, 2026 at 05:22:14PM +0100, Lorenzo Stoakes (ARM) wrote: > > When a user requests an mmap_action be performed in mmap_prepare, this > > involves populating the VMA range with data. > > > > However, if the VMA is mergeable, it might then mistakenly be merged with > > another VMA without having populated the range. > > > > Every mmap action currently available sets VMA flags such that the VMA > > cannot be merged. > > > > However, to ensure that no future mmap action falls foul of this, assert > > that this is the case upon mmap_prepare validation. > > > > Signed-off-by: Lorenzo Stoakes (ARM) <[email protected]> > > --- > > mm/vma.c | 9 +++++++++ > > 1 file changed, 9 insertions(+) > > > > diff --git a/mm/vma.c b/mm/vma.c > > index d6ed10cefc8f..62f2ce1ad5a1 100644 > > --- a/mm/vma.c > > +++ b/mm/vma.c > > @@ -2809,6 +2809,15 @@ static int mmap_validate(unsigned long prev_start, > > unsigned long prev_end, > > int mmap_prepare_validate(const struct vm_area_desc *prev_desc, > > const struct vm_area_desc *desc) > > { > > + /* > > + * It is not valid to execute mmap actions for VMAs which can be merged, > > + * as any such merge would leave portions of the mapping incorrectly > > + * unmapped. > > + */ > > + if (vma_flags_can_merge(&desc->vma_flags) && > > + WARN_ON_ONCE(desc->action.type != MMAP_NOTHING)) > > + return -EINVAL; > > + > > If you wanted to make this unit-testable, you could pull it out into a > separate function: > > static bool mmap_action_is_valid(const struct vm_area_desc *desc) > { > return desc->action.type == MMAP_NOTHING || > !vma_flags_can_merge(&desc->vma_flags); > } > > then write: > > if (WARN_ON_ONCE(!mmap_action_is_valid(desc))) > return -EINVAL; > > And you can write a unit test directly against mmap_action_is_valid
You mean to isolate this check specifically? All of the functions in vma.c are unit-testable in the userland VMA tests, obviously here you'd be testing further stuff but you could certainly assert a mergeable VMA specifying an action should result in an error there. I'm also keen not to proliferate two many 'kinds' of validation. As mmap_validate() checks pretty much everything BUT the action check, and it has to work across mmap_prepare and mmap hooks. So the idea here is we put the mmap_prepare-specific stuff in mmap_prepare_validate() and the shared stuff in mmap_validate(). And already the stuff that can be validated just against flags lives in mmap_validate_vma_flags() so that is itself separated out nicely. > > otherwise > > Reviewed-by: Gregory Price (Meta) <[email protected]> Thanks! -- Cheers, Lorenzo
