Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3013502pxu; Sat, 10 Oct 2020 16:06:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylqd4O0lN/FNOvjHdHxC1hxZ9y/bgQmOYfT1ZQbVWMwhHUe2Ct9tJ1yVU7DVFeUdQpa+Xa X-Received: by 2002:a50:c38e:: with SMTP id h14mr6791153edf.174.1602371206752; Sat, 10 Oct 2020 16:06:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602371206; cv=none; d=google.com; s=arc-20160816; b=AbveInljp0KP1zZnRMzBl4HhuB0wu4ajNAv/lVrYv2Vv52CtMlNU3V8vaFfsDVqsyk usM8MyGeUf2q0ojPszL/qX6eFdX7le37rlR/b2s0JcIq1nBTEIdxRb/wPR/KuZrotxOW KbnzsDvBFiz7HzaGxrViDca3Jfq39iDg8VX3dgMR3mCT5udCFfCWkw/qyF38wJjxu4fw luP9dE/z7zk7WOm3D0M4SaFLq+k/vxpdXgzzo2lBoWZKqq1wVpAkxRSdq+H9RkSYmagj VYyalLrbVDHKuvpPOI0gYDt4qKcg4WgU6mipi/FsZNORqcib87E1omSSiWOnMyd7vG/r AVAg== 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=xsOZOc5wUkDsyS+q4XR7sRY+/Nw08dWS4rH9PR3SdYM=; b=PPIt2htv5AEZCnL7JSzPcWtVWLCAryVXuhiblnTdC+Y7RD+S5znOv6uB96XK3BfIq7 cJ5zj+CUUBAWErAMThh8IcnBP1SELu66dMwJCtDVpV5bbs61izQfFYu3kh+IGNY5pq1b aqiMoJKVxhNf2goBX7Jbv+sQU98Ho0O4YnZg5QckF2i/6WF4NwieylQRcZqlRHU11ekq VykYTUwlZpbivGp2J+g2zqn4n1N4ED8MGG48BzEG15XJ4DziUJAy2G82SXMFB2Vnxvu1 aCT58JzEpFWmNEXHMJgxv+bAXlUVanEBChFy8sgBfFeABi5cqMJuYOuyaJEYhByP4nJd /zUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=K43vYuvF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i13si9052529edq.350.2020.10.10.16.06.24; Sat, 10 Oct 2020 16:06:46 -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=@chromium.org header.s=google header.b=K43vYuvF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389194AbgJJWz0 (ORCPT + 99 others); Sat, 10 Oct 2020 18:55:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731431AbgJJTVv (ORCPT ); Sat, 10 Oct 2020 15:21:51 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6164C08EA7F for ; Sat, 10 Oct 2020 10:31:13 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id p15so17567186ejm.7 for ; Sat, 10 Oct 2020 10:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xsOZOc5wUkDsyS+q4XR7sRY+/Nw08dWS4rH9PR3SdYM=; b=K43vYuvFf4p0HKwpNNYM8EVjuArTRuuNWIw2q4YLC5jyws5WqABCqrRlB8L6Kw/ga/ 9pb07pav9vu70DJL9+qIG+8WZUav68UhLbRS2hY3VnFfDpqam6GcqIBnDSm/T02riaI0 bK3Q77l+IKqRqvdVTvJ6gEi/4zr+9omw8Jdkw= 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=xsOZOc5wUkDsyS+q4XR7sRY+/Nw08dWS4rH9PR3SdYM=; b=gvMfm0wF/HiaJzTl+gqo5RpmTjdVlJYd+A475p1yFbZPU4U1Ip3F9YBnHc5HqAPox7 0lNGyLgqGmN20MzU7fS3D0rqPqDNC6IxL0yvMuCvRP/2fMlKB6x3D9XdjMfW6uQC7aLH 6RJWHrP/54rnKyXMAz0h0QTUZrtJKUfYW2tVFZj8ujynjA+0a47jJE+2pwsnnrdIcL8K Vehd3zt0ofPz7JjgxmDD1+TqQOoW/cGRb3CmMW10Fb3hkFu0fA4jHTa6lmfYMqKl2UDk 64Hm1yqPxzPpZWOr2BQR3ArYLH1Fqs2ISBgRsO97WQDd70t8udKI9le9tRKpxaYY+NFy cxEw== X-Gm-Message-State: AOAM531Ya9/MMXkGxpdz6JeMlqyVBKaoB43t6KVYShS+sM95jOV7wJ+o OJfvObURVJi6c7npZQ+c38Sn+mL3D1tATw== X-Received: by 2002:a17:906:f11a:: with SMTP id gv26mr19702198ejb.13.1602351071664; Sat, 10 Oct 2020 10:31:11 -0700 (PDT) Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com. [209.85.128.44]) by smtp.gmail.com with ESMTPSA id b25sm7978387eds.66.2020.10.10.10.31.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 10 Oct 2020 10:31:10 -0700 (PDT) Received: by mail-wm1-f44.google.com with SMTP id p15so12875504wmi.4 for ; Sat, 10 Oct 2020 10:31:10 -0700 (PDT) X-Received: by 2002:a1c:8057:: with SMTP id b84mr3433695wmd.116.1602351069766; Sat, 10 Oct 2020 10:31:09 -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> In-Reply-To: <20201009143723.45609bfb@coco.lan> From: Tomasz Figa Date: Sat, 10 Oct 2020 19:30:59 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 09/17] mm: Add unsafe_follow_pfn To: Mauro Carvalho Chehab Cc: Jason Gunthorpe , Daniel Vetter , DRI Development , LKML , kvm , Linux MM , "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , linux-samsung-soc , Linux Media Mailing List , 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 Hi Mauro, On Fri, Oct 9, 2020 at 2:37 PM Mauro Carvalho Chehab wrote: > > Em Fri, 9 Oct 2020 09:21:11 -0300 > Jason Gunthorpe escreveu: > > > On Fri, Oct 09, 2020 at 12:34:21PM +0200, Mauro Carvalho Chehab wrote: > > > Hi, > > > > > > Em Fri, 9 Oct 2020 09:59:26 +0200 > > > Daniel Vetter escreveu: > > > > > > > Way back it was a reasonable assumptions that iomem mappings never > > > > change the pfn range they point at. But this has changed: > > > > > > > > - gpu drivers dynamically manage their memory nowadays, invalidating > > > > ptes with unmap_mapping_range when buffers get moved > > > > > > > > - contiguous dma allocations have moved from dedicated carvetouts to > > > > cma regions. This means if we miss the unmap the pfn might contain > > > > pagecache or anon memory (well anything allocated with GFP_MOVEABLE) > > > > > > > > - even /dev/mem now invalidates mappings when the kernel requests that > > > > iomem region when CONFIG_IO_STRICT_DEVMEM is set, see 3234ac664a87 > > > > ("/dev/mem: Revoke mappings when a driver claims the region") > > > > > > > > Accessing pfns obtained from ptes without holding all the locks is > > > > therefore no longer a good idea. > > > > > > > > Unfortunately there's some users where this is not fixable (like v4l > > > > userptr of iomem mappings) or involves a pile of work (vfio type1 > > > > iommu). For now annotate these as unsafe and splat appropriately. > > > > > > > > This patch adds an unsafe_follow_pfn, which later patches will then > > > > roll out to all appropriate places. > > > > > > NACK, as this breaks an existing userspace API on media. > > > > It doesn't break it. You get a big warning the thing is broken and it > > keeps working. > > > > We can't leave such a huge security hole open - it impacts other > > subsystems, distros need to be able to run in a secure mode. > > Well, if distros disable it, then apps will break. > Do we have any information on userspace that actually needs this functionality? Note that we're _not_ talking here about the complete USERPTR functionality, but rather just the very corner case of carveout memory not backed by struct pages. Given that the current in-tree ways of reserving carveout memory, such as shared-dma-pool, actually give memory backed by struct pages, do we even have a source of such legacy memory in the kernel today? I think that given that this is a very niche functionality, we could have it disabled by default for security reasons and if someone _really_ (i.e. there is no replacement) needs it, they probably need to use a custom kernel build anyway for their exotic hardware setup (with PFN-backed carveout memory), so they can enable it. > > > While I agree that using the userptr on media is something that > > > new drivers may not support, as DMABUF is a better way of > > > handling it, changing this for existing ones is a big no, > > > as it may break usersapace. > > > > media community needs to work to fix this, not pretend it is OK to > > keep going as-is. > > > Dealing with security issues is the one case where an uABI break might > > be acceptable. > > > > If you want to NAK it then you need to come up with the work to do > > something here correctly that will support the old drivers without the > > kernel taint. > > > > Unfortunately making things uncomfortable for the subsystem is the big > > hammer the core kernel needs to use to actually get this security work > > done by those responsible. > > > I'm not pretending that this is ok. Just pointing that the approach > taken is NOT OK. > > 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. > > 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. > > 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. > > Please let address the issue on this way, instead of broken an > userspace API that it is there since 1991. Note that USERPTR as a whole generally has been considered deprecated in V4L2 for many years and people have been actively discouraged to use it. And, still, we're just talking here about the very rare corner case, not the whole USERPTR API. Best regards, Tomasz