Re: [PATCH mm-unstable v1 05/20] mm: add early FAULT_FLAG_WRITE consistency checks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: David Hildenbrand <david@xxxxxxxxxx>, linux-kernel@xxxxxxxxxxxxxxx
- Subject: Re: [PATCH mm-unstable v1 05/20] mm: add early FAULT_FLAG_WRITE consistency checks
- From: Vlastimil Babka <vbabka@xxxxxxx>
- Date: Fri, 18 Nov 2022 18:03:00 +0100
- Cc: x86@xxxxxxxxxx, linux-alpha@xxxxxxxxxxxxxxx, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, linux-ia64@xxxxxxxxxxxxxxx, linux-mips@xxxxxxxxxxxxxxx, linuxppc-dev@xxxxxxxxxxxxxxxx, sparclinux@xxxxxxxxxxxxxxx, linux-um@xxxxxxxxxxxxxxxxxxx, etnaviv@xxxxxxxxxxxxxxxxxxxxx, dri-devel@xxxxxxxxxxxxxxxxxxxxx, linux-samsung-soc@xxxxxxxxxxxxxxx, linux-rdma@xxxxxxxxxxxxxxx, linux-media@xxxxxxxxxxxxxxx, linux-fsdevel@xxxxxxxxxxxxxxx, linux-mm@xxxxxxxxx, linux-perf-users@xxxxxxxxxxxxxxx, linux-security-module@xxxxxxxxxxxxxxx, linux-kselftest@xxxxxxxxxxxxxxx, Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>, Jason Gunthorpe <jgg@xxxxxxxx>, John Hubbard <jhubbard@xxxxxxxxxx>, Peter Xu <peterx@xxxxxxxxxx>, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>, Andrea Arcangeli <aarcange@xxxxxxxxxx>, Hugh Dickins <hughd@xxxxxxxxxx>, Nadav Amit <namit@xxxxxxxxxx>, Matthew Wilcox <willy@xxxxxxxxxxxxx>, Mike Kravetz <mike.kravetz@xxxxxxxxxx>, Muchun Song <songmuchun@xxxxxxxxxxxxx>, Shuah Khan <shuah@xxxxxxxxxx>, Lucas Stach <l.stach@xxxxxxxxxxxxxx>, David Airlie <airlied@xxxxxxxxx>, Oded Gabbay <ogabbay@xxxxxxxxxx>, Arnd Bergmann <arnd@xxxxxxxx>, Christoph Hellwig <hch@xxxxxxxxxxxxx>, Alex Williamson <alex.williamson@xxxxxxxxxx>
- In-reply-to: <20221116102659.70287-6-david@redhat.com>
- References: <20221116102659.70287-1-david@redhat.com> <20221116102659.70287-6-david@redhat.com>
- User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2
On 11/16/22 11:26, David Hildenbrand wrote:
> Let's catch abuse of FAULT_FLAG_WRITE early, such that we don't have to
> care in all other handlers and might get "surprises" if we forget to do
> so.
>
> Write faults without VM_MAYWRITE don't make any sense, and our
> maybe_mkwrite() logic could have hidden such abuse for now.
>
> Write faults without VM_WRITE on something that is not a COW mapping is
> similarly broken, and e.g., do_wp_page() could end up placing an
> anonymous page into a shared mapping, which would be bad.
>
> This is a preparation for reliable R/O long-term pinning of pages in
> private mappings, whereby we want to make sure that we will never break
> COW in a read-only private mapping.
>
> Signed-off-by: David Hildenbrand <david@xxxxxxxxxx>
Reviewed-by: Vlastimil Babka <vbabka@xxxxxxx>
> ---
> mm/memory.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/mm/memory.c b/mm/memory.c
> index e014435a87db..c4fa378ec2a0 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -5170,6 +5170,14 @@ static vm_fault_t sanitize_fault_flags(struct vm_area_struct *vma,
> */
> if (!is_cow_mapping(vma->vm_flags))
> *flags &= ~FAULT_FLAG_UNSHARE;
> + } else if (*flags & FAULT_FLAG_WRITE) {
> + /* Write faults on read-only mappings are impossible ... */
> + if (WARN_ON_ONCE(!(vma->vm_flags & VM_MAYWRITE)))
> + return VM_FAULT_SIGSEGV;
> + /* ... and FOLL_FORCE only applies to COW mappings. */
> + if (WARN_ON_ONCE(!(vma->vm_flags & VM_WRITE) &&
> + !is_cow_mapping(vma->vm_flags)))
> + return VM_FAULT_SIGSEGV;
> }
> return 0;
> }
[Index of Archives]
[Linux Kernel]
[Sparc Linux]
[DCCP]
[Linux ARM]
[Yosemite News]
[Linux SCSI]
[Linux x86_64]
[Linux for Ham Radio]