Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp876498lqp; Thu, 23 May 2024 02:41:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVbHF/KqNl1dmwDLi2rPuiswDCrhoMOiXRGljDxI+chEUSRNHxLeyt3AcJPmC30Ub9FhL15Tm1udja4RBJKwI273qHt6F5EXzpUDeX36g== X-Google-Smtp-Source: AGHT+IFt+2T/CdKKuxfYVRPHdL/V2gogvTn8mZ2nu+D2vrdKTaTNg90H69i+AdkyXhsS5Dgsqnnc X-Received: by 2002:a05:622a:189b:b0:43a:d39a:45bc with SMTP id d75a77b69052e-43f9e173824mr49169171cf.49.1716457302188; Thu, 23 May 2024 02:41:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716457302; cv=pass; d=google.com; s=arc-20160816; b=uQDdf07jUxDdCBeXPeXGglV6wSoNH9ias8RMuPs6WcJxpz2asszzRqEhRxWMPtpRlg 7Y7V0Ngc2Dt+eJTPqjZVQvQbDYDWEg+guO/I8axSw1hZ5yM5e6nj9dpYwhv3IVUacDDu mtBSR9iDDrirO2FDFnrzwiBskiz4g/0pU7rW//o81/SMoAFIBAfy7OF2rf/DlAP6JRZS CqYfNfK0HdUPgE2MctHVofICA7SD9LLMdhp9408/Izgq+FLK8hNcSsjzUcWvjS4u+AeQ Zpkf/Ono/Ip/7yAUMJx+/rGhE/LbK1fEbJ2mkvSkqx2T1ogLFqTep9mNTZS7S/7roQDE zrNA== 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=7P0FBG/QIqolUidBUOAk5xSpyavQelBrO3qhLkdkCo4=; fh=C9T5LoHNVb3inWYp1cCyV7euXV7NqJtyhF+IkLBzhgU=; b=anP4J1s1wfkdQetG5qWTllEyJmZyS6Oe4iKgk86RmvbglFoZnN54Nf+T+ptNT4Rozn RxbWRg5rmGmRpEOUmoqRv66oxDljWczSvclbT+o1tWtFf4yQXyBEyTb3Ikw7JWU7LIye 9vQw/YAJArvB9Daey0a7ZywvG5lD4ciuSxtfh9GxJRMBbglH0AsPSgKVzvKyrj7oyxlX cH8zLBCMl2QbYrjJNlfPtzZxNsEqc+rHb+jRAPiyWBfemejMhcudfiGA5UYmUgNQwFAJ Z+DgbyGJiK5SMNBFOqB0JNvYH5SyWspGNpRZLXF7Yr7fK851C6GXhDlDaI2IMfY50Tp1 RrDw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=A7BKMpgH; arc=pass (i=1 dkim=pass dkdomain=ffwll.ch); spf=pass (google.com: domain of linux-kernel+bounces-187287-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187287-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43df567099bsi115090451cf.370.2024.05.23.02.41.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 02:41:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187287-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=A7BKMpgH; arc=pass (i=1 dkim=pass dkdomain=ffwll.ch); spf=pass (google.com: domain of linux-kernel+bounces-187287-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187287-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D59BC1C22305 for ; Thu, 23 May 2024 09:41:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3B27D13B58D; Thu, 23 May 2024 09:41:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="A7BKMpgH" Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 870B94685 for ; Thu, 23 May 2024 09:41:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716457293; cv=none; b=fnYI8WH+6n+0bSRaEKeXM+XHyX85C/Y8KndCnMn872FExyjDC2/+8p0rA0Kj3SEtSk94ukeCxY56jhS4xRaktEpjg+KwNwt7PejmmV3c8D2B/Tq1r1n180FPThprWQDuv2UF7HXUtdJ7IrSf8WJ/EJXrAdbP8ftlpNA4MJ/C5dc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716457293; c=relaxed/simple; bh=j2zvU3m0yzWo1+kw71p/VfCXySbVS/PxKnovAE6DvVE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dFp10GcGqQxdCL68wjjeCnSFVu1HRETHoN5t+6Ijb/ixH+9v/BL6qtqbx0WDHn7/oBHYA39OrA1Un3XGMOXI6BGWpaaa96dy8V2/qaE5OTYUOjxk9KmGhokJfmIxpa4l9KQkDdEPYmYccaVlQdeUoLa3ONf8JGdQD/Kjjyc/GFw= 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=A7BKMpgH; arc=none smtp.client-ip=209.85.208.181 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-lj1-f181.google.com with SMTP id 38308e7fff4ca-2e20088184cso11244051fa.1 for ; Thu, 23 May 2024 02:41:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1716457289; x=1717062089; 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=7P0FBG/QIqolUidBUOAk5xSpyavQelBrO3qhLkdkCo4=; b=A7BKMpgH4ry3m1y24XN02Euv9t7X+SIKSTFivWGVX4sz1v8D4dX1ZIoO/13Mw9A3JI iavQSwWhm23vGsi0Z25bOqGWWOoxAmFuqvjI4lDqxG/SGpFzFdGFEOLKjWnY+k8Iswga UMXgaNDEinuWp7G0Pp2lekJjLOti1NQNpU7dg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716457289; x=1717062089; 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=7P0FBG/QIqolUidBUOAk5xSpyavQelBrO3qhLkdkCo4=; b=O7Yznwx2ktkgP61diK0hXIXDM5LiHAtQLKiE4X6pIYM059r8c6UsgxWQGTEk+jzBMa 007IY/X/GE3WfhNZ+O8Ne8dCeXXcdomdk0V4f/N5EhTv4aWBMLPzpOdie2LQqbv87MLp fd+lhTCMCm95GBsRSyJ/MnZ0jkqfoQjjxV0+18JZleWXcYvX6fMNTORR0prW7gigpi0d RG2eoXn1/hnaTKzjUi9AVaZsXcG8veaMFQ2DrUJ0e76YbbCwGUYJdBqe+Ubigm4psrjm kl+XLmHK06yAvU30Pu59xL8q1HvZR+v8NVAr3N+Z8Oy1ysUlcXzHn6pbHJQ/DQlBPzMS C7DA== X-Forwarded-Encrypted: i=1; AJvYcCVgJ4HfCCabXyoukZijYT7k8PcBT7RYfUEy++l1XlFySlqmcVyAmLLP9iqcjV0uJ4PTN0PxGaFU2y6Vc9R4QQx9v66aw1RpQn4n7R90 X-Gm-Message-State: AOJu0YwAjS5TqEsj08CWxrwRtgbxhAhYx01PGK0mzHFngKuE3s2AbY5g 5CgczqscGnbZj8liEnwS3d04jmM2Bo822ApGNsR872dFLS7qFuEpVDLWIN8RtidgqvKQxbMisub L X-Received: by 2002:a2e:7214:0:b0:2e8:e8db:34ea with SMTP id 38308e7fff4ca-2e9496214edmr30640171fa.5.1716457288819; Thu, 23 May 2024 02:41:28 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42100ee806esm20062515e9.3.2024.05.23.02.41.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 02:41:28 -0700 (PDT) Date: Thu, 23 May 2024 11:41:26 +0200 From: Daniel Vetter To: Maxime Ripard Cc: Daniel Vetter , Hans de Goede , 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: Maxime Ripard , Hans de Goede , 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> <20240522-thankful-cow-of-freedom-f0cbf8@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: <20240522-thankful-cow-of-freedom-f0cbf8@houat> X-Operating-System: Linux phenom 6.8.9-amd64 On Wed, May 22, 2024 at 03:34:52PM +0200, Maxime Ripard wrote: > Hi, > > On Mon, May 06, 2024 at 03:38:24PM GMT, 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. > > > > So you need more, either: > > > > - cgroups limits on dma-buf and dma-buf heaps. This has been bikeshedded > > for years and is just not really moving. > > For reference, are you talking about: > > https://lore.kernel.org/r/20220502231944.3891435-1-tjmercier@google.com > > Or has there been a new version of that recently? I think the design feedback from Tejun has changed to that system memory should be tracked with memcg instead (but that kinda leaves the open of what to do with cma), and only device memory be tracked with a separate cgroups controller. But I'm also not sure whether that would actually solve all the tracking/isolation requirements people tossed around or just gives us something that wont get the job done. Either way, yes I think that was the most recent code. -Sima -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch