[{"id":39660,"web_url":"https://patchwork.libcamera.org/comment/39660/","msgid":"<20260709194716.GA1052680@killaraus.ideasonboard.com>","date":"2026-07-09T19:47:16","subject":"Re: [PATCH] DmaBufAllocator: Open heap device files O_RDONLY","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Thu, Jul 09, 2026 at 11:30:45AM -0700, T.J. Mercier wrote:\n> The write access mode is not required to issue ioctls and allocate\n> dma-bufs from heaps. Applications should be opening them as O_RDONLY.\n\nIs that explictly documented somewhere, or just the current behaviour ?\nI suppose it won't change as that would introduce regressions.\n\n> Permission errors can be encountered while attempting to open() files in\n> /dev/dma_heap/* on systems where write permissions are not available. So\n> apply the principle of least privilege and remove the write access mode.\n\nI'm curious, what systems have you encountered read-only dma-buf heap\ndevice nodes on ?\n\n> Signed-off-by: T.J. Mercier <tjmercier@google.com>\n> ---\n>  src/libcamera/dma_buf_allocator.cpp | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp\n> index d8c62dd67..c673d23ec 100644\n> --- a/src/libcamera/dma_buf_allocator.cpp\n> +++ b/src/libcamera/dma_buf_allocator.cpp\n> @@ -100,7 +100,7 @@ DmaBufAllocator::DmaBufAllocator(DmaBufAllocatorFlags type)\n>  \t\tif (!(type & info.type))\n>  \t\t\tcontinue;\n>  \n> -\t\tint ret = ::open(info.deviceNodeName, O_RDWR | O_CLOEXEC, 0);\n> +\t\tint ret = ::open(info.deviceNodeName, O_RDONLY | O_CLOEXEC, 0);\n>  \t\tif (ret < 0) {\n>  \t\t\tret = errno;\n>  \t\t\tLOG(DmaBufAllocator, Debug)","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 1EE3DC3318\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  9 Jul 2026 19:47:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2B4C266104;\n\tThu,  9 Jul 2026 21:47:20 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 762BC660E3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  9 Jul 2026 21:47:18 +0200 (CEST)","from killaraus.ideasonboard.com\n\t(2001-14ba-70f3-e800--a06.rev.dnainternet.fi\n\t[IPv6:2001:14ba:70f3:e800::a06])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9100F289;\n\tThu,  9 Jul 2026 21:46:27 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"khR/B31k\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1783626387;\n\tbh=KNZDjunpP3TEjlaO01OqFNUxV+FD80mKQ/+ek+QsNBI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=khR/B31k/do7gc4iNIaU+h6u4BjihB8Ow47rdavKe9sMFlJki/t6zd2z1ogwgq+ws\n\tfIbpQvo4iLIzaubavoeMiAtaQ6FgU9TGRXeU9m8xkaCMJBykwUXkH7iC+z5TrO0JIt\n\tRaC5loTNlBdlKYigO+N+0m7bcDvGkGvQ4pcJ372s=","Date":"Thu, 9 Jul 2026 22:47:16 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"\"T.J. Mercier\" <tjmercier@google.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH] DmaBufAllocator: Open heap device files O_RDONLY","Message-ID":"<20260709194716.GA1052680@killaraus.ideasonboard.com>","References":"<20260709183049.2282221-1-tjmercier@google.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20260709183049.2282221-1-tjmercier@google.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":39661,"web_url":"https://patchwork.libcamera.org/comment/39661/","msgid":"<CABdmKX3+XwKh1UC_8_B2u=71mjByQY8PYMfoKrhgFsEu56q2+g@mail.gmail.com>","date":"2026-07-09T20:04:42","subject":"Re: [PATCH] DmaBufAllocator: Open heap device files O_RDONLY","submitter":{"id":385,"url":"https://patchwork.libcamera.org/api/people/385/","name":"T.J. Mercier","email":"tjmercier@google.com"},"content":"On Thu, Jul 9, 2026 at 12:47 PM Laurent Pinchart\n<laurent.pinchart@ideasonboard.com> wrote:\n>\n> On Thu, Jul 09, 2026 at 11:30:45AM -0700, T.J. Mercier wrote:\n> > The write access mode is not required to issue ioctls and allocate\n> > dma-bufs from heaps. Applications should be opening them as O_RDONLY.\n>\n> Is that explictly documented somewhere, or just the current behaviour ?\n> I suppose it won't change as that would introduce regressions.\n\nHi, Unfortunately I don't think it's documented anywhere. Even the\nkernel selftests are mixed (which some users were pointing at), but\nI've addressed those here:\nhttps://lore.kernel.org/all/20260701192210.2997769-1-tjmercier@google.com/\n\nThe file descriptor is really all that's needed, however it is\nobtained. The ioctl handler in the dma-heap driver intentionally\nperforms no permission checks.\n\n> > Permission errors can be encountered while attempting to open() files in\n> > /dev/dma_heap/* on systems where write permissions are not available. So\n> > apply the principle of least privilege and remove the write access mode.\n>\n> I'm curious, what systems have you encountered read-only dma-buf heap\n> device nodes on ?\n\nAndroid: https://cs.android.com/android/platform/superproject/+/android-latest-release:system/core/rootdir/ueventd.rc;l=55-57\n\n> > Signed-off-by: T.J. Mercier <tjmercier@google.com>\n> > ---\n> >  src/libcamera/dma_buf_allocator.cpp | 2 +-\n> >  1 file changed, 1 insertion(+), 1 deletion(-)\n> >\n> > diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp\n> > index d8c62dd67..c673d23ec 100644\n> > --- a/src/libcamera/dma_buf_allocator.cpp\n> > +++ b/src/libcamera/dma_buf_allocator.cpp\n> > @@ -100,7 +100,7 @@ DmaBufAllocator::DmaBufAllocator(DmaBufAllocatorFlags type)\n> >               if (!(type & info.type))\n> >                       continue;\n> >\n> > -             int ret = ::open(info.deviceNodeName, O_RDWR | O_CLOEXEC, 0);\n> > +             int ret = ::open(info.deviceNodeName, O_RDONLY | O_CLOEXEC, 0);\n> >               if (ret < 0) {\n> >                       ret = errno;\n> >                       LOG(DmaBufAllocator, Debug)\n>\n> --\n> Regards,\n>\n> Laurent Pinchart","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id C665DC3318\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  9 Jul 2026 20:04:56 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 196DA660F9;\n\tThu,  9 Jul 2026 22:04:56 +0200 (CEST)","from mail-wm1-x336.google.com (mail-wm1-x336.google.com\n\t[IPv6:2a00:1450:4864:20::336])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 88C6E660E3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  9 Jul 2026 22:04:55 +0200 (CEST)","by mail-wm1-x336.google.com with SMTP id\n\t5b1f17b1804b1-493c556ada3so13955e9.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 09 Jul 2026 13:04:55 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"kA7FLgul\"; dkim-atps=neutral","ARC-Seal":"i=1; a=rsa-sha256; t=1783627495; cv=none;\n\td=google.com; s=arc-20260327;\n\tb=cS1PhwXtkeuGcWQs3PVSFKuERYVxZOjV16mwpDpkzJqduoUAXsS84Y9P3HKANtVSSv\n\tSLmZ4BsDhhpZJhibdLK8Ml+LZcuBJEN9NlIbbQTQrpmY6l8mnENQlO/q8d0P0lo57Gq2\n\tStTXIXYpacuUl0Pk0L8Dod7cjYKTiUTbnDCC514IlCGvdMH/BWmzoYHDx4IvYPgTv5Bo\n\tWUjDEWTVYGuCqZgO1oAaXj3mEX8SAGkN9cYc6/58W6JA6m/5OqmhLgb1RN7lVAW9ZFqc\n\taLJ4xEkIB+GEFzcgzrcUGkdz5/KGCazYBHPUKCE7MuXZQ6MMCuXp281bYH3WU48b42v6\n\twE0g==","ARC-Message-Signature":"i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n\ts=arc-20260327; \n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:dkim-signature;\n\tbh=lpSYVWxY5ZCvebmsNf0ao640n8AOkC+esFCET4kQ0Vs=;\n\tfh=kAwbguIY0wmqf1QQypnTiLH20ruRu7+JSSp6fzxLlN4=;\n\tb=UAMeQSYKhDHMPsw9X4fQR6zbk/AmfVeO9qn74APTaALXW/fzQRDUoLRiVOV/ILKKri\n\tXzn9WvimIZ0q8BknCFjd7qwhC58pwPfyBfk6/q3i9+5MHXFzEIyV365nxNL63V8L8Pqe\n\tX6yqR3XW6p9y/vUIw6up4UuPqxl/TDQsprOnPKQjCZiTo2WsiC9ItaFImt8tAk5vfVkM\n\tWNgyRZP8Hz2f4rn4xZ0j5lISzD64aqRjMYfWoMdc8VpxJFAxztkTqf2KXdQmcSwmFh1R\n\t4el3V4PFXqAetj+78tWP7079qk7TkBjIrY++Exq2Kib+IpqewEij9u9Tgx3027LmtUdc\n\tnwig==; darn=lists.libcamera.org","ARC-Authentication-Results":"i=1; mx.google.com; arc=none","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=google.com; s=20251104; t=1783627495; x=1784232295;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:content-type:cc:to:subject:message-id\n\t:date:from:in-reply-to:references:mime-version:from:to:cc:subject\n\t:date:message-id:reply-to:content-type;\n\tbh=lpSYVWxY5ZCvebmsNf0ao640n8AOkC+esFCET4kQ0Vs=;\n\tb=kA7FLgul0rRGlOdwYV7MZKqVD/Do//LHAxyid9fuMvR3Tt3vrVh86HwejiDxn9OrcD\n\tfJNE28U4f6/wJPo9t6+Mz7iYbB1/8FTcJq62Qz2QMU48loCjbtQsOgSUs5URNI5wl0Qp\n\tpr3DpiyejmcHbyAL3D0JCVv9+8EvPsu+oMJ8CN1g1xYJcFu0ZjUOEOq/EpeW9TXLFW+5\n\tuNRc2Au2bvpnxrVJCy9UK4NbzJHyqcCaUYBMHHi2W8mQRORTyT046xaUUslktPXW45Kk\n\tEGXaLRILejfHhCmmd8zstYLIo471Oi3R2CykxSUipIMwRaku1VHBMoY8nJ8pkAmZkjSv\n\tirlQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1783627495; x=1784232295;\n\th=content-transfer-encoding:content-type:cc:to:subject:message-id\n\t:date:from:in-reply-to:references:mime-version:x-gm-gg\n\t:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to\n\t:content-type;\n\tbh=lpSYVWxY5ZCvebmsNf0ao640n8AOkC+esFCET4kQ0Vs=;\n\tb=OBxjcwVRKK0i41GFy1YIs/J6cD4SlJQSQVbXqOfYYUqZt/I1aowpfC7C1SRngZMqpa\n\tfqkyeoe6p7g2CQodZDzHTV+BKF74us6dRy4Iz7JUx3mvr//4/xq+rZNAkrxYGPUKWPKJ\n\tufyMCFy3T3/g8mUkpGzo7T6LYFlNbxqP6SMzp+vx2COeQglz+GlkV5BB7CtWPzn6Vv1Q\n\tYjK9PhNnnZfk2zYuKXNCy2tDO7vodGzRFf9xk8o6/jOy9nA6ZvWh8ZZvcDXdbZAC3j1v\n\ttv6wdrK5W5P/c0Ao6VSWv5mTjDrBVYOQsYtgBPpTrK5GJPfmpXA9XGYvp8/mMnh/kTcg\n\tP06A==","X-Gm-Message-State":"AOJu0YweKHnh9u8JpvFWOXWAqe/Slwo9xjnmjysghKxpKnXjp5tLw4C+\n\tKTJbcHGYKHKbpIcBdFpbAls7RPFDdL3wkPY3EJmSqfWdL0SEZcYs9oGuO7gEEJ2CHuqZN7lPN9a\n\t8Y0OJ3agzNlpmBzVJ3Q809v4l2SHPTfoaqD6X+MMRqKZirfPMpbnKG+CrMNKLSw==","X-Gm-Gg":"AfdE7cl/kUzj9dnhkGlNCvjNFLYq9zQIcuFPjVq9uV7AK3sJJenZLoFAUWgQ4fyLMJF\n\tz7JNXjJcfp7thiuoEWFroiQ/+lq6omEoZi7sa+mXO3hsz/vlhH4+q3P4uy+6ABzRDTah0IdQLY/\n\t1NiVw/9FNVbIBlWH2XCuH6qyZSug5sTz4tbiGePicPMLggr45gjqTfBgrbS/6u2U82Fy6XNB5k1\n\tqi9m31LpYKf36NgfEkPLsq1Fg4ckGVHrCIxksGgdLpiOEczebhayi0yGyDbe6y5Y4OPrdvVTeBl\n\tfnKZ5ut+By9jALshsOsJ2RWaOfA5SkB6y/E46bnA1h2JDhIupdY/dmf1goU=","X-Received":"by 2002:a05:600c:63d0:b0:45f:2940:d194 with SMTP id\n\t5b1f17b1804b1-493f2cb0368mr138815e9.2.1783627494616; Thu, 09 Jul 2026\n\t13:04:54 -0700 (PDT)","MIME-Version":"1.0","References":"<20260709183049.2282221-1-tjmercier@google.com>\n\t<20260709194716.GA1052680@killaraus.ideasonboard.com>","In-Reply-To":"<20260709194716.GA1052680@killaraus.ideasonboard.com>","From":"\"T.J. Mercier\" <tjmercier@google.com>","Date":"Thu, 9 Jul 2026 13:04:42 -0700","X-Gm-Features":"AUfX_myn7nahk1xySqKoG6dSJMGSS0u5IbRiN7BHQCDxh6a2hL8vIhOYQ2YW5wI","Message-ID":"<CABdmKX3+XwKh1UC_8_B2u=71mjByQY8PYMfoKrhgFsEu56q2+g@mail.gmail.com>","Subject":"Re: [PATCH] DmaBufAllocator: Open heap device files O_RDONLY","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]