Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp2400437pxu; Fri, 9 Oct 2020 16:34:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0Uh2Vvz5kwcgQmFevEY3J5y6a6jMLgZ96X8WgFpY1H2odk2Xm+kZKZlxs+GiDVFaLRguZ X-Received: by 2002:a05:6402:21fd:: with SMTP id ce29mr1698893edb.383.1602286460566; Fri, 09 Oct 2020 16:34:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602286460; cv=none; d=google.com; s=arc-20160816; b=qglKYkQftQVZ5GlB5Mm6a+kTVixGNjDxYwNzNfvBA2k+wlMp1rFyeA79pBjssZUkyy 0Qtjz5cO2K13wYHAwpOnDoihjos/zIwqz5CcScbwMKI3QEi1Gk0z8Wrqv2lXX7ZAlGXD 1BZfHL9a4aLji2pN9XyFDMoD9QlKrCT+ipWvpVCkwEwbb8N6Ce0qpm3ukuUfzQeWwUSt G7YwDFYNWxYPE91SxdPZxM+UH9QkFGvfxJwoYx0QMAY+IJ6KeByfP2PUGvE8oMZQG5dI cQtGVaQ9lIycAaCAy3PvDvySYJaU6Pox+qOQYUmvRYZXAOk3kF+pX3Lm1WNKmoEhY0u0 sthA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Chc8637Rd8yI9tLS7AREeItMweAw4M0AE06Zuj7bhU0=; b=FtG6JywpDQNKGq9kZy9VuEaGei2Ggw0tbHk7nQp4zGHfcImXevoGawGF5VB/fz/eQf n/hYkVpznOqboSs9DN0vCv8BnMeoPGRwfjyZvazUUG4tvhgYOIPrGLLPDlVNMv7XmVXN UO7ARdWi1UD0zoJcZ+Wq54mjqYcLJFY27tSwHtzG3Qjh4JnF03CmoL+tIiI22o3agJnQ /axOb4k9pTVtEDLDjrficBSx03bbyxflujmEsylrVR2i7Wu9hwK/3no028SgDECNjWGF +mk8xPc1X3hf4gdXW63qocb1BoE4ssROL4MuKpXiF/IWLSNEGcUa+Cr8RIu/PBw1+gbJ 50ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=L4kTmlRV; 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 dd24si5673622ejb.523.2020.10.09.16.33.55; Fri, 09 Oct 2020 16:34:20 -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 header.i=@ffwll.ch header.s=google header.b=L4kTmlRV; 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 S2390102AbgJIRwV (ORCPT + 99 others); Fri, 9 Oct 2020 13:52:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389529AbgJIRwT (ORCPT ); Fri, 9 Oct 2020 13:52:19 -0400 Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61D12C0613D2 for ; Fri, 9 Oct 2020 10:52:17 -0700 (PDT) Received: by mail-ot1-x343.google.com with SMTP id s66so9779292otb.2 for ; Fri, 09 Oct 2020 10:52:17 -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=Chc8637Rd8yI9tLS7AREeItMweAw4M0AE06Zuj7bhU0=; b=L4kTmlRVcZoe/avVgvgJLaWOs03iPF87kjF+Wg5Dr1BO68grQeWij+sKeGLbjkKVnS uWxXV8aahQlRlzimSn7k7/L57rwPuRVe9l/HoPbmKuzL42kNzmiAubvKP93NNRPozIcb M7wzXGB/zvSu+un9zoWu7yVJIqeg+g4rBMVIc= 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=Chc8637Rd8yI9tLS7AREeItMweAw4M0AE06Zuj7bhU0=; b=D0SE6RhNmrrJwb9hHI+5CDge4FzXVOlL0+BrNIAa8SExqWYTCWTwZaNAKoN6uF0QxH PF7WFz2fnt2vAA5rzAueuGkFUKVwjEm4ImpgAE2w2IzUl9wrshyI6ZQBhtZs5bQ8hLcj 7p7vCIWLJVJOBznqfWq6E6WkGiQWEv+BvYXWhR3V4dkRk+Ec0XzKYR1Pc1KR0EXcGkAZ qHnVIr/s5IkbSwePWYJU/o3LMHFz+/Y2ESpZEPhQnpbTXUbvoZlG9WS9838vgJiHaEJI xBX6DuXMNNQki8+tjWPiumCKuaDzdwYKjftSdslErUBfv/jRYrcXtDrIZuzF2RJenG7f nH6A== X-Gm-Message-State: AOAM530bFR6e8t04ALxksgQ35tyEb1kFKmEWg/wzx36mTxPVdRX3qTUq Ewv4ct3JUIU2bAvhQMieZLeeBKmtWeMr4fhzBOj82A== X-Received: by 2002:a05:6830:1647:: with SMTP id h7mr10168614otr.281.1602265936612; Fri, 09 Oct 2020 10:52:16 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: <20201009124850.GP5177@ziepe.ca> From: Daniel Vetter Date: Fri, 9 Oct 2020 19:52:05 +0200 Message-ID: Subject: Re: [PATCH v2 09/17] mm: Add unsafe_follow_pfn To: Jason Gunthorpe Cc: 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?SsOpcsO0bWUgR2xpc3Nl?= , Jan Kara , Linus Torvalds Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > 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. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch