From efc7a85bc00a767427c219a43d0bb420dfc6361b Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Wed, 31 Jul 2024 02:09:44 +0300 Subject: libcamera: shared_mem_object: Prevent memfd from shrinking or growing 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 Reviewed-by: Milan Zamazal Reviewed-by: Kieran Bingham Tested-by: Milan Zamazal Tested-by: Hans de Goede Reviewed-by: Hans de Goede --- 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 022645e7..d4c7991a 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; -- cgit v1.2.1