From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A5AAC433FE for ; Fri, 10 Sep 2021 09:23:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CEFAA6101A for ; Fri, 10 Sep 2021 09:23:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CEFAA6101A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 34E2B6B0071; Fri, 10 Sep 2021 05:23:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D5D66B0072; Fri, 10 Sep 2021 05:23:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1501D900002; Fri, 10 Sep 2021 05:23:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0200.hostedemail.com [216.40.44.200]) by kanga.kvack.org (Postfix) with ESMTP id F3BD16B0071 for ; Fri, 10 Sep 2021 05:23:53 -0400 (EDT) Received: from smtpin34.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A54331807F641 for ; Fri, 10 Sep 2021 09:23:53 +0000 (UTC) X-FDA: 78571126746.34.0DEB357 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 22ECDD02AF8A for ; Fri, 10 Sep 2021 09:23:52 +0000 (UTC) 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-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-587-TJGfHHnlPQqybDMi4M0qrA-1; Fri, 10 Sep 2021 05:23:51 -0400 X-MC-Unique: TJGfHHnlPQqybDMi4M0qrA-1 Received: by mail-wr1-f70.google.com with SMTP id p18-20020a5d4e12000000b0015940dc586aso293151wrt.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=BA86L5bLKUtqEXTdRxe3CKaPVI763VwVhnnISq2xJshuZovAqQhG+QtOfV/4kHCDW6 GmQIZSWX28Xt62s6IkM19NKa5w4xdTnRScCp58BBHlssTTpgrHGm1Nd3Yump2a3m5tUg WPLv8wyUfXMFhpN5quXQ8NAvlzgvtjO+oUUJmy/x4gh2aftv2rVCllTjboPWmEneQloI MMnDPlaaqLhDf4NRYgMunpib332rj9yUDWdEDlEx0eqZZtfHdvhepZj/70iPu8Qi/kbx 7dVadb7C0Oh9Lk5FWf3d7K5+47xFL4u3cnmAP06180vb/OY0XL90LzVkvH9kz659Wklt 0zFg== X-Gm-Message-State: AOAM532YJggKQieQs7Ac8CeU2uN+1dWjLglfaH2v1bY9dzBVSsxaLDoc rGPQwNM8GLkdRarxSGmCMG7D1fFr0/SSx0PfxGEbs99HPsEnpS5fL1IWDRMxQzZ8AXjcU/U/Myx 4QKHZalRbMfB/h7rKxYFbm++HO5o9gnSG2Hh8tYD+aALYg+5VZuKmqDJK+sk= X-Received: by 2002:adf:e7ca:: with SMTP id e10mr537330wrn.97.1631265830295; Fri, 10 Sep 2021 02:23:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbJtumfWhoeoqWdrbbfX6WGzwZFjWqOeIuwT2t9OUhauNMdOAXqx3T37WZquMUdpxR8rvMgA== 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> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 22ECDD02AF8A X-Stat-Signature: bk8kzepfk8xgym61yspap1bkrxgyy6wg Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JJEvg2H5; spf=none (imf21.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1631265832-823306 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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