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=-11.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 B839EC47095 for ; Mon, 5 Oct 2020 17:53:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B4F9207BC for ; Mon, 5 Oct 2020 17:53:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728067AbgJERxL (ORCPT ); Mon, 5 Oct 2020 13:53:11 -0400 Received: from mx2.suse.de ([195.135.220.15]:47786 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727033AbgJERxL (ORCPT ); Mon, 5 Oct 2020 13:53:11 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 1EAA9ADDF; Mon, 5 Oct 2020 17:53:09 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 4D3281E12F3; Mon, 5 Oct 2020 19:53:08 +0200 (CEST) Date: Mon, 5 Oct 2020 19:53:08 +0200 From: Jan Kara To: Jason Gunthorpe Cc: andrew Morton , Daniel Vetter , linux-mm@kvack.org, Hans Verkuil , Jan Kara , Mauro Carvalho Chehab , Mel Gorman , stable@vger.kernel.org, Vlastimil Babka , John Hubbard , DRI Development , LKML , Dan Williams , Linux ARM , linux-samsung-soc , linux-media@vger.kernel.org Subject: Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM Message-ID: <20201005175308.GI4225@quack2.suse.cz> References: <0-v1-447bb60c11dd+174-frame_vec_fix_jgg@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0-v1-447bb60c11dd+174-frame_vec_fix_jgg@nvidia.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 05-10-20 14:38:54, Jason Gunthorpe wrote: > When get_vaddr_frames() does its hacky follow_pfn() loop it should never > be allowed to extract a struct page from a normal VMA. This could allow a > serious use-after-free problem on any kernel memory. > > Restrict this to only work on VMA's with one of VM_IO | VM_PFNMAP > set. This limits the use-after-free problem to only IO memory, which while > still serious, is an improvement. > > Cc: stable@vger.kernel.org > Fixes: 8025e5ddf9c1 ("[media] mm: Provide new get_vaddr_frames() helper") > Signed-off-by: Jason Gunthorpe > --- > mm/frame_vector.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/mm/frame_vector.c b/mm/frame_vector.c > index 10f82d5643b6de..26cb20544b6c37 100644 > --- a/mm/frame_vector.c > +++ b/mm/frame_vector.c > @@ -99,6 +99,10 @@ int get_vaddr_frames(unsigned long start, unsigned int nr_frames, > if (ret >= nr_frames || start < vma->vm_end) > break; > vma = find_vma_intersection(mm, start, start + 1); > + if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) { > + ret = -EINVAL; > + goto out; > + } > } while (vma && vma->vm_flags & (VM_IO | VM_PFNMAP)); Hum, I fail to see how this helps. If vma has no VM_IO or VM_PFNMAP flag, we'd exit the loop (to out: label) anyway due to the loop termination condition and why not return the frames we already have? Furthermore find_vma_intersection() can return NULL which would oops in your check then. What am I missing? Honza > out: > if (locked) > -- > 2.28.0 > -- Jan Kara SUSE Labs, CR 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=-12.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham 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 00721C4363A for ; Mon, 5 Oct 2020 17:54:40 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A3BA0207BC for ; Mon, 5 Oct 2020 17:54:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Zce9qyo+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A3BA0207BC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Nus1iklJbh9J1O1sqDDOo2g0yCceyHIRMxv1Pyg9flQ=; b=Zce9qyo+O33UD+568x+GCW8EO Xgf88iZHDZM2YtuojsUzRxZJrqRpiLxsp1l4aAvF0tyy2IDpy76aDG7z/+kBbs22r4PY3B40yXPY1 52GwQiXavvht6nkPV8ozkI5XWVpnH56nMQuqZgJscHGErLE+NjcH/EjIt9RTOqvGYeDjGWCxsV7ev hfO8UydRFbJEsvhxRmTd6+M940OyjWw/V7TZFgp/+EJhIRI+UD5B/+XVl+HCXUYOyFIsJZ0u50Jo8 qSufNZ5DgAImSTCernpGwJPniWtnmTxSKZL8qXmPChmuyi6Yrr4oH3ptGX/oIqMC8eLygVFq7S4qQ wffBOVniQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPUfj-0004GH-L2; Mon, 05 Oct 2020 17:53:15 +0000 Received: from mx2.suse.de ([195.135.220.15]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPUfg-0004FX-CX for linux-arm-kernel@lists.infradead.org; Mon, 05 Oct 2020 17:53:13 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 1EAA9ADDF; Mon, 5 Oct 2020 17:53:09 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 4D3281E12F3; Mon, 5 Oct 2020 19:53:08 +0200 (CEST) Date: Mon, 5 Oct 2020 19:53:08 +0200 From: Jan Kara To: Jason Gunthorpe Subject: Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM Message-ID: <20201005175308.GI4225@quack2.suse.cz> References: <0-v1-447bb60c11dd+174-frame_vec_fix_jgg@nvidia.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <0-v1-447bb60c11dd+174-frame_vec_fix_jgg@nvidia.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201005_135312_600837_88524B4B X-CRM114-Status: GOOD ( 22.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linux ARM , linux-samsung-soc , Jan Kara , Mauro Carvalho Chehab , Daniel Vetter , DRI Development , LKML , stable@vger.kernel.org, linux-mm@kvack.org, Hans Verkuil , Mel Gorman , John Hubbard , andrew Morton , Dan Williams , Vlastimil Babka , linux-media@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon 05-10-20 14:38:54, Jason Gunthorpe wrote: > When get_vaddr_frames() does its hacky follow_pfn() loop it should never > be allowed to extract a struct page from a normal VMA. This could allow a > serious use-after-free problem on any kernel memory. > > Restrict this to only work on VMA's with one of VM_IO | VM_PFNMAP > set. This limits the use-after-free problem to only IO memory, which while > still serious, is an improvement. > > Cc: stable@vger.kernel.org > Fixes: 8025e5ddf9c1 ("[media] mm: Provide new get_vaddr_frames() helper") > Signed-off-by: Jason Gunthorpe > --- > mm/frame_vector.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/mm/frame_vector.c b/mm/frame_vector.c > index 10f82d5643b6de..26cb20544b6c37 100644 > --- a/mm/frame_vector.c > +++ b/mm/frame_vector.c > @@ -99,6 +99,10 @@ int get_vaddr_frames(unsigned long start, unsigned int nr_frames, > if (ret >= nr_frames || start < vma->vm_end) > break; > vma = find_vma_intersection(mm, start, start + 1); > + if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) { > + ret = -EINVAL; > + goto out; > + } > } while (vma && vma->vm_flags & (VM_IO | VM_PFNMAP)); Hum, I fail to see how this helps. If vma has no VM_IO or VM_PFNMAP flag, we'd exit the loop (to out: label) anyway due to the loop termination condition and why not return the frames we already have? Furthermore find_vma_intersection() can return NULL which would oops in your check then. What am I missing? Honza > out: > if (locked) > -- > 2.28.0 > -- Jan Kara SUSE Labs, CR _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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=-11.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 DE66BC46466 for ; Mon, 5 Oct 2020 17:53:12 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 58F7020B80 for ; Mon, 5 Oct 2020 17:53:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 58F7020B80 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4690389B7D; Mon, 5 Oct 2020 17:53:11 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6DAB389B7D for ; Mon, 5 Oct 2020 17:53:10 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 1EAA9ADDF; Mon, 5 Oct 2020 17:53:09 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 4D3281E12F3; Mon, 5 Oct 2020 19:53:08 +0200 (CEST) Date: Mon, 5 Oct 2020 19:53:08 +0200 From: Jan Kara To: Jason Gunthorpe Subject: Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM Message-ID: <20201005175308.GI4225@quack2.suse.cz> References: <0-v1-447bb60c11dd+174-frame_vec_fix_jgg@nvidia.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <0-v1-447bb60c11dd+174-frame_vec_fix_jgg@nvidia.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linux ARM , linux-samsung-soc , Jan Kara , Mauro Carvalho Chehab , Daniel Vetter , DRI Development , LKML , stable@vger.kernel.org, linux-mm@kvack.org, Hans Verkuil , Mel Gorman , John Hubbard , andrew Morton , Dan Williams , Vlastimil Babka , linux-media@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Mon 05-10-20 14:38:54, Jason Gunthorpe wrote: > When get_vaddr_frames() does its hacky follow_pfn() loop it should never > be allowed to extract a struct page from a normal VMA. This could allow a > serious use-after-free problem on any kernel memory. > > Restrict this to only work on VMA's with one of VM_IO | VM_PFNMAP > set. This limits the use-after-free problem to only IO memory, which while > still serious, is an improvement. > > Cc: stable@vger.kernel.org > Fixes: 8025e5ddf9c1 ("[media] mm: Provide new get_vaddr_frames() helper") > Signed-off-by: Jason Gunthorpe > --- > mm/frame_vector.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/mm/frame_vector.c b/mm/frame_vector.c > index 10f82d5643b6de..26cb20544b6c37 100644 > --- a/mm/frame_vector.c > +++ b/mm/frame_vector.c > @@ -99,6 +99,10 @@ int get_vaddr_frames(unsigned long start, unsigned int nr_frames, > if (ret >= nr_frames || start < vma->vm_end) > break; > vma = find_vma_intersection(mm, start, start + 1); > + if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) { > + ret = -EINVAL; > + goto out; > + } > } while (vma && vma->vm_flags & (VM_IO | VM_PFNMAP)); Hum, I fail to see how this helps. If vma has no VM_IO or VM_PFNMAP flag, we'd exit the loop (to out: label) anyway due to the loop termination condition and why not return the frames we already have? Furthermore find_vma_intersection() can return NULL which would oops in your check then. What am I missing? Honza > out: > if (locked) > -- > 2.28.0 > -- Jan Kara SUSE Labs, CR _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel