All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH libdrm] amdgpu: make sure to set CLOEXEC on duplicated FDs
@ 2018-07-17  9:04 Christian König
       [not found] ` <20180717090431.6830-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2018-07-17  9:04 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW, Jerry.Zhang-5C7GfCeVMHo

Otherwise we leak file descriptors into child processes.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 amdgpu/amdgpu_device.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
index 34ac95b8..d7aec6a4 100644
--- a/amdgpu/amdgpu_device.c
+++ b/amdgpu/amdgpu_device.c
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <fcntl.h>
 
 #include "xf86drm.h"
 #include "amdgpu_drm.h"
@@ -205,7 +206,7 @@ int amdgpu_device_initialize(int fd,
 			return r;
 		}
 		if ((flag_auth) && (!flag_authexist)) {
-			dev->flink_fd = dup(fd);
+			dev->flink_fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
 		}
 		*major_version = dev->major_version;
 		*minor_version = dev->minor_version;
@@ -239,7 +240,7 @@ int amdgpu_device_initialize(int fd,
 		goto cleanup;
 	}
 
-	dev->fd = dup(fd);
+	dev->fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
 	dev->flink_fd = dev->fd;
 	dev->major_version = version->version_major;
 	dev->minor_version = version->version_minor;
-- 
2.14.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH libdrm] amdgpu: make sure to set CLOEXEC on duplicated FDs
       [not found] ` <20180717090431.6830-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
@ 2018-07-17  9:19   ` Zhang, Jerry (Junwei)
  2018-07-17  9:19   ` Michel Dänzer
  1 sibling, 0 replies; 3+ messages in thread
From: Zhang, Jerry (Junwei) @ 2018-07-17  9:19 UTC (permalink / raw)
  To: Christian König, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On 07/17/2018 05:04 PM, Christian König wrote:
> Otherwise we leak file descriptors into child processes.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>

Yeah, that's the key point that dup could remove CLOEXEC effect.

Reviewed-and-Tested-by: Junwei Zhang <Jerry.Zhang@amd.com>

> ---
>   amdgpu/amdgpu_device.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
> index 34ac95b8..d7aec6a4 100644
> --- a/amdgpu/amdgpu_device.c
> +++ b/amdgpu/amdgpu_device.c
> @@ -34,6 +34,7 @@
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <unistd.h>
> +#include <fcntl.h>
>
>   #include "xf86drm.h"
>   #include "amdgpu_drm.h"
> @@ -205,7 +206,7 @@ int amdgpu_device_initialize(int fd,
>   			return r;
>   		}
>   		if ((flag_auth) && (!flag_authexist)) {
> -			dev->flink_fd = dup(fd);
> +			dev->flink_fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
>   		}
>   		*major_version = dev->major_version;
>   		*minor_version = dev->minor_version;
> @@ -239,7 +240,7 @@ int amdgpu_device_initialize(int fd,
>   		goto cleanup;
>   	}
>
> -	dev->fd = dup(fd);
> +	dev->fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
>   	dev->flink_fd = dev->fd;
>   	dev->major_version = version->version_major;
>   	dev->minor_version = version->version_minor;
>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH libdrm] amdgpu: make sure to set CLOEXEC on duplicated FDs
       [not found] ` <20180717090431.6830-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2018-07-17  9:19   ` Zhang, Jerry (Junwei)
@ 2018-07-17  9:19   ` Michel Dänzer
  1 sibling, 0 replies; 3+ messages in thread
From: Michel Dänzer @ 2018-07-17  9:19 UTC (permalink / raw)
  To: Christian König, Jerry.Zhang-5C7GfCeVMHo
  Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On 2018-07-17 11:04 AM, Christian König wrote:
> Otherwise we leak file descriptors into child processes.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>  amdgpu/amdgpu_device.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
> index 34ac95b8..d7aec6a4 100644
> --- a/amdgpu/amdgpu_device.c
> +++ b/amdgpu/amdgpu_device.c
> @@ -34,6 +34,7 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <unistd.h>
> +#include <fcntl.h>
>  
>  #include "xf86drm.h"
>  #include "amdgpu_drm.h"
> @@ -205,7 +206,7 @@ int amdgpu_device_initialize(int fd,
>  			return r;
>  		}
>  		if ((flag_auth) && (!flag_authexist)) {
> -			dev->flink_fd = dup(fd);
> +			dev->flink_fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
>  		}
>  		*major_version = dev->major_version;
>  		*minor_version = dev->minor_version;
> @@ -239,7 +240,7 @@ int amdgpu_device_initialize(int fd,
>  		goto cleanup;
>  	}
>  
> -	dev->fd = dup(fd);
> +	dev->fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
>  	dev->flink_fd = dev->fd;
>  	dev->major_version = version->version_major;
>  	dev->minor_version = version->version_minor;
> 

Nice catch.

Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-17  9:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-17  9:04 [PATCH libdrm] amdgpu: make sure to set CLOEXEC on duplicated FDs Christian König
     [not found] ` <20180717090431.6830-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-07-17  9:19   ` Zhang, Jerry (Junwei)
2018-07-17  9:19   ` Michel Dänzer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.