Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp87877lqh; Mon, 6 May 2024 12:07:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVnCvtpp/lyuDx7BmVUMRjov9qYqjiXpgBZ7GFm4YlHracnqFgSjhveqIKb3uprrRda3o5N21RpezGSjBrYNQIf0DOKfejCrcGlCRTEIQ== X-Google-Smtp-Source: AGHT+IF3qAloQ1a39JEDQE/TAgnQrlKDofqs+NfPcZKq5gTdYVhlTSYFTQICX4Pl9Tdt9l8jnbUU X-Received: by 2002:a05:620a:535d:b0:790:fa6c:611b with SMTP id op29-20020a05620a535d00b00790fa6c611bmr11475237qkn.50.1715022460539; Mon, 06 May 2024 12:07:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715022460; cv=pass; d=google.com; s=arc-20160816; b=asBAb9PFsPlqGxbWBvQUCP0WNCmCLA4/ox1QVoEvba4s1tMGEPvBf0XXgDGg4IZvkS XI0vAnJc/AtUO64P4pYgq8drp3/h28BrSfEEo14nV4eEGHKGG5tG4tRLiEFcxMloOebg Kps/mN368QKRuDKLv53ZOiUXcK+x/SURhSdhJG6DgHnIjJT3+u11HbMJ6MbtASEkLOVf Gx1Ie2MQZWD8AVDcJjsMomg9QyNFdgQ8leqR7JANHgmmRwgFy6g6P66JSYpVXWJummhc qDMvCTEPWfpO33oSw2MfxsF3OJGO8jXEZ0pUlwX8wYf9zBwdaiuU2/u93XoQIqY0n2gY 2EQw== 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=05pEfdeTjP/gT4q1VDqtZ2Mm8b7W7bMEgQ0JTj2r+x4=; fh=0IcnXaWUO8cphL8r1iqELjR8K/r+dogDgeTEn+30a7A=; b=L2JF4wXwSUyT8D8f3p1PEfbpYmIyRjGciPwk9Pq++neVjcAgRKHetvtmK+MXubPqyB kUBlB2V4AXyM2ZNBDdzWF5VBo9SWi6wgpaQeW8tatYzfs/mT1MqEhbQg9to4I6uZKP7h XBH9UnKRqPBCGgYlZR9r9pkJC2vECEld8eR24q7eTmdoWaFmkWtK5COtxs7cGrST2WKU dMatGl6h1DMdlxvQdztH2FVbgbjN/b8p14hW2cju/PazTaXgKaww8NEbIZoWeKDfZlbU O2OXXTpoKZfXUigobjwmbjtMdCCPEj5+8fz9L5t425ijY+OPlS4+rAIuzv2q7hXYeM/g 11fA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=bCio00bX; arc=pass (i=1 dkim=pass dkdomain=ffwll.ch); spf=pass (google.com: domain of linux-kernel+bounces-169921-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169921-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 b15-20020a05620a270f00b007928dc0e24fsi5597777qkp.524.2024.05.06.12.07.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 12:07:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169921-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=bCio00bX; arc=pass (i=1 dkim=pass dkdomain=ffwll.ch); spf=pass (google.com: domain of linux-kernel+bounces-169921-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169921-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 04CE61C22958 for ; Mon, 6 May 2024 13:42:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 335AA78B4C; Mon, 6 May 2024 13:38:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="bCio00bX" Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 0832178C68 for ; Mon, 6 May 2024 13:38:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715002711; cv=none; b=rO8KunWZnFyBglTYxftxgArLYZBcBfqjTonm5MiQw5bB18ZRD6K9dI8n2QuzdRgSJUJnScTjO9iHuA9JSH+DtpzxZ00B6ErqH/Lv8J9Or2rsPBFdCuZ3IeKNkmbsgfUA//qRI5t/W4p921GZe4GEGi1ySgjeLdlIxOoC5amxKeI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715002711; c=relaxed/simple; bh=It9OpP6gC8bm5/vZVTQBOX1m6p9O8bYlAf/OdYb0psI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VCPPiFhAGRTrcupghS0aWZkfK0ri6T9elPcZITXVPuvlHDxZaVpGwJw/8CTneQaHaRnWc7qSSBDoi0jymx2Zp5o+5O0Ax9xQvtYRDf4njdR35PPNND82/iVzijkEFI14AgronPEoiuXdNz+fFLCc5U79WLO+VSewQF7ksYCCU8c= 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=bCio00bX; arc=none smtp.client-ip=209.85.128.43 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-wm1-f43.google.com with SMTP id 5b1f17b1804b1-41beaaecf9bso79645e9.1 for ; Mon, 06 May 2024 06:38:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1715002707; x=1715607507; 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=05pEfdeTjP/gT4q1VDqtZ2Mm8b7W7bMEgQ0JTj2r+x4=; b=bCio00bXGx0rOEGQgsW+cyXPMAEaUjZkVmv9Z7YAHR6pj3cpRxYr/aru5n6RBrblc6 h1G6rCGNRQlyim87RXhMzcGeG5Ngc1NIMellFQdSoDyeKM5PWa+s8u5Fh1f6BqVclRl8 Wb9qkrOeAGjMnjxHIA9olZ0LbNav8fYqSWbR8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715002707; x=1715607507; 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=05pEfdeTjP/gT4q1VDqtZ2Mm8b7W7bMEgQ0JTj2r+x4=; b=CjYPQVZStuNehzqozQY7VpN3CBPWpXoTXKotZpz/875CQrs7jhpseKXhbWfV50rkaw sK3XDQXfACUJLEd4pw2G3DSITkeXezRUXexyISy9bPbSRIA4HLmDHiEPnLri+8HYgler mLsKuugsb0ZdWXoIeohnLbn1YfI46ZoYZOnpklXF0R7LiZV1gwm67+VK0M4lcr3hQr9o HjpcIv1mwLkFUCHKqWbhKQswbE4RLLG46r6ugQGaKfJ3ab7eccMDNH2rlxA7z1ZsZTV1 /2IU75AjSMtCqkmzzVs0WuF8tY2KFU4VyMCX5R7bSJthbh8sBhyq65S7+HUQqFhn18wM cXpQ== X-Forwarded-Encrypted: i=1; AJvYcCWxCEq8qcKSyPxOAmYTq4fEJIBZewfOWeEuAYEc2iKx3ceT2E4+ogdX4mcO+r3kqxd/LaUCzvVrTuRodiMdos/9xZwGAQ8oVcrX3vox X-Gm-Message-State: AOJu0YzWBKnknj3pc3O/CnpljnxWOMlk9SBGXK5G2Kdw6pTTTvnsSZ4X t0fBTxsXyyGQBPBfHnM4R+L+MKLvct0Tb+nb8yjNS6gY+dxEaAE52kA5aBORwdw= X-Received: by 2002:a05:600c:46cf:b0:41a:bb50:92bb with SMTP id q15-20020a05600c46cf00b0041abb5092bbmr7391993wmo.0.1715002707370; Mon, 06 May 2024 06:38:27 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id z5-20020a05600c0a0500b0041bd85cd3f2sm16051523wmp.19.2024.05.06.06.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 06:38:26 -0700 (PDT) Date: Mon, 6 May 2024 15:38:24 +0200 From: Daniel Vetter To: Maxime Ripard Cc: 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> 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: <20240506-dazzling-nippy-rhino-eabccd@houat> X-Operating-System: Linux phenom 6.6.15-amd64 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. - An allocator service which checks whether you're allowed to allocate these special buffers. Android does that through binder. Probably also some way to nuke applications that refuse to release buffers when they're no longer the right application. cgroups is a lot more convenient for that. -Sima > > But devices tagged for uaccess are only opened up to users who are > > physcially present behind the machine and those can just hit > > the powerbutton, so I don't believe that any *on purpose* DOS is part of > > the thread model. > > How would that work for headless devices? > > Maxime -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch