Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp526174lqh; Tue, 7 May 2024 06:41:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX53leBNXC7Ziiy+GddRsK4bYmLiz+heayVfuA4t1w/6/pUlKKnJU2wfheUFi7sVHMx10oIsveM037WRJK8sKp3eVtySu8dVrxB4sgVkg== X-Google-Smtp-Source: AGHT+IHuOm0HUwyxNwTt/JL7+Ucab0a/6ZOhFIcD+zkMUt64f3WWXMv17V2iydUuGPaAS4Lxhi1d X-Received: by 2002:ad4:5d4a:0:b0:6a0:d32d:79d with SMTP id jk10-20020ad45d4a000000b006a0d32d079dmr16562799qvb.56.1715089301078; Tue, 07 May 2024 06:41:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715089301; cv=pass; d=google.com; s=arc-20160816; b=Sq5PEyT3plibEjFY+fHRTBcvFj4OZhTLj8Pp5Q56/dZ12bJ+oHWAu8t7mUtjEyLgwu B16VE83DPY1ZDFOzBmPnv+8a1dbcjIHmNabzAkEOvp3hGaHzJOQ1sBKTLya7fQg2UdDD 3fXFxtt7vOs3E/B/CmGaxdqLU+vh+YT/C7/ndn7uXGn+w2rCNQLbYoZ5DD5m4WiIynh/ uUczv3xTeM/qSmwUzgZlYdGgau6wJaBRy7TyGlgvf6+F8Q6HlXAP7tau/rwQBtxH0AlZ xB/2TCCfGdOaJAi8XXkhQekeYfyz9YLIR+NPkad8x94JYBGB14JDJjFoVROu+PbEZD3s 7Y7Q== 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:message-id:subject:cc :to:from:date:dkim-signature; bh=IKHBCvFKsC6Nzkx2NIWqoEqwLv1oOisbbcdd9aYPJks=; fh=KjTaZwSIt4Ccu3567jR00kKHI/ijuQ9O0wVVPefV5L0=; b=tuTg3DuCYPqBU4PMW8K/aKEavc5fgweHT0Ev9oHwr2B1m9HyL+gSyHGhqPgCAVAaKa dGjmKvqVr905iZKWYTqtr8DXcBdZmnLSlNn9pkhcovh2WDA2cNRMcbeiGVQ344SxJD8Z lW2IMjJIqoBaQtiul+ojM+cVIExlMsq5xNUKhiEojaMabAWt3k22nOhi/0V/sS43KlOP Kn5gkFw3xD3bIpHCh0+Do/0ob02GmbJ0bmjPygpV1KNjfF04c1nMP4d8ODJKBcPamGl3 kPWLYQTLodbObnK7agb7MqaIrBX+T4WBNE1OEz61U70MuySGtXXnhQ2w2KaFuthy5Isz pdyw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BABvXfHq; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-171450-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171450-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 a21-20020a05622a02d500b00437bd2a532dsi11807813qtx.120.2024.05.07.06.41.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 06:41:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171450-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=@linaro.org header.s=google header.b=BABvXfHq; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-171450-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171450-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 BC8681C23DCD for ; Tue, 7 May 2024 13:41:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B45B515F3F7; Tue, 7 May 2024 13:34:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="BABvXfHq" Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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 DCCF515EFDC for ; Tue, 7 May 2024 13:34:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715088889; cv=none; b=l2HVvNAG+jBsapJAp5R7+vr/e0hp0gk4tmTSJppiHtlgbeSWUqlN5EcX02mU2VUqvQ9qqdSqq7vBJ5bHqFak2wBc1lDTJMj8dIMOqTICTGLWkM+cV6z+Igcs+nhRR91C4cUmpQw95tLOpiBJduie0tmeKwDafBlfPcMI7LtSgGE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715088889; c=relaxed/simple; bh=RSGtQZGJXs8I6hGHPO4lrlq3ymfMFw5EiPxwgetnth0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mI+bAYr11Nbf/mrmcoYrlZzlkZeXe9JZo3DPN7vDa+kwajjqk8dH6evcNhTES81ub/V7gsT5AOwxZqueCwXIJaD0/V/V/yliFfZBwx86ANWbtCZGri1jNchiCbLYDGoP4mQnLYPcGZDCF6JH565uvUyeottZ16EI81GuAhBpCaY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=BABvXfHq; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-51f3761c96aso4082016e87.3 for ; Tue, 07 May 2024 06:34:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715088886; x=1715693686; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=IKHBCvFKsC6Nzkx2NIWqoEqwLv1oOisbbcdd9aYPJks=; b=BABvXfHq536qkZYcYEuvTYRhk1d1yC8T0W1sWwT8uHqfQyak7FaMLbQ9iMniyVaF5f TGccjdcBsuMGmtTI9fOM1a+Vs0hMwGUVI0F+YDspy7PKnUnjKcBnZTIUvuMuLNAY9VKs hur/uAr1GY81sR+mlbTAI6zROXre/hCJ59+1S20sdAxK2wZNftVk6kQ1yEUiIEShEu3V 2ovhQX79rL/s//vFp5vnNBQfs6B7Jqifjtks6xeJsHaxXmhL61piF/qwJVnyog+tkeQo jjqASijPzeaZcrLSOItOI6Uso8CkbpUe2SdK77ljNtUYW5b8tuwfwhJ2Iw/bVODs3mAC 91lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715088886; x=1715693686; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=IKHBCvFKsC6Nzkx2NIWqoEqwLv1oOisbbcdd9aYPJks=; b=r2wLmDxhl99QrOzUoF/QPK8WQn7O2iVOeG6KoulWTekcibRbnCIBX2NwEJSjOjMwWq j7HZzuPe5JjXC3yvpbqcsp/C9gu8ZfwxlwfM88AUtiUBeeNF57l4F0Tsb4pTU4eMnFdW 8I/Cffsb/HMiGewWv8ekv6wWyV+H6Sygk8rZUUznf/bA4+vTc2j1RDPkEbJ0p8aaWOJp kp0FSMkviKSFM34FaWzJoOtUDG42yIFzJ5E778JR/qv5ywFJdYQz7oZAcDUeAGIr+fW3 XuQ/IbYCNW/CUb4bPfcM0mKAZKsy184LXaaYuD98eywRga/cQ/1ML/Wl4dgvxbXZCiDb dctg== X-Forwarded-Encrypted: i=1; AJvYcCX1FqCUIqbMHtIk8fP4uZAfuUNX9F9//ezdaIWMSDmA2QBWeE56XWqjQ9Ra0q6MH096cC7NFnf6IlWvk09f2ejjFaKrtr4slgXIFFFA X-Gm-Message-State: AOJu0YxeRCJ1QxIzGKQrbe91POtpLC99lsbfDFqELfZ8j8tPwUqH35Kr vJeaKgHWyKTyx7WXMGyPlIb3BSJ2tNfiwf5g1i+kdS3wHQJkT8lpo//lmEjPjohrLHIv5G6kJ6e f X-Received: by 2002:a05:6512:4016:b0:51f:567b:c399 with SMTP id br22-20020a056512401600b0051f567bc399mr14982616lfb.62.1715088885984; Tue, 07 May 2024 06:34:45 -0700 (PDT) Received: from eriador.lumag.spb.ru (dzdbxzyyyyyyyyyyyykxt-3.rev.dnainternet.fi. [2001:14ba:a0c3:3a00::227]) by smtp.gmail.com with ESMTPSA id t6-20020ac243a6000000b0051d87562dfasm2116396lfl.27.2024.05.07.06.34.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 06:34:45 -0700 (PDT) Date: Tue, 7 May 2024 16:34:44 +0300 From: Dmitry Baryshkov To: Hans de Goede Cc: Maxime Ripard , Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , Christian =?utf-8?B?S8O2bmln?= , 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: 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: 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. > > 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. What about an app built by the user? The machines can still be multi-seat or have multiple users. > 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 ? > > Regards, > > Hans > -- With best wishes Dmitry