Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp482460lqh; Tue, 7 May 2024 05:32:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVmhloddig+OnVlCVR+Hdum2iCRXCavvnRSJ2GIbF96pkdYeM2cjoTNJMj0vcUKpQBGLQ4sN6GlY96XpH3KY/ysWagbjnn/mb1ASCsh/w== X-Google-Smtp-Source: AGHT+IFZSXQuYBVgiCq/qRjM3SK8LhBeZGc7yptEOEER2/xqHvLbYbLfdMgAziF1xU1bUzzl/61w X-Received: by 2002:a05:6a21:3994:b0:1ad:7e4e:428d with SMTP id ad20-20020a056a21399400b001ad7e4e428dmr18720161pzc.20.1715085126536; Tue, 07 May 2024 05:32:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715085126; cv=pass; d=google.com; s=arc-20160816; b=kuEeipwy2yNbaj5cLfXksSv0slrjH0UzKfdsNYRxEYudALuNiBCpte7J98wWWNrkkz WpUfGjY3WJIm51H+i4EnMPQxGmXVLgbjkjI1J0eTiSZk18l7idmBniRfP38AStRDuaOw ZhzS55vf10DUZmiHgEwJDa4jQirU9KGtcITKbU9tYRhN4fLTZDk+xAQ/XAJG41/0lhtf zOGEpHDpqwa/rshDygy2knaGvBzqVBxdagoU82sEoplvcK1uGr6mSpcnrnVdw17aEKc6 2+U4kyQ43OB607sDOwhka4nIamAwFecSlG+HAKgTDr8HO0RqGJpXmJM6ZA4ophnSxpTU zggQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature; bh=wXHaXKdqUHwPFQAJMHKHEEcPt9R1JT6UoeAkdx1FiUQ=; fh=6yH2SAUQkljHyywz4VdvcH9l3YVht07DK9ISE9h2G3Q=; b=AX2OH5K67x0FgHOjHTSGnL9We9joyiIQI1z/vcii0mC/c/G0IwVG1lAPR48DkFfZE/ uQ9pQD6linmKg69PUYPLibon5wGjqKfVNYdJUfuZE2CckHstRXkZtPNNgxIiB07gZHrq X9YgdAAcXFZ2w6EHBF/wNm6kIfoU6iibAvhQprCx1Jz1PBGUjp965aNDMWvotUUMWfsQ o7iaE7OldINpSptR03eJ9ERWn+6pSLXlND+Ao/Xn4VLtnQqZdVmy107QeKG5KEeo2kSy AVMW4ySxLN66JZHf98nHneZVDoEU+6Xji1xF5yhlluGR/k0QvkK4ncQRcmfSWbyPwUz9 VP0w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=Lw0aGt4j; arc=pass (i=1 dkim=pass dkdomain=ffwll.ch); spf=pass (google.com: domain of linux-kernel+bounces-171182-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171182-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e19-20020a63f553000000b005ee3f1a2d57si10791016pgk.885.2024.05.07.05.32.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 05:32:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171182-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=Lw0aGt4j; arc=pass (i=1 dkim=pass dkdomain=ffwll.ch); spf=pass (google.com: domain of linux-kernel+bounces-171182-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171182-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id BEF3BB274E9 for ; Tue, 7 May 2024 11:15:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7518F13CFAD; Tue, 7 May 2024 11:15:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="Lw0aGt4j" Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA18914F109 for ; Tue, 7 May 2024 11:15:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715080533; cv=none; b=VlyI8Q9vrG5oa3PgQhuoLhf/EKiq3p3OEH8JEFBKniBZnjyCqXOXGa7eZ2jRwWIUnkpC8U6V29Oc4oJ6qqfcmDuNNhGFu4ZEKoouwQ9NWpN7uGTta3vodhYTMcX+xp+0D6zbQNJWyyVbLBP/Xd50ViwxDtUT0bYGfNTYgZctkV8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715080533; c=relaxed/simple; bh=cg+Ro88ytJjd/fd08mRf8Cz6ImUq4vWBcpmoLF+uj6s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NicfVnbMKgYSCbTIlgXxe4+I93ycv6xdZvlUKN4+1vjfD/i7n5g70/kF583NCL1U9X19dIhvfxrl5zYIlwzTQ4++VWnunCAiVhaAZFkdsHW3a1meqXkWHpCQOf7XGzwPlOjS454V14H50WF6BRb96uf0uz7NjztRmeovwLcW+m0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch; spf=none smtp.mailfrom=ffwll.ch; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b=Lw0aGt4j; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ffwll.ch Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-346407b8c9aso905205f8f.0 for ; Tue, 07 May 2024 04:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1715080530; x=1715685330; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=wXHaXKdqUHwPFQAJMHKHEEcPt9R1JT6UoeAkdx1FiUQ=; b=Lw0aGt4jy3dTDdTuxyoeQT/ZRaFMncE8c0QbvGvgLoK1CPB8glR2J60YilKswlABWL 7BJxnW7VY61EI2+jJMoxpnpDe54lryiracbplfdT+MuP/4wUkzk4XRT8elRMTSoBdA57 sis0nq4I/80RNmGHtYDIGpSllvfFyZ7E1hK7E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715080530; x=1715685330; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wXHaXKdqUHwPFQAJMHKHEEcPt9R1JT6UoeAkdx1FiUQ=; b=lF+28lMmYjdTDl0PFhuIxx8m6BEDjGHf6LhTiEabth9aOs0cGad1js3RS0W81CDHNM K4CraKNmadARy0oD2lyXLuWcJvvf00XpJz7N9bRmdc8slmonHLSJnnUAVAa2HsxYM/81 FPg9zJN5Uy+ifMKYZsrEKcGKm44ElDZU1pemDwE29uPsARbMpBVNGb57kuRt6lN8AMIW zer8VvA0U3TkLKUy4r2bsvZSv57CN4mVi8iJMp6rv400hqailErptJjOg17rENRxQ0rX nQoRanshZHuHlAzEuoGxbnQHGfd0bWTLMlYZtzkmb1OT5GWpkQ2Z5lemep+M3Pp+t89J SEoA== X-Forwarded-Encrypted: i=1; AJvYcCUU+JhvIOMWTV/9Cyx/cvINfxZ/d6k6PBov/GdSRzg8wRkkQ5tYHrPXp9tksyhAWQ9FNk/hg28VPBkxv3APLqhjF8HBXxdc5jUNPXE4 X-Gm-Message-State: AOJu0YzYHs9kaG1r+9iywNe/6sY7BGRLNQEJeO/e4n4TeTTb/JehVXro XvsRSXhcTBuhsfzLbLQkC7i7MePHPOF1Z6sB1cBcPK4E+A2+Jy9EjNq53m2GLmc= X-Received: by 2002:a05:600c:3b02:b0:41a:c4fe:b0a5 with SMTP id m2-20020a05600c3b0200b0041ac4feb0a5mr8937623wms.4.1715080530250; Tue, 07 May 2024 04:15:30 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id d10-20020a05600c3aca00b00418e4cc9de7sm22960582wms.7.2024.05.07.04.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 04:15:29 -0700 (PDT) Date: Tue, 7 May 2024 13:15:27 +0200 From: Daniel Vetter To: Hans de Goede Cc: Maxime Ripard , Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , Christian =?iso-8859-1?Q?K=F6nig?= , Lennart Poettering , Robert Mader , Sebastien Bacher , Linux Media Mailing List , "dri-devel@lists.freedesktop.org" , linaro-mm-sig@lists.linaro.org, Linux Kernel Mailing List , Bryan O'Donoghue , Milan Zamazal , Andrey Konovalov Subject: Re: Safety of opening up /dev/dma_heap/* to physically present users (udev uaccess tag) ? Message-ID: Mail-Followup-To: Hans de Goede , Maxime Ripard , Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , Christian =?iso-8859-1?Q?K=F6nig?= , Lennart Poettering , Robert Mader , Sebastien Bacher , Linux Media Mailing List , "dri-devel@lists.freedesktop.org" , linaro-mm-sig@lists.linaro.org, Linux Kernel Mailing List , Bryan O'Donoghue , Milan Zamazal , Andrey Konovalov References: <20240506-dazzling-nippy-rhino-eabccd@houat> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: Linux phenom 6.6.15-amd64 On Mon, May 06, 2024 at 04:01:42PM +0200, Hans de Goede wrote: > Hi Sima, > > On 5/6/24 3:38 PM, Daniel Vetter wrote: > > On Mon, May 06, 2024 at 02:05:12PM +0200, Maxime Ripard wrote: > >> Hi, > >> > >> On Mon, May 06, 2024 at 01:49:17PM GMT, Hans de Goede wrote: > >>> Hi dma-buf maintainers, et.al., > >>> > >>> Various people have been working on making complex/MIPI cameras work OOTB > >>> with mainline Linux kernels and an opensource userspace stack. > >>> > >>> The generic solution adds a software ISP (for Debayering and 3A) to > >>> libcamera. Libcamera's API guarantees that buffers handed to applications > >>> using it are dma-bufs so that these can be passed to e.g. a video encoder. > >>> > >>> In order to meet this API guarantee the libcamera software ISP allocates > >>> dma-bufs from userspace through one of the /dev/dma_heap/* heaps. For > >>> the Fedora COPR repo for the PoC of this: > >>> https://hansdegoede.dreamwidth.org/28153.html > >> > >> For the record, we're also considering using them for ARM KMS devices, > >> so it would be better if the solution wasn't only considering v4l2 > >> devices. > >> > >>> I have added a simple udev rule to give physically present users access > >>> to the dma_heap-s: > >>> > >>> KERNEL=="system", SUBSYSTEM=="dma_heap", TAG+="uaccess" > >>> > >>> (and on Rasperry Pi devices any users in the video group get access) > >>> > >>> This was just a quick fix for the PoC. Now that we are ready to move out > >>> of the PoC phase and start actually integrating this into distributions > >>> the question becomes if this is an acceptable solution; or if we need some > >>> other way to deal with this ? > >>> > >>> Specifically the question is if this will have any negative security > >>> implications? I can certainly see this being used to do some sort of > >>> denial of service attack on the system (1). This is especially true for > >>> the cma heap which generally speaking is a limited resource. > >> > >> There's plenty of other ways to exhaust CMA, like allocating too much > >> KMS or v4l2 buffers. I'm not sure we should consider dma-heaps > >> differently than those if it's part of our threat model. > > > > So generally for an arm soc where your display needs cma, your render node > > doesn't. And user applications only have access to the later, while only > > the compositor gets a kms fd through logind. At least in drm aside from > > vc4 there's really no render driver that just gives you access to cma and > > allows you to exhaust that, you need to be a compositor with drm master > > access to the display. > > > > Which means we're mostly protected against bad applications, and that's > > not a threat the "user physically sits in front of the machine accounts > > for", and which giving cma access to everyone would open up. And with > > flathub/snaps/... this is very much an issue. > > I agree that bad applications are an issue, but not for the flathub / snaps > case. Flatpacks / snaps run sandboxed and don't have access to a full /dev > so those should not be able to open /dev/dma_heap/* independent of > the ACLs on /dev/dma_heap/*. The plan is for cameras using the > libcamera software ISP to always be accessed through pipewire and > the camera portal, so in this case pipewere is taking the place of > the compositor in your kms vs render node example. Yeah essentially if you clarify to "set the permissions such that pipewire can do allocations", then I think that makes sense. And is at the same level as e.g. drm kms giving compsitors (but _only_ compositors) special access rights. > So this reduces the problem to bad apps packaged by regular distributions > and if any of those misbehave the distros should fix that. > > So I think that for the denial of service side allowing physical > present users (but not sandboxed apps running as those users) to > access /dev/dma_heap/* should be ok. > > My bigger worry is if dma_heap (u)dma-bufs can be abused in other > ways then causing a denial of service. > > I guess that the answer there is that causing other security issues > should not be possible ? Well pinned memory exhaustion is a very useful tool to make all kinds of other kernel issues exploitable. Like if you have that you can weaponize all kinds of kmalloc error paths (and since it's untracked memory the oom killer will not get you of these issuees). I think for the pipewire based desktop it'd be best if you only allow pipewire to get at an fd for allocating from dma-heaps, kinda like logind furnishes the kms master fd ... Still has the issue that you can't nuke these buffers, but that's for another day. But at least from a "limit attack surface" design pov I think this would be better than just handing out access to the current user outright. But that's also not the worst option I guess, as long as snaps/flatpacks only go through the pipewire service. -Sima -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch