lkml.org 
[lkml]   [2023]   [Apr]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] mm/gup: disallow GUP writing to file-backed mappings by default
On Sat, Apr 22, 2023 at 02:37:05PM +0100, Lorenzo Stoakes wrote:
> @@ -959,16 +959,46 @@ static int faultin_page(struct vm_area_struct *vma,
> return 0;
> }
>
> +/*
> + * Writing to file-backed mappings using GUP is a fundamentally broken operation
> + * as kernel write access to GUP mappings may not adhere to the semantics
> + * expected by a file system.
> + *
> + * In most instances we disallow this broken behaviour, however there are some
> + * exceptions to this enforced here.
> + */
> +static inline bool can_write_file_mapping(struct vm_area_struct *vma,
> + unsigned long gup_flags)
> +{
> + struct file *file = vma->vm_file;
> +
> + /* If we aren't pinning then no problematic write can occur. */
> + if (!(gup_flags & (FOLL_GET | FOLL_PIN)))
> + return true;
> +
> + /* Special mappings should pose no problem. */
> + if (!file)
> + return true;
> +
> + /* Has the caller explicitly indicated this case is acceptable? */
> + if (gup_flags & FOLL_ALLOW_BROKEN_FILE_MAPPING)
> + return true;
> +
> + /* shmem and hugetlb mappings do not have problematic semantics. */
> + return vma_is_shmem(vma) || is_file_hugepages(file);

Can this be generalized to any fs that doesn't have vm_ops->page_mkwrite()?

--
Kiryl Shutsemau / Kirill A. Shutemov

\
 
 \ /
  Last update: 2023-04-24 14:04    [W:0.110 / U:0.460 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site