[{"id":30509,"web_url":"https://patchwork.libcamera.org/comment/30509/","msgid":"<87r0ba9g7m.fsf@redhat.com>","date":"2024-07-31T07:24:29","subject":"Re: [PATCH 2/3] libcamera: shared_mem_object: Prevent memfd from\n\tshrinking or growing","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Hi Laurent,\n\nthank you for the patch.\n\nLaurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n\n> The memfd underlying the SharedMem object must not shrink, or memory\n> corruption will happen. Prevent this by setting the shrink seal on the\n> file. As there's no valid use case for growing the memory either, set\n> the grow seal as well.\n\nMakes sense to me.\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/shared_mem_object.cpp | 3 ++-\n>  1 file changed, 2 insertions(+), 1 deletion(-)\n>\n> diff --git a/src/libcamera/shared_mem_object.cpp b/src/libcamera/shared_mem_object.cpp\n> index 022645e71a35..d4c7991ad16a 100644\n> --- a/src/libcamera/shared_mem_object.cpp\n> +++ b/src/libcamera/shared_mem_object.cpp\n> @@ -58,7 +58,8 @@ SharedMem::SharedMem() = default;\n>   */\n>  SharedMem::SharedMem(const std::string &name, std::size_t size)\n>  {\n> -\tUniqueFD memfd = MemFd::create(name.c_str(), size);\n> +\tUniqueFD memfd = MemFd::create(name.c_str(), size, MemFd::Seal::Shrink |\n> +\t\t\t\t       MemFd::Seal::Grow);\n>  \tif (!memfd.isValid())\n>  \t\treturn;","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 CA456C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 31 Jul 2024 07:24:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5760063374;\n\tWed, 31 Jul 2024 09:24:37 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A6AE16336B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 31 Jul 2024 09:24:35 +0200 (CEST)","from mail-ej1-f71.google.com (mail-ej1-f71.google.com\n\t[209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-691-N7rYqHQuOE2gWv_e2XEy6A-1; Wed, 31 Jul 2024 03:24:32 -0400","by mail-ej1-f71.google.com with SMTP id\n\ta640c23a62f3a-a6f571c3eefso322727566b.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 31 Jul 2024 00:24:32 -0700 (PDT)","from nuthatch (ip-77-48-47-2.net.vodafone.cz. [77.48.47.2])\n\tby smtp.gmail.com with ESMTPSA id\n\ta640c23a62f3a-a7acada29f2sm733443166b.162.2024.07.31.00.24.30\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 31 Jul 2024 00:24:30 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"NNQHhfv1\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1722410674;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=xZOoWO2WQMULJNnCaBJg67jHHT8y1CVbeszQbf+tEy4=;\n\tb=NNQHhfv1R4xzt/XCqqdc6yVUF4Fi+RNtmQ1iSQPMohM1hFCPKBxraS7QBwrmifVSYypSHD\n\trzN/cFnhDPbcYbLnCOBWRvZzpLmOSH46MEt0QvFx8/ZhMMEFipWXefzpA827ARKdV4IW1b\n\tKh894zxS6noL1p1QHXyfAQuRqmN+IRA=","X-MC-Unique":"N7rYqHQuOE2gWv_e2XEy6A-1","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1722410671; x=1723015471;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=xZOoWO2WQMULJNnCaBJg67jHHT8y1CVbeszQbf+tEy4=;\n\tb=jr+RVT2Hq0eS+isyjS5BkGcc4IAQQnqHoJfXOG8Vfni98t898LObDztRplz1FHbYVB\n\tMDqGPzSkXUQh+81irBk3j6hUe2cuInHdXsmFQeHWSd27dcSWTwoQc4eVaoaHVh9QHfMj\n\tJfA+wlXca/ZTgVDFUFmuVR3D+I6L/FLhEvReCbVvW79eL8Nf2PYV5pZfM3K3+vwXEeQ7\n\trPjTc4CgTd74rsgN6xcPF8bIYfXwTjKD2jTwNUpkORmAvXqWpbQFutIsnVU5y05QAjK5\n\tTWOwmMclDphnYQqebwowW3d8SE30TZJ8J08cgxg9JqJP7U3gF0xRAO0vMyTd8DsV8zAc\n\tnGAg==","X-Gm-Message-State":"AOJu0YwlwNk++1hYOrIU75JKvIDH78jCCrKnI4R0AR8PqUCNsbQ1yQ4F\n\ttfC/E0FHSpXqiS7Km7IIBunTqKEyqfEyliAhjg5x99qsci0WAPdjKaCMF25r9+Bgcv77SA6/w03\n\t9fU9S2w7M18URTgYVTIX5sEc1wKhpatgr5SZXfeSPE4GKRUxuipRc2zFmuzPssA4AXNxUT2zZk6\n\tc36Nfmp72+GnTLS7BuL0ejS9TW/xGci95nV9vQTO8KBQ9RG5losg+HeLU=","X-Received":["by 2002:a17:907:7e9f:b0:a77:c043:5b5a with SMTP id\n\ta640c23a62f3a-a7d400ad8fcmr976179866b.39.1722410671410; \n\tWed, 31 Jul 2024 00:24:31 -0700 (PDT)","by 2002:a17:907:7e9f:b0:a77:c043:5b5a with SMTP id\n\ta640c23a62f3a-a7d400ad8fcmr976178066b.39.1722410670989; \n\tWed, 31 Jul 2024 00:24:30 -0700 (PDT)"],"X-Google-Smtp-Source":"AGHT+IGX0dEnBDJXNIwYNy5y5paJxH5G5lOEnze8fw5EwLHKRxhdGkGYa5iJ95kFEuMXQwERe4CIIA==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH 2/3] libcamera: shared_mem_object: Prevent memfd from\n\tshrinking or growing","In-Reply-To":"<20240730232708.17399-3-laurent.pinchart@ideasonboard.com>\n\t(Laurent Pinchart's message of \"Wed, 31 Jul 2024 02:27:07 +0300\")","References":"<20240730232708.17399-1-laurent.pinchart@ideasonboard.com>\n\t<20240730232708.17399-3-laurent.pinchart@ideasonboard.com>","Date":"Wed, 31 Jul 2024 09:24:29 +0200","Message-ID":"<87r0ba9g7m.fsf@redhat.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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":30512,"web_url":"https://patchwork.libcamera.org/comment/30512/","msgid":"<172241521111.392292.13402618738280505384@ping.linuxembedded.co.uk>","date":"2024-07-31T08:40:11","subject":"Re: [PATCH 2/3] libcamera: shared_mem_object: Prevent memfd from\n\tshrinking or growing","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Milan Zamazal (2024-07-31 08:24:29)\n> Hi Laurent,\n> \n> thank you for the patch.\n> \n> Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n> \n> > The memfd underlying the SharedMem object must not shrink, or memory\n> > corruption will happen. Prevent this by setting the shrink seal on the\n> > file. As there's no valid use case for growing the memory either, set\n> > the grow seal as well.\n> \n> Makes sense to me.\n> \n> Reviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\nHaha, I was going to ask about this in the previous patch - then I\ndiscovered this ;-)\n\nBut should we - with the same logic also add MemFd::Seal::Grow to the\nallocFromUDmaBuf() implementation too?\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> \n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  src/libcamera/shared_mem_object.cpp | 3 ++-\n> >  1 file changed, 2 insertions(+), 1 deletion(-)\n> >\n> > diff --git a/src/libcamera/shared_mem_object.cpp b/src/libcamera/shared_mem_object.cpp\n> > index 022645e71a35..d4c7991ad16a 100644\n> > --- a/src/libcamera/shared_mem_object.cpp\n> > +++ b/src/libcamera/shared_mem_object.cpp\n> > @@ -58,7 +58,8 @@ SharedMem::SharedMem() = default;\n> >   */\n> >  SharedMem::SharedMem(const std::string &name, std::size_t size)\n> >  {\n> > -     UniqueFD memfd = MemFd::create(name.c_str(), size);\n> > +     UniqueFD memfd = MemFd::create(name.c_str(), size, MemFd::Seal::Shrink |\n> > +                                    MemFd::Seal::Grow);\n> >       if (!memfd.isValid())\n> >               return;\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 2EE6CBDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 31 Jul 2024 08:40:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 054E363375;\n\tWed, 31 Jul 2024 10:40:16 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 72CC36336F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 31 Jul 2024 10:40:14 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8E53A7E4;\n\tWed, 31 Jul 2024 10:39:26 +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=\"pWIGsivB\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1722415166;\n\tbh=B/vPl5TcVkDx3UYCtHV1lT4lhc4UZiGvko4bxL6w22E=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=pWIGsivBEwh/qh/gstBIwwUKEcNXY4SK6mkiej3CpAK4bKBrLTcEkE0GRxifwV++X\n\tjcNS9lRUc32Wqansq6LvlTFQRvdwyPqlZhGJt3hcQvi1S8mUygt3oEqhqq7rN6G+RB\n\t17tbFBaIdJU1F4yevXooh1fUmfjRMeYX4Ip76IZM=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<87r0ba9g7m.fsf@redhat.com>","References":"<20240730232708.17399-1-laurent.pinchart@ideasonboard.com>\n\t<20240730232708.17399-3-laurent.pinchart@ideasonboard.com>\n\t<87r0ba9g7m.fsf@redhat.com>","Subject":"Re: [PATCH 2/3] libcamera: shared_mem_object: Prevent memfd from\n\tshrinking or growing","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tMilan Zamazal <mzamazal@redhat.com>","Date":"Wed, 31 Jul 2024 09:40:11 +0100","Message-ID":"<172241521111.392292.13402618738280505384@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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":30514,"web_url":"https://patchwork.libcamera.org/comment/30514/","msgid":"<20240731085414.GN8146@pendragon.ideasonboard.com>","date":"2024-07-31T08:54:14","subject":"Re: [PATCH 2/3] libcamera: shared_mem_object: Prevent memfd from\n\tshrinking or growing","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Wed, Jul 31, 2024 at 09:40:11AM +0100, Kieran Bingham wrote:\n> Quoting Milan Zamazal (2024-07-31 08:24:29)\n> > Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n> > \n> > > The memfd underlying the SharedMem object must not shrink, or memory\n> > > corruption will happen. Prevent this by setting the shrink seal on the\n> > > file. As there's no valid use case for growing the memory either, set\n> > > the grow seal as well.\n> > \n> > Makes sense to me.\n> > \n> > Reviewed-by: Milan Zamazal <mzamazal@redhat.com>\n> \n> Haha, I was going to ask about this in the previous patch - then I\n> discovered this ;-)\n> \n> But should we - with the same logic also add MemFd::Seal::Grow to the\n> allocFromUDmaBuf() implementation too?\n\nI think we could. Do you want to submit a patch ? :-)\n\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > > ---\n> > >  src/libcamera/shared_mem_object.cpp | 3 ++-\n> > >  1 file changed, 2 insertions(+), 1 deletion(-)\n> > >\n> > > diff --git a/src/libcamera/shared_mem_object.cpp b/src/libcamera/shared_mem_object.cpp\n> > > index 022645e71a35..d4c7991ad16a 100644\n> > > --- a/src/libcamera/shared_mem_object.cpp\n> > > +++ b/src/libcamera/shared_mem_object.cpp\n> > > @@ -58,7 +58,8 @@ SharedMem::SharedMem() = default;\n> > >   */\n> > >  SharedMem::SharedMem(const std::string &name, std::size_t size)\n> > >  {\n> > > -     UniqueFD memfd = MemFd::create(name.c_str(), size);\n> > > +     UniqueFD memfd = MemFd::create(name.c_str(), size, MemFd::Seal::Shrink |\n> > > +                                    MemFd::Seal::Grow);\n> > >       if (!memfd.isValid())\n> > >               return;","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 45308C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 31 Jul 2024 08:54:38 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6F50163374;\n\tWed, 31 Jul 2024 10:54:37 +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 2F8D66336B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 31 Jul 2024 10:54:35 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 48ADF7E4;\n\tWed, 31 Jul 2024 10:53:47 +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=\"Ws5qQGa9\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1722416027;\n\tbh=KEVlZsJZ9CrjjlsMnHbS2Sf0nm6Kyjs2KOONO+aVHkM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Ws5qQGa9BBsoH4nZRteNpW042eqi7FGnMrjFoiaR8lvRCdL0XhaVWScaJklNMveVn\n\tE5J1WIMobkSrf7C6oYBh4SSFNnPJyPu9YyNN56IkSeTxryc5n1PtAuuNPP9oUyqVV0\n\tetjv+Vl57nqiYiwMbV/HEIyHE0SSKaPpZS8Pg/Zc=","Date":"Wed, 31 Jul 2024 11:54:14 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH 2/3] libcamera: shared_mem_object: Prevent memfd from\n\tshrinking or growing","Message-ID":"<20240731085414.GN8146@pendragon.ideasonboard.com>","References":"<20240730232708.17399-1-laurent.pinchart@ideasonboard.com>\n\t<20240730232708.17399-3-laurent.pinchart@ideasonboard.com>\n\t<87r0ba9g7m.fsf@redhat.com>\n\t<172241521111.392292.13402618738280505384@ping.linuxembedded.co.uk>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<172241521111.392292.13402618738280505384@ping.linuxembedded.co.uk>","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>"}}]