[v2,3/4] libcamera: shared_mem_object: Prevent memfd from shrinking or growing
diff mbox series

Message ID 20240731135936.2105-4-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • libcamera: Address soft ISP file seal TODO item
Related show

Commit Message

Laurent Pinchart July 31, 2024, 1:59 p.m. UTC
The memfd underlying the SharedMem object must not shrink, or memory
corruption will happen. Prevent this by setting the shrink seal on the
file. As there's no valid use case for growing the memory either, set
the grow seal as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/libcamera/shared_mem_object.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Hans de Goede July 31, 2024, 7:01 p.m. UTC | #1
Hi,

On 7/31/24 3:59 PM, Laurent Pinchart wrote:
> The memfd underlying the SharedMem object must not shrink, or memory
> corruption will happen. Prevent this by setting the shrink seal on the
> file. As there's no valid use case for growing the memory either, set
> the grow seal as well.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans



> ---
>  src/libcamera/shared_mem_object.cpp | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/shared_mem_object.cpp b/src/libcamera/shared_mem_object.cpp
> index 022645e71a35..d4c7991ad16a 100644
> --- a/src/libcamera/shared_mem_object.cpp
> +++ b/src/libcamera/shared_mem_object.cpp
> @@ -58,7 +58,8 @@ SharedMem::SharedMem() = default;
>   */
>  SharedMem::SharedMem(const std::string &name, std::size_t size)
>  {
> -	UniqueFD memfd = MemFd::create(name.c_str(), size);
> +	UniqueFD memfd = MemFd::create(name.c_str(), size, MemFd::Seal::Shrink |
> +				       MemFd::Seal::Grow);
>  	if (!memfd.isValid())
>  		return;
>

Patch
diff mbox series

diff --git a/src/libcamera/shared_mem_object.cpp b/src/libcamera/shared_mem_object.cpp
index 022645e71a35..d4c7991ad16a 100644
--- a/src/libcamera/shared_mem_object.cpp
+++ b/src/libcamera/shared_mem_object.cpp
@@ -58,7 +58,8 @@  SharedMem::SharedMem() = default;
  */
 SharedMem::SharedMem(const std::string &name, std::size_t size)
 {
-	UniqueFD memfd = MemFd::create(name.c_str(), size);
+	UniqueFD memfd = MemFd::create(name.c_str(), size, MemFd::Seal::Shrink |
+				       MemFd::Seal::Grow);
 	if (!memfd.isValid())
 		return;