libcamera: dma_buf_allocator: Create memfd with CLOEXEC
diff mbox series

Message ID 20240605075055.18039-1-laurent.pinchart@ideasonboard.com
State Accepted
Commit 9c2ca46391ea2ba089d5d082a0dbdd3b15b28498
Headers show
Series
  • libcamera: dma_buf_allocator: Create memfd with CLOEXEC
Related show

Commit Message

Laurent Pinchart June 5, 2024, 7:50 a.m. UTC
Ensure that the memfd file descriptor won't be leaked to child processes
by creating it with MFD_CLOEXEC.

Fixes: ea4baaacc325 ("libcamera: DmaBufAllocator: Support allocating from /dev/udmabuf")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/dma_buf_allocator.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


base-commit: 98071d3109c131820439f61d9380c0bd4cd2119a

Comments

Hans de Goede June 5, 2024, 8:04 a.m. UTC | #1
Hi,

On 6/5/24 9:50 AM, Laurent Pinchart wrote:
> Ensure that the memfd file descriptor won't be leaked to child processes
> by creating it with MFD_CLOEXEC.
> 
> Fixes: ea4baaacc325 ("libcamera: DmaBufAllocator: Support allocating from /dev/udmabuf")
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Thanks, patch looks good to me:

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

Regards,

Hans



> ---
>  src/libcamera/dma_buf_allocator.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp
> index 5ae517210adf..5ec29949c66a 100644
> --- a/src/libcamera/dma_buf_allocator.cpp
> +++ b/src/libcamera/dma_buf_allocator.cpp
> @@ -132,7 +132,7 @@ UniqueFD DmaBufAllocator::allocFromUDmaBuf(const char *name, std::size_t size)
>  	std::size_t pageMask = sysconf(_SC_PAGESIZE) - 1;
>  	size = (size + pageMask) & ~pageMask;
>  
> -	int ret = memfd_create(name, MFD_ALLOW_SEALING);
> +	int ret = memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC);
>  	if (ret < 0) {
>  		ret = errno;
>  		LOG(DmaBufAllocator, Error)
> 
> base-commit: 98071d3109c131820439f61d9380c0bd4cd2119a
Kieran Bingham June 5, 2024, 8:10 a.m. UTC | #2
Quoting Laurent Pinchart (2024-06-05 08:50:55)
> Ensure that the memfd file descriptor won't be leaked to child processes
> by creating it with MFD_CLOEXEC.
> 
> Fixes: ea4baaacc325 ("libcamera: DmaBufAllocator: Support allocating from /dev/udmabuf")
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Oh yeah, we hit this before...


Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
>  src/libcamera/dma_buf_allocator.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp
> index 5ae517210adf..5ec29949c66a 100644
> --- a/src/libcamera/dma_buf_allocator.cpp
> +++ b/src/libcamera/dma_buf_allocator.cpp
> @@ -132,7 +132,7 @@ UniqueFD DmaBufAllocator::allocFromUDmaBuf(const char *name, std::size_t size)
>         std::size_t pageMask = sysconf(_SC_PAGESIZE) - 1;
>         size = (size + pageMask) & ~pageMask;
>  
> -       int ret = memfd_create(name, MFD_ALLOW_SEALING);
> +       int ret = memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC);
>         if (ret < 0) {
>                 ret = errno;
>                 LOG(DmaBufAllocator, Error)
> 
> base-commit: 98071d3109c131820439f61d9380c0bd4cd2119a
> -- 
> Regards,
> 
> Laurent Pinchart
>

Patch
diff mbox series

diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp
index 5ae517210adf..5ec29949c66a 100644
--- a/src/libcamera/dma_buf_allocator.cpp
+++ b/src/libcamera/dma_buf_allocator.cpp
@@ -132,7 +132,7 @@  UniqueFD DmaBufAllocator::allocFromUDmaBuf(const char *name, std::size_t size)
 	std::size_t pageMask = sysconf(_SC_PAGESIZE) - 1;
 	size = (size + pageMask) & ~pageMask;
 
-	int ret = memfd_create(name, MFD_ALLOW_SEALING);
+	int ret = memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC);
 	if (ret < 0) {
 		ret = errno;
 		LOG(DmaBufAllocator, Error)