Re: [PATCH v3 6/7] selftests/mm: check MADV_PAGEOUT file permissions

From: Sarthak Sharma

Date: Wed Oct 28 2026 - 07:34:56 EST




On 10/19/26 10:42 PM, Gregory Price (Meta) wrote:
> MADV_PAGEOUT only pages out file pages for a caller that owns the file or
> could open it for writing, per can_do_file_pageout(). Any other caller
> gets nothing from a shared file mapping, and only the anonymous COW pages
> from a private one.
>
> main() now also checks once whether MADV_PAGEOUT can unmap a clean page
> of a file in /tmp, where the tests make their files. The tests below skip
> if it cannot, since none of them would show anything.
>
> Check that the owner of a read-only file can page out a clean page of
> it. When started as root, the test hands the file to nobody and drops
> privileges, so that capabilities cannot stand in for ownership and
> nobody need not be able to write to /tmp.
>
> Also check that an unauthorized caller leaves a shared file page mapped,
> and that it pages out the COW page of a private mapping but not the file
> page next to it. These need root to change credentials, and skip if that
> fails. The private mapping check also skips if MADV_PAGEOUT cannot swap.
>
> Signed-off-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
> ---
Thanks for the changes. It looks good to me.

Reviewed-by: Sarthak Sharma <sarthak.sharma@xxxxxxx>