Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1285697pxb; Fri, 10 Sep 2021 02:25:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2ZZUrReiP/e4O1zzzz9X4OYp+//J4R2UoRYPYpiUnjKT022x3t01IEx4EziXcyORlR2L4 X-Received: by 2002:a05:6e02:1ca9:: with SMTP id x9mr5622699ill.164.1631265909531; Fri, 10 Sep 2021 02:25:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631265909; cv=none; d=google.com; s=arc-20160816; b=ViNV5O+a02P+/R+3QOboRRpHm2N5OWyse725pNWsM0qrPU660kCSBH6x/z5koQs2Q/ b9JxIpU8rjCj8IJ8qIUiasDlcAO18hD0wX7l/U0/0Dtf/7P40H4OxJT6zRUfdPPWTFEl KH9LijGKfMVm2KrjOEf7uKEd3n8/E534ESkWm8PZnIpnLr1DED3ttEx+8XUoPUq1ng+R IpNf5vOt/KKjvtlLawPDCIiD+/aMR2aLdoSDMkt2Ae0DyhlEaWRHl8+rVU750VFzmQYy 2DI5FI2xNwlDL23s8C1jCK6w7hAix/RDDINrn8ShsBuwkRbfNNa3mevQ8VDhLK33dbya 9vgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-signature; bh=vrslVFgCV0A1ASGIKU12boBiWPC4TLJ7XoCjGrBTCz8=; b=XY9HCGDr5RjKjSeBAzSYLrG87dp2xZYfRoUijT6Gpl1/9NTRp5nXdBciI7vL5bgy/s j/a4svLoU2HS92Q9i8lAFIazocxw6NfEJrXyfeilSrtFYoF/kZuStYhSGEQ7MOPgN11S g7bBAmQt3NqzVRQHX8Aosym26kSeKHjAtuEi0E3mIRw9qvzmH9MNphe1u5dHwyoyRT37 s1b+Ez/AQZaTt2uZ7Zhq6YhDND2ftw/mh6tnDGmpv9Y+lupdNXTnmgP1NxBya8gG8A/I WccjgCmblS0uEWjmBzCbE8rPMFI2PMPG1YowCnlBCtE2PO1sn8pRPCQjkX6XsrktgwKl tIdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JJEvg2H5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g4si4647313ilq.142.2021.09.10.02.24.57; Fri, 10 Sep 2021 02:25:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JJEvg2H5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232078AbhIJJZE (ORCPT + 99 others); Fri, 10 Sep 2021 05:25:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31100 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231916AbhIJJZD (ORCPT ); Fri, 10 Sep 2021 05:25:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631265832; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vrslVFgCV0A1ASGIKU12boBiWPC4TLJ7XoCjGrBTCz8=; b=JJEvg2H5+TLjA9WWSA96xgLOShSki5LRRV51vAw4FkeJKk9aTbTXTBID0YKSTaMdkL8KzI BPtKEbJeaWWq7p6ohU2BNeRphgDq2X0pznRgjwlRUrIO/SY0O7d/DukENTt+QJWaFJ5kJA 6DPIYQTiZsK+QmEV2eV3+QX/QzLoWik= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-584-EpoP7FQFOV67SySPaiJZ1Q-1; Fri, 10 Sep 2021 05:23:51 -0400 X-MC-Unique: EpoP7FQFOV67SySPaiJZ1Q-1 Received: by mail-wm1-f71.google.com with SMTP id c4-20020a1c9a04000000b002e864b7edd1so548778wme.6 for ; Fri, 10 Sep 2021 02:23:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=vrslVFgCV0A1ASGIKU12boBiWPC4TLJ7XoCjGrBTCz8=; b=apILDfII/dngz3BFmQ1h5/hhQj8/gLNcOX1DeZvjXKIA5ZSBagk5MO5zGoM3L1KjdN Y7hKqGs6F6XWxrKkAQmosAd9BQIIih3mBD2cqf0B5IsyiYKtk2iCt6cTwmIWpBPqY1fL zZYvWhsJVHvljUwfufVsB/N1tHcbF5ayzsCl1ztI7B5wgwvj7B1xznIjqJOX6/DfvhiC vC2iy1R2haRsk/LCqRjc6vel/MLW6JtEhWqWfnAleNS4uVbnPShr2iO/RrhI25P8tZEE pdvjGJNLUp1zkBntvIuZfL3OCSLkogjjWMJ/iCc/Yxqvza9zskPuSpSN0hAd15Y8Y2oH hHTg== X-Gm-Message-State: AOAM533n5UT7AvrxRfcR0UdzWFCvvHle8wLzeSD4B8Z8KHEYii/8ahDK hRF1syr84gsduGPgsylhqVOMdukcpLFKcqbupnrDZv9jqrX+wJsmrxWKloGqPEKlzlfg9cCAi6h +NnLmSnDK3KogSUDeHPge269l X-Received: by 2002:adf:e7ca:: with SMTP id e10mr537328wrn.97.1631265830262; Fri, 10 Sep 2021 02:23:50 -0700 (PDT) X-Received: by 2002:adf:e7ca:: with SMTP id e10mr537307wrn.97.1631265829997; Fri, 10 Sep 2021 02:23:49 -0700 (PDT) Received: from [192.168.3.132] (p5b0c600c.dip0.t-ipconnect.de. [91.12.96.12]) by smtp.gmail.com with ESMTPSA id p5sm4479649wrd.25.2021.09.10.02.23.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Sep 2021 02:23:49 -0700 (PDT) Subject: Re: [PATCH RFC 6/9] s390/pci_mmio: fully validate the VMA before calling follow_pte() To: Niklas Schnelle , linux-kernel@vger.kernel.org Cc: linux-s390@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org References: <20210909145945.12192-1-david@redhat.com> <20210909145945.12192-7-david@redhat.com> <82d683ec361245e1879b3f14492cdd5c41957e52.camel@linux.ibm.com> From: David Hildenbrand Organization: Red Hat Message-ID: Date: Fri, 10 Sep 2021 11:23:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <82d683ec361245e1879b3f14492cdd5c41957e52.camel@linux.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10.09.21 10:22, Niklas Schnelle wrote: > On Thu, 2021-09-09 at 16:59 +0200, David Hildenbrand wrote: >> We should not walk/touch page tables outside of VMA boundaries when >> holding only the mmap sem in read mode. Evil user space can modify the >> VMA layout just before this function runs and e.g., trigger races with >> page table removal code since commit dd2283f2605e ("mm: mmap: zap pages >> with read mmap_sem in munmap"). >> >> find_vma() does not check if the address is >= the VMA start address; >> use vma_lookup() instead. >> >> Fixes: dd2283f2605e ("mm: mmap: zap pages with read mmap_sem in munmap") >> Signed-off-by: David Hildenbrand >> --- >> arch/s390/pci/pci_mmio.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/arch/s390/pci/pci_mmio.c b/arch/s390/pci/pci_mmio.c >> index ae683aa623ac..c5b35ea129cf 100644 >> --- a/arch/s390/pci/pci_mmio.c >> +++ b/arch/s390/pci/pci_mmio.c >> @@ -159,7 +159,7 @@ SYSCALL_DEFINE3(s390_pci_mmio_write, unsigned long, mmio_addr, >> >> mmap_read_lock(current->mm); >> ret = -EINVAL; >> - vma = find_vma(current->mm, mmio_addr); >> + vma = vma_lookup(current->mm, mmio_addr); >> if (!vma) >> goto out_unlock_mmap; >> if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) >> @@ -298,7 +298,7 @@ SYSCALL_DEFINE3(s390_pci_mmio_read, unsigned long, mmio_addr, >> >> mmap_read_lock(current->mm); >> ret = -EINVAL; >> - vma = find_vma(current->mm, mmio_addr); >> + vma = vma_lookup(current->mm, mmio_addr); >> if (!vma) >> goto out_unlock_mmap; >> if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) > > Oh wow great find thanks! If I may say so these are not great function > names. Looking at the code vma_lookup() is inded find_vma() plus the > check that the looked up address is indeed inside the vma. > IIRC, vma_lookup() was introduced fairly recently. Before that, this additional check was open coded (and still are in some instances). It's confusing, I agree. > I think this is pretty independent of the rest of the patches, so do > you want me to apply this patch independently or do you want to wait > for the others? Sure, please go ahead and apply independently. It'd be great if you could give it a quick sanity test, although I don't expect surprises -- unfortunately, the environment I have easily at hand is not very well suited (#cpu, #mem, #disk ...) for anything that exceeds basic compile tests (and even cross-compiling is significantly faster ...). > > In any case: > > Reviewed-by: Niklas Schnelle > Thanks! -- Thanks, David / dhildenb