From 8fcb631389123ab7f5d795ae3a36a67842b3028c Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Thu, 5 Jun 2014 20:26:25 -0700 Subject: [PATCH] adb: avoid leaking file descriptors If an adb shell connection comes in while taking a screenshot, an open pipe file descriptor will be leaked to the shell process. This causes SELinux denials of the form: avc: denied { read } for path="pipe:[21838]" dev="pipefs" ino=21838 scontext=u:r:shell:s0 tcontext=u:r:adbd:s0 tclass=fifo_file permissive=0 avc: denied { write } for path="pipe:[21838]" dev="pipefs" ino=21838 scontext=u:r:shell:s0 tcontext=u:r:adbd:s0 tclass=fifo_file permissive=0 Set O_CLOEXEC on the pipe connections, to avoid leaking them across an exec boundary. Bug: 15437785 Change-Id: Id2304b316bd7082d8baac246dce1f0e0e26e9197 --- adb/framebuffer_service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adb/framebuffer_service.c b/adb/framebuffer_service.c index fa7fd98dc..8cbe8403c 100644 --- a/adb/framebuffer_service.c +++ b/adb/framebuffer_service.c @@ -61,7 +61,7 @@ void framebuffer_service(int fd, void *cookie) int w, h, f; int fds[2]; - if (pipe(fds) < 0) goto pipefail; + if (pipe2(fds, O_CLOEXEC) < 0) goto pipefail; pid_t pid = fork(); if (pid < 0) goto done;