[{"id":27064,"web_url":"https://patchwork.libcamera.org/comment/27064/","msgid":"<168327663741.1880445.11638291661026521011@Monstersaurus>","date":"2023-05-05T08:50:37","subject":"Re: [libcamera-devel] [PATCH] libcamera: Add missing O_CLOEXEC flag","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Elias,\n\nI would set the $SUBJECT as :\n\nlibcamera: v4l2_videodevice: Use O_CLOEXEC when exporting DMA buffers\n\nQuoting Elias Naur via libcamera-devel (2023-05-02 00:47:34)\n> Missed in commit 436b38fd89fe4324d2342084ef477a7a8809a001.\n\nIt's still good to explain why and what the commit is doing.\n\nWe can replicate most of the message from 436b38fd89fe:\n\nI'll propose this:\n\n\"\"\"\nFiles opened internally in libcamera without the O_CLOEXEC file will\nremain open upon a call to one of the exec(3) functions. As exec()\ndoesn't destroy local or global objects, this can lead to various side\neffects. Avoid this by opening file descriptors with O_CLOEXEC for all\ninternal files.\n\nThe O_CLOEXEC flag should also be set when obtaining file handles from\nthe V4L2 VIDIOC_EXPBUF operation, but was missed during the updates to\nboth d942bdc913c5 (\"libcamera: v4l2_device: openat(2) with O_CLOEXEC to\ncleanup after exec(3)\") and 436b38fd89fe (\"libcamera: Open files with\nO_CLOEXEC\").\n\nSet the O_CLOEXEC flag on calls to ioctl(VIDIOC_EXPBUF).\n\nFixes: 436b38fd89fe (\"libcamera: Open files with O_CLOEXEC\")\nSigned-off-by: Elias Naur <mail@eliasnaur.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\"\"\"\n\nI can update as required when applying if you (and at least one more\nreviewer) is happy with that.\n\n--\nKieran\n\n\n> \n> Signed-off-by: Elias Naur <mail@eliasnaur.com>\n> ---\n>  src/libcamera/v4l2_videodevice.cpp | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 1051997e..a72ef64d 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -1471,7 +1471,7 @@ UniqueFD V4L2VideoDevice::exportDmabufFd(unsigned int index,\n>         expbuf.type = bufferType_;\n>         expbuf.index = index;\n>         expbuf.plane = plane;\n> -       expbuf.flags = O_RDWR;\n> +       expbuf.flags = O_CLOEXEC | O_RDWR;\n>  \n>         ret = ioctl(VIDIOC_EXPBUF, &expbuf);\n>         if (ret < 0) {\n> -- \n> 2.39.2\n>","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 0FFE7BD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  5 May 2023 08:50:44 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5CF43633B4;\n\tFri,  5 May 2023 10:50:43 +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 F29DE61EAB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 May 2023 10:50:40 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net\n\t[82.37.23.78])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DE78C6D6;\n\tFri,  5 May 2023 10:50:36 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1683276643;\n\tbh=4EkqedTAiZ48lDA762/pcHeEC8zBogEAZ/yKLE27Ixg=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=nhBmGESDPmlvioBQiHO7R53FoYdS5U7l8leP4LhOICshbZ4tyTaWxJcAgos4Kiw5Q\n\tqXIhAzS8lhDRqP5pmC8TTovQnvs5VJd7W/4xaU2xz/QeClRgxqhuPEb55O3uHgFOD/\n\tpW71lwZcKZzFxhdeRDf4LmCNw/5GCLcZ3Rtl5/3B8eqV5P4chPv3YiR+VRhGbXMJTe\n\tMDPk6grJQMvCo7F87zWMpATadppfIrsgOFLdQ9l5/mLuUB90z1CxqTjgrqv0Q2XoET\n\tQVO0J3ZYDTyeMxTO3LZMvFEix87QZtIuv7APztU+DKPINbW5tMorkBYX3brCNJ0x4p\n\tdRghNYyk9TDyg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1683276637;\n\tbh=4EkqedTAiZ48lDA762/pcHeEC8zBogEAZ/yKLE27Ixg=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=Nhw16pRaZFc8bfa6Rme95V0vH2cBafP3Nlbj+rTAWoilmgsPaJeEogp/QOuplYqVX\n\tn1lW6Nuz9G8F/kRpUH732j3uEZp9Uo1NWljeNaVHZaQz4PXUD7Z94rfgX8QOlmk0Yc\n\tlvaUd7B7VdV8GQQNOPnpsuBp8H1yJK0yZ8mWwFPg="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Nhw16pRa\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20230501234734.43869-1-mail@eliasnaur.com>","References":"<20230501234734.43869-1-mail@eliasnaur.com>","To":"Elias Naur <mail@eliasnaur.com>, libcamera-devel@lists.libcamera.org","Date":"Fri, 05 May 2023 09:50:37 +0100","Message-ID":"<168327663741.1880445.11638291661026521011@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH] libcamera: Add missing O_CLOEXEC flag","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>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Elias Naur <mail@eliasnaur.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":27065,"web_url":"https://patchwork.libcamera.org/comment/27065/","msgid":"<20230505092621.GT4551@pendragon.ideasonboard.com>","date":"2023-05-05T09:26:21","subject":"Re: [libcamera-devel] [PATCH] libcamera: Add missing O_CLOEXEC flag","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Fri, May 05, 2023 at 09:50:37AM +0100, Kieran Bingham via libcamera-devel wrote:\n> Hi Elias,\n> \n> I would set the $SUBJECT as :\n> \n> libcamera: v4l2_videodevice: Use O_CLOEXEC when exporting DMA buffers\n> \n> Quoting Elias Naur via libcamera-devel (2023-05-02 00:47:34)\n> > Missed in commit 436b38fd89fe4324d2342084ef477a7a8809a001.\n> \n> It's still good to explain why and what the commit is doing.\n> \n> We can replicate most of the message from 436b38fd89fe:\n> \n> I'll propose this:\n> \n> \"\"\"\n> Files opened internally in libcamera without the O_CLOEXEC file will\n> remain open upon a call to one of the exec(3) functions. As exec()\n> doesn't destroy local or global objects, this can lead to various side\n> effects. Avoid this by opening file descriptors with O_CLOEXEC for all\n> internal files.\n> \n> The O_CLOEXEC flag should also be set when obtaining file handles from\n> the V4L2 VIDIOC_EXPBUF operation, but was missed during the updates to\n> both d942bdc913c5 (\"libcamera: v4l2_device: openat(2) with O_CLOEXEC to\n> cleanup after exec(3)\") and 436b38fd89fe (\"libcamera: Open files with\n> O_CLOEXEC\").\n> \n> Set the O_CLOEXEC flag on calls to ioctl(VIDIOC_EXPBUF).\n> \n> Fixes: 436b38fd89fe (\"libcamera: Open files with O_CLOEXEC\")\n> Signed-off-by: Elias Naur <mail@eliasnaur.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \"\"\"\n> \n> I can update as required when applying if you (and at least one more\n> reviewer) is happy with that.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> > Signed-off-by: Elias Naur <mail@eliasnaur.com>\n> > ---\n> >  src/libcamera/v4l2_videodevice.cpp | 2 +-\n> >  1 file changed, 1 insertion(+), 1 deletion(-)\n> > \n> > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> > index 1051997e..a72ef64d 100644\n> > --- a/src/libcamera/v4l2_videodevice.cpp\n> > +++ b/src/libcamera/v4l2_videodevice.cpp\n> > @@ -1471,7 +1471,7 @@ UniqueFD V4L2VideoDevice::exportDmabufFd(unsigned int index,\n> >         expbuf.type = bufferType_;\n> >         expbuf.index = index;\n> >         expbuf.plane = plane;\n> > -       expbuf.flags = O_RDWR;\n> > +       expbuf.flags = O_CLOEXEC | O_RDWR;\n> >  \n> >         ret = ioctl(VIDIOC_EXPBUF, &expbuf);\n> >         if (ret < 0) {","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 334AAC0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  5 May 2023 09:26:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9700B627DE;\n\tFri,  5 May 2023 11:26:14 +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 CEEF661EAB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 May 2023 11:26:12 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(133-32-181-51.west.xps.vectant.ne.jp [133.32.181.51])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B7BF02CF;\n\tFri,  5 May 2023 11:26:07 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1683278774;\n\tbh=iE/jprA3AZ8eRhYpWemNKFNjTOskNkNdPDMBdq3+uTI=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=x0NHYFQaeTmGCEJo7cTwOPKfpMtMGHlVGvYJ9DLCY8D6gQ766DS4TlmCWePuWfhk/\n\tgIN8N2fK7yIbuavngJ4hJyEPp7szD3KjfRE3s/xasNuh9shj8ZysMR/WIU5Wkf2q0T\n\tSfsYA5v7ZuF/9nc/z1yToZJrzIHchGWm1SYs1CTXr7AOR++WyksHCFfCmKX1DF9B38\n\tnSeRDNVDXgOzhG6Gx42jEoY5M8B+iWt7nVreT0jdDUarTKXCC+RfAV4AM/cU8Fgid+\n\tvQYL0vXfhhGBk4CumBQAqUkM+TCPr2bvFo4zYdzlRbhcVxf2FewHrvrk/uqp0IFpxC\n\tyjF1yAxS65/AA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1683278768;\n\tbh=iE/jprA3AZ8eRhYpWemNKFNjTOskNkNdPDMBdq3+uTI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ESaCnSsxKkEltY2F0v0NYX6P1g9xc9KV9gpefCZZuEA8JLe5YOdppGeKK1i57VtUX\n\tr0Jyi0qFeVW46JX+Q4FHLOPM350/ZWqFHSVX7SGUOD9Z6iKELJF8EWtwCNwZyDWubW\n\tWopVf3zzQA5HHCe7PmNR6t8h/mLiiBdR1RnHe/to="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"ESaCnSsx\"; dkim-atps=neutral","Date":"Fri, 5 May 2023 12:26:21 +0300","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<20230505092621.GT4551@pendragon.ideasonboard.com>","References":"<20230501234734.43869-1-mail@eliasnaur.com>\n\t<168327663741.1880445.11638291661026521011@Monstersaurus>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<168327663741.1880445.11638291661026521011@Monstersaurus>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: Add missing O_CLOEXEC flag","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, Elias Naur <mail@eliasnaur.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]