Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3423126pxu; Sun, 11 Oct 2020 09:09:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfgbC4Ru+qO4tlCo4L7JX+VzH8XzsbSIRn/ItZNtdz+mcVayL10FWQ5hgnkNE/QLfeXrKl X-Received: by 2002:a05:6402:373:: with SMTP id s19mr10052398edw.140.1602432557669; Sun, 11 Oct 2020 09:09:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602432557; cv=none; d=google.com; s=arc-20160816; b=QX/iGLfd7uxgmPXebMAnxppi3BM3/Ckn1klS5rTdhkxOyeZPP4EmlUzjP6q0UP5jGS tkGtahxHYvhWk/CiPG0jLz1W010X5XIG9r5LubEaQp92pher6eFSX1l8audpZl/Ynjzw CGJKSQO6fx9Sspcdb1AYr5008KkMlKq+Zu9+0+9Bz7aac41TtqY9iz2J9F0B+ZWlUmNs c27HWcvKa3dKcF4q1Lp3OAVSYa/FrHmUALH0hfdW+J9CzS8oYpN9gkt0nbW4eQJ8tJsK QfN3qjO9fO11JB4RRdvEChJ61fDXOn68ulLgrH6amIEjrCTudvJHb1g2W91AnNj5KZq6 72oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=woKXhVifW2tG5wkLh+ljBy4wBc7AccZBMhN/0khgQfw=; b=xq0MOMekzdoaTUhHOvMt8xYttxb0344GL0mywI7LAuXCG5FHAI8DB83PgjMO+zz4Tp QpbKVbpA37gRG8u85brbQd4PYqYTrnd17bIfZ/GG0pvCPW3P+DQsoH+RBzi/wQhLSiwq pnKA8FHejeD1g8zUUbhfBeuHZL7KZUfO+X4TeUJ7OPNT/eVS5By8JxBdNg8JD5azgOyF mlF9y/j/5HA1mFDzGwK6GhPTfXlpM8pVmKQ0oqQqFmRCURYz7/VazzVfDHkC4fe03YZS Uj0W65KUMEnqvuctGb3cu/6zM5uFIFNmhS0ywXOkvGtySy/q9PZkBPZQwBwPDTS8ovQw njuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=rHwYSWi2; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s21si4928153eju.119.2020.10.11.09.08.54; Sun, 11 Oct 2020 09:09:17 -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 (test mode) header.i=@ideasonboard.com header.s=mail header.b=rHwYSWi2; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732313AbgJJW7c (ORCPT + 99 others); Sat, 10 Oct 2020 18:59:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725900AbgJJVMB (ORCPT ); Sat, 10 Oct 2020 17:12:01 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65FD3C0613D0; Sat, 10 Oct 2020 14:11:59 -0700 (PDT) Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D2859528; Sat, 10 Oct 2020 23:11:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1602364316; bh=fpHhn5rM48GkcDX4bL4eRbG5dZr4i+sFRkbewEJH1Dg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rHwYSWi2XUI2y1Ti8u+N8R/KTpRgkW0TVn4LDZpKlDrbVLcAqDJGAnhyonxoldFRN psEGjrkDGp3K4p9i8ooaZhsYuS95RR6PuHIrw4PwyU90aSj/y97JR/y7rgRiYg/Ar0 8MefjhVZFKvV0sPG+/srQf9fVVfiV4dR3+khqARU= Date: Sun, 11 Oct 2020 00:11:11 +0300 From: Laurent Pinchart To: Daniel Vetter Cc: Jason Gunthorpe , Mauro Carvalho Chehab , DRI Development , LKML , KVM list , Linux MM , Linux ARM , linux-samsung-soc , "open list:DMA BUFFER SHARING FRAMEWORK" , linux-s390 , Daniel Vetter , Kees Cook , Dan Williams , Andrew Morton , John Hubbard , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Jan Kara , Linus Torvalds Subject: Re: [PATCH v2 09/17] mm: Add unsafe_follow_pfn Message-ID: <20201010211111.GA3939@pendragon.ideasonboard.com> References: <20201009075934.3509076-1-daniel.vetter@ffwll.ch> <20201009075934.3509076-10-daniel.vetter@ffwll.ch> <20201009123421.67a80d72@coco.lan> <20201009122111.GN5177@ziepe.ca> <20201009143723.45609bfb@coco.lan> <20201009124850.GP5177@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Daniel, On Fri, Oct 09, 2020 at 07:52:05PM +0200, Daniel Vetter wrote: > On Fri, Oct 9, 2020 at 2:48 PM Jason Gunthorpe wrote: > > On Fri, Oct 09, 2020 at 02:37:23PM +0200, Mauro Carvalho Chehab wrote: > > > > > I'm not a mm/ expert, but, from what I understood from Daniel's patch > > > description is that this is unsafe *only if* __GFP_MOVABLE is used. > > > > No, it is unconditionally unsafe. The CMA movable mappings are > > specific VMAs that will have bad issues here, but there are other > > types too. > > > > The only way to do something at a VMA level is to have a list of OK > > VMAs, eg because they were creatd via a special mmap helper from the > > media subsystem. > > > > > Well, no drivers inside the media subsystem uses such flag, although > > > they may rely on some infrastructure that could be using it behind > > > the bars. > > > > It doesn't matter, nothing prevents the user from calling media APIs > > on mmaps it gets from other subsystems. > > I think a good first step would be to disable userptr of non struct > page backed storage going forward for any new hw support. Even on > existing drivers. dma-buf sharing has been around for long enough now > that this shouldn't be a problem. Unfortunately right now this doesn't > seem to exist, so the entire problem keeps getting perpetuated. On the V4L2 side, I think we should disable USERPTR for any new driver, period. That's what I've been recommended when reviewing patches for several years already. It's a deprecated API, it should be phased out, which starts by not allowing any new use case. > > > If this is the case, the proper fix seems to have a GFP_NOT_MOVABLE > > > flag that it would be denying the core mm code to set __GFP_MOVABLE. > > > > We can't tell from the VMA these kinds of details.. > > > > It has to go the other direction, evey mmap that might be used as a > > userptr here has to be found and the VMA specially created to allow > > its use. At least that is a kernel only change, but will need people > > with the HW to do this work. > > I think the only reasonable way to keep this working is: > - add a struct dma_buf *vma_tryget_dma_buf(struct vm_area_struct *vma); > - add dma-buf export support to fbdev and v4l > - roll this out everywhere we still need it. > > Realistically this just isn't going to happen. And anything else just > reimplements half of dma-buf, which is kinda pointless (you need > minimally refcounting and some way to get at a promise of a permanent > sg list for dma. Plus probably the vmap for kernel cpu access. > > > > Please let address the issue on this way, instead of broken an > > > userspace API that it is there since 1991. > > > > It has happened before :( It took 4 years for RDMA to undo the uAPI > > breakage caused by a security fix for something that was a 15 years > > old bug. > > Yeah we have a bunch of these on the drm side too. Some of them are > really just "you have to upgrade userspace", and there's no real fix > for the security nightmare without that. -- Regards, Laurent Pinchart