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