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=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 7AD45C4727F for ; Tue, 6 Oct 2020 11:57:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F1332080A for ; Tue, 6 Oct 2020 11:57:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="lLhpfE52" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726164AbgJFL5G (ORCPT ); Tue, 6 Oct 2020 07:57:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726087AbgJFL5F (ORCPT ); Tue, 6 Oct 2020 07:57:05 -0400 Received: from mail-ot1-x341.google.com (mail-ot1-x341.google.com [IPv6:2607:f8b0:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31D02C0613D1 for ; Tue, 6 Oct 2020 04:57:05 -0700 (PDT) Received: by mail-ot1-x341.google.com with SMTP id m11so6393210otk.13 for ; Tue, 06 Oct 2020 04:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0/v0p3FvFQy6vefIiWkN5sABT9yaRl0KmB4aTLtFJ80=; b=lLhpfE52DsBTlXOZaNcfYtajrRM/cDqIwevRSBDcVW4qoPVbzEi7+sihe6YcHp2QOU hnAD2eoXIOk84DvIqJ2RTZpXb49sc13g/2RKsA0kTklQEV+Sykz8QqnvTSECPTErHsRx qsTQaNy+j6UOMtosFQSSws5ErF7y9aC00H4zo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0/v0p3FvFQy6vefIiWkN5sABT9yaRl0KmB4aTLtFJ80=; b=ATCTkonSBL2gmlr598He9SXZ6CfDTaXmXMPFq3S+Ey+DO+V7uKSb4l1oFhz84KwRCB tV+Me4q0iqeXqAPChJ9aQroLPvMEbxDdMx/BaUfMo8B7zZE8jiA/4yfbCLjSbmFBR0E3 R7olxl9ZU0W+g2yg+R5v7aWUIPfQ6EhVxiGOUVogUWEpK07ed3BKpqZMtYTUd1/5Ofvu UX+aFBK4XIaYzDv7pDLwStGOKveC8Kc4AK6I+gGg3jXj7SjlyL6MyIjO/E2gRoAqZs2B ng65oLf06tbUUJ5H8OLK97mrRQK6cKFCL/wmGNXcFgAFJnVpEuAGRS1ypM1HDV4uRSFs /GeA== X-Gm-Message-State: AOAM530BeHqjb/I5ZDOL/aCni0S1tPNBITs5UggC46yAmtBnzszVNr2X y55Jrnn2f2jYhvcMLvLTqzUivdjerls1P06sP4sX5Q== X-Google-Smtp-Source: ABdhPJyMG6+nB6zVd1RDfgIGK4/zu55vJ18yPOXo0KPUU4RdObE/Y3T3eJQEZZwVcpMDmw5VSMtR9OkGz5YHDq9+Jw8= X-Received: by 2002:a05:6830:1c3c:: with SMTP id f28mr2857746ote.188.1601985424516; Tue, 06 Oct 2020 04:57:04 -0700 (PDT) MIME-Version: 1.0 References: <0-v1-447bb60c11dd+174-frame_vec_fix_jgg@nvidia.com> <20201005175308.GI4225@quack2.suse.cz> <20201005175746.GA4734@nvidia.com> In-Reply-To: <20201005175746.GA4734@nvidia.com> From: Daniel Vetter Date: Tue, 6 Oct 2020 13:56:53 +0200 Message-ID: Subject: Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM To: Jason Gunthorpe Cc: Jan Kara , andrew Morton , Linux MM , Hans Verkuil , Mauro Carvalho Chehab , Mel Gorman , stable , Vlastimil Babka , John Hubbard , DRI Development , LKML , Dan Williams , Linux ARM , linux-samsung-soc , "open list:DMA BUFFER SHARING FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 5, 2020 at 7:58 PM Jason Gunthorpe wrote: > > On Mon, Oct 05, 2020 at 07:53:08PM +0200, Jan Kara wrote: > > 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 > > > +++ 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? > > Oh, nothing, you are right. It just didn't read naturally because > hitting the wrong kind of VMA should be an error condition :\ Also follow_pfn checks for this same conditionat already too, so this isn't really stopping anything bad from happening. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch 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=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 1412DC41604 for ; Tue, 6 Oct 2020 11:57:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 30AB02087E for ; Tue, 6 Oct 2020 11:57:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="lLhpfE52" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 30AB02087E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3303F900002; Tue, 6 Oct 2020 07:57:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E0196B005D; Tue, 6 Oct 2020 07:57:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21CE8900002; Tue, 6 Oct 2020 07:57:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0253.hostedemail.com [216.40.44.253]) by kanga.kvack.org (Postfix) with ESMTP id E90CA6B005C for ; Tue, 6 Oct 2020 07:57:06 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 758153634 for ; Tue, 6 Oct 2020 11:57:06 +0000 (UTC) X-FDA: 77341349652.20.coal24_400d1dc271c6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 5099A180C07AB for ; Tue, 6 Oct 2020 11:57:06 +0000 (UTC) X-HE-Tag: coal24_400d1dc271c6 X-Filterd-Recvd-Size: 5193 Received: from mail-ot1-f66.google.com (mail-ot1-f66.google.com [209.85.210.66]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Tue, 6 Oct 2020 11:57:05 +0000 (UTC) Received: by mail-ot1-f66.google.com with SMTP id q21so11995176ota.8 for ; Tue, 06 Oct 2020 04:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0/v0p3FvFQy6vefIiWkN5sABT9yaRl0KmB4aTLtFJ80=; b=lLhpfE52DsBTlXOZaNcfYtajrRM/cDqIwevRSBDcVW4qoPVbzEi7+sihe6YcHp2QOU hnAD2eoXIOk84DvIqJ2RTZpXb49sc13g/2RKsA0kTklQEV+Sykz8QqnvTSECPTErHsRx qsTQaNy+j6UOMtosFQSSws5ErF7y9aC00H4zo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0/v0p3FvFQy6vefIiWkN5sABT9yaRl0KmB4aTLtFJ80=; b=rKt3askLOPRj5I/zya2ySlS9J0u9hVEILAqfQIXd78DJMJUMwQMDfNTUJlNuAOw9+p 1ZcDacQr7NRRQa9IG5HczdtnjunuXYpu2hg3Q+p1ooF2CpQzwC7p19Jo7l0qhsfT/cMu NWcBTC6igtUhVp0xMVViGwbhzrLaEr0ywrUdE/lCL8WEC2eMaW++JzJSM2Y4Hdd26q7D Jk6XhHZ/1AFXNTOTIspZzUgQyMVw85p+yXWvG90XA01bBVZ/fvVHWG/KUrcs4GXmgDOD 5UMXRvrC0Ace5rW87HeG2wmAPOBYNz6kVhorvDtXX7axkEK2Eng/kn1S0ZKj4ilSV2w4 5MKw== X-Gm-Message-State: AOAM53098UOIjDV1Sh/Ua/azn6nPY9h9QUR4BgObhWXj536sglTilKvZ 9DuPc7RsrantP+qD9/dFwp7Nykiz7CO2eHFS6gcOAg== X-Google-Smtp-Source: ABdhPJyMG6+nB6zVd1RDfgIGK4/zu55vJ18yPOXo0KPUU4RdObE/Y3T3eJQEZZwVcpMDmw5VSMtR9OkGz5YHDq9+Jw8= X-Received: by 2002:a05:6830:1c3c:: with SMTP id f28mr2857746ote.188.1601985424516; Tue, 06 Oct 2020 04:57:04 -0700 (PDT) MIME-Version: 1.0 References: <0-v1-447bb60c11dd+174-frame_vec_fix_jgg@nvidia.com> <20201005175308.GI4225@quack2.suse.cz> <20201005175746.GA4734@nvidia.com> In-Reply-To: <20201005175746.GA4734@nvidia.com> From: Daniel Vetter Date: Tue, 6 Oct 2020 13:56:53 +0200 Message-ID: Subject: Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM To: Jason Gunthorpe Cc: Jan Kara , andrew Morton , Linux MM , Hans Verkuil , Mauro Carvalho Chehab , Mel Gorman , stable , Vlastimil Babka , John Hubbard , DRI Development , LKML , Dan Williams , Linux ARM , linux-samsung-soc , "open list:DMA BUFFER SHARING FRAMEWORK" Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Oct 5, 2020 at 7:58 PM Jason Gunthorpe wrote: > > On Mon, Oct 05, 2020 at 07:53:08PM +0200, Jan Kara wrote: > > 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 > > > +++ 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? > > Oh, nothing, you are right. It just didn't read naturally because > hitting the wrong kind of VMA should be an error condition :\ Also follow_pfn checks for this same conditionat already too, so this isn't really stopping anything bad from happening. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch 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=-10.5 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 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 218D7C4363D for ; Tue, 6 Oct 2020 11:58: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 AEFCE2080A for ; Tue, 6 Oct 2020 11:58: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="SCPKjGjR"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="lLhpfE52" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AEFCE2080A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch 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:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jeAnUAT1b0tRHwbYyBujsr1Ey0S9relOWpE1ks56QkA=; b=SCPKjGjRU0XxunDoyQyToljMh Xrk3tZoxOsj2yYKhYfEUJrVmiWkLZixZx/LdcpvizOCIMKfY78Ul/FzydotLIHyt3ejNgxL2q75CT rRH6dhZ678I9dqAWu+NId2eg6qnRb0ml8sbPIsgZtv6PRQJ9alXnlQd9/ddLtiSL/aMiZvbRd1Hm3 WMvNJ/Gb2MDBNlITwhwul1hefgRrw7I/rli8uDtCQDIvkQ+OWBmJ+XFomLk27D/6XUe6ipjTfLwbi PLT7LiZC9J0T+9tnT8sQ+M8mKVr719M18/t6kv6fOWOlB/7Zk4gnT4ut6hWFHJs/AIohZ8WVYWML5 joTqAMqOA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPlag-00075n-H7; Tue, 06 Oct 2020 11:57:10 +0000 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kPlae-00074r-AN for linux-arm-kernel@lists.infradead.org; Tue, 06 Oct 2020 11:57:09 +0000 Received: by mail-ot1-x341.google.com with SMTP id s66so12020104otb.2 for ; Tue, 06 Oct 2020 04:57:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0/v0p3FvFQy6vefIiWkN5sABT9yaRl0KmB4aTLtFJ80=; b=lLhpfE52DsBTlXOZaNcfYtajrRM/cDqIwevRSBDcVW4qoPVbzEi7+sihe6YcHp2QOU hnAD2eoXIOk84DvIqJ2RTZpXb49sc13g/2RKsA0kTklQEV+Sykz8QqnvTSECPTErHsRx qsTQaNy+j6UOMtosFQSSws5ErF7y9aC00H4zo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0/v0p3FvFQy6vefIiWkN5sABT9yaRl0KmB4aTLtFJ80=; b=X2mR4vCf/ilGUSAIxcc+3a7KVOZTFVVTqFD01/vycdBQb1EnIv42lNyNwdqq5WPFYx +t/3FStMF0dD/rtj7+JSIpaaGjAq8QWTB9FB9zHXencYxej6HSrZn33YVxuIkUJe693B gRLYuCTC4hxmjKlE0kNAHv63NNyFqjaleyHT30uGbQz8hzM5KjLm5bnLmn/hbdMuqRo5 zkTvYYmZyTyq6Wdlv01VBJkfnl5bAxNDz6qSGVF0dC/B/9cl9qnMVuibxtAwH1fYNDMm v3uJ4I2kFtSz699kzpA1glrjpDd0R2ZDXVK4QO0NrX5FjmiU2+nqEPqnAqi3La4Kiob2 6m6Q== X-Gm-Message-State: AOAM532pzI6ti7S9mOIzv4d0JzhHZQ7EbxCp8U8fwBpFFBRUaR1qCorG ZxwZfqMnbEOs7q5ezhwFJ/NmrIilLrQHdauFcTSydg== X-Google-Smtp-Source: ABdhPJyMG6+nB6zVd1RDfgIGK4/zu55vJ18yPOXo0KPUU4RdObE/Y3T3eJQEZZwVcpMDmw5VSMtR9OkGz5YHDq9+Jw8= X-Received: by 2002:a05:6830:1c3c:: with SMTP id f28mr2857746ote.188.1601985424516; Tue, 06 Oct 2020 04:57:04 -0700 (PDT) MIME-Version: 1.0 References: <0-v1-447bb60c11dd+174-frame_vec_fix_jgg@nvidia.com> <20201005175308.GI4225@quack2.suse.cz> <20201005175746.GA4734@nvidia.com> In-Reply-To: <20201005175746.GA4734@nvidia.com> From: Daniel Vetter Date: Tue, 6 Oct 2020 13:56:53 +0200 Message-ID: Subject: Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM To: Jason Gunthorpe X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201006_075708_494184_7D5A40F6 X-CRM114-Status: GOOD ( 25.35 ) 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 , John Hubbard , DRI Development , LKML , stable , Linux MM , Hans Verkuil , Mel Gorman , andrew Morton , Dan Williams , Vlastimil Babka , "open list:DMA BUFFER SHARING FRAMEWORK" 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, Oct 5, 2020 at 7:58 PM Jason Gunthorpe wrote: > > On Mon, Oct 05, 2020 at 07:53:08PM +0200, Jan Kara wrote: > > 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 > > > +++ 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? > > Oh, nothing, you are right. It just didn't read naturally because > hitting the wrong kind of VMA should be an error condition :\ Also follow_pfn checks for this same conditionat already too, so this isn't really stopping anything bad from happening. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ 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=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 617DCC4727E for ; Tue, 6 Oct 2020 11:57:07 +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 79DB72087E for ; Tue, 6 Oct 2020 11:57:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="lLhpfE52" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 79DB72087E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch 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 9CD0989C03; Tue, 6 Oct 2020 11:57:05 +0000 (UTC) Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4708789C9C for ; Tue, 6 Oct 2020 11:57:05 +0000 (UTC) Received: by mail-ot1-x343.google.com with SMTP id a2so11984491otr.11 for ; Tue, 06 Oct 2020 04:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0/v0p3FvFQy6vefIiWkN5sABT9yaRl0KmB4aTLtFJ80=; b=lLhpfE52DsBTlXOZaNcfYtajrRM/cDqIwevRSBDcVW4qoPVbzEi7+sihe6YcHp2QOU hnAD2eoXIOk84DvIqJ2RTZpXb49sc13g/2RKsA0kTklQEV+Sykz8QqnvTSECPTErHsRx qsTQaNy+j6UOMtosFQSSws5ErF7y9aC00H4zo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0/v0p3FvFQy6vefIiWkN5sABT9yaRl0KmB4aTLtFJ80=; b=jCAVTDjXHxfp/LY8wle6fEl8W670UUig1S+XHRrHJ1LNj+BUxZJIM+TfvCOzHUvxJ3 0k8dgaQ5wv4DfRmXJ8N9zdDgHX4UBCz2pR1Ee+3f4aESnQpW9tFT20UXuRzHChut8xTC /WVw7beoltJF/5XJRiX0N9wtnM3L9OGxReVPsPOQT8dyODh+sHjCYsFfKaIf8moNIhTE +rh/GXpx5qgUeb48dw4o+TOxXLn0iE4q8hJ2OO9cTJfegM+qlu/OP76j4QGiWbETQI+5 d0vMlSKyQnK4CX8dYVwvGFp9JFGu5JMEdlqm8iNEbf9ac4QBTVPNcoh0cFeKqGOhIOcK e9cw== X-Gm-Message-State: AOAM530e62Iosf9cVXDc1kCEOiuiEHX5YVtkN3ERBEDl4++qL6+W6rZE GzJHhR56+x9K/mPEfQPQPM/awk4ubAQ77CADIaFWHA== X-Google-Smtp-Source: ABdhPJyMG6+nB6zVd1RDfgIGK4/zu55vJ18yPOXo0KPUU4RdObE/Y3T3eJQEZZwVcpMDmw5VSMtR9OkGz5YHDq9+Jw8= X-Received: by 2002:a05:6830:1c3c:: with SMTP id f28mr2857746ote.188.1601985424516; Tue, 06 Oct 2020 04:57:04 -0700 (PDT) MIME-Version: 1.0 References: <0-v1-447bb60c11dd+174-frame_vec_fix_jgg@nvidia.com> <20201005175308.GI4225@quack2.suse.cz> <20201005175746.GA4734@nvidia.com> In-Reply-To: <20201005175746.GA4734@nvidia.com> From: Daniel Vetter Date: Tue, 6 Oct 2020 13:56:53 +0200 Message-ID: Subject: Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM To: Jason Gunthorpe 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 , John Hubbard , DRI Development , LKML , stable , Linux MM , Hans Verkuil , Mel Gorman , andrew Morton , Dan Williams , Vlastimil Babka , "open list:DMA BUFFER SHARING FRAMEWORK" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Mon, Oct 5, 2020 at 7:58 PM Jason Gunthorpe wrote: > > On Mon, Oct 05, 2020 at 07:53:08PM +0200, Jan Kara wrote: > > 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 > > > +++ 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? > > Oh, nothing, you are right. It just didn't read naturally because > hitting the wrong kind of VMA should be an error condition :\ Also follow_pfn checks for this same conditionat already too, so this isn't really stopping anything bad from happening. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel