From b63a00a6831d5a15803cd422b68408c24135114c Mon Sep 17 00:00:00 2001 From: Chris Wailes Date: Wed, 10 Apr 2019 15:55:29 -0700 Subject: [PATCH] Fix FD leak in the Zygote. Issues with LocalSocketImpl.close meant that a FD that was supposed to be closed wasn't. This CL switches to using Os.close to ensure that the FD is closed properly. Bug: 130309968 Bug: 130235718 Test: atest android.security.cts.FileDescriptorTest#testCLOEXEC Test: Tested for file existance after Os.close call Change-Id: I80fb3b378f651e71bc1ae9aab8636935a2ff6356 Merged-In: I80fb3b378f651e71bc1ae9aab8636935a2ff6356 --- core/java/com/android/internal/os/Zygote.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/java/com/android/internal/os/Zygote.java b/core/java/com/android/internal/os/Zygote.java index afdeb1b602d76..a295bd21b20fb 100644 --- a/core/java/com/android/internal/os/Zygote.java +++ b/core/java/com/android/internal/os/Zygote.java @@ -566,7 +566,18 @@ public final class Zygote { System.exit(-1); } finally { IoUtils.closeQuietly(sessionSocket); - IoUtils.closeQuietly(usapPoolSocket); + + try { + // This socket is closed using Os.close due to an issue with the implementation of + // LocalSocketImp.close. Because the raw FD is created by init and then loaded from + // an environment variable (as opposed to being created by the LocalSocketImpl + // itself) the current implementation will not actually close the underlying FD. + // + // See b/130309968 for discussion of this issue. + Os.close(usapPoolSocket.getFileDescriptor()); + } catch (ErrnoException ex) { + Log.e("USAP", "Failed to close USAP pool socket: " + ex.getMessage()); + } } try {