diff options
| author | 2022-01-06 14:23:05 +0000 | |
|---|---|---|
| committer | 2022-01-06 14:23:05 +0000 | |
| commit | a54a75b29dbf5bd35099f88bf5680bd59db685f0 (patch) | |
| tree | 0879b8f88488779a1992206fa1bd4a6eec8faad3 | |
| parent | 1c15308b455dd1f86ca653584f3097d22bcfaf6a (diff) | |
| parent | bbc431f3eaee29f83056f41ce5bd1ee936d89928 (diff) | |
Merge "Remove ParcelFileDescriptor hidden API usage from IpSecService" am: ff35093684 am: 04e2efc144 am: bbc431f3ea
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1931585
Change-Id: I7a6724284f29f05e7bbd9ee2a1ad671fd442e519
| -rw-r--r-- | packages/ConnectivityT/service/src/com/android/server/IpSecService.java | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/packages/ConnectivityT/service/src/com/android/server/IpSecService.java b/packages/ConnectivityT/service/src/com/android/server/IpSecService.java index d1e432e80f51..179d9459fd84 100644 --- a/packages/ConnectivityT/service/src/com/android/server/IpSecService.java +++ b/packages/ConnectivityT/service/src/com/android/server/IpSecService.java @@ -1236,37 +1236,53 @@ public class IpSecService extends IIpSecService.Stub { int callingUid = Binder.getCallingUid(); UserRecord userRecord = mUserResourceTracker.getUserRecord(callingUid); final int resourceId = mNextResourceId++; - FileDescriptor sockFd = null; + + ParcelFileDescriptor pFd = null; try { if (!userRecord.mSocketQuotaTracker.isAvailable()) { return new IpSecUdpEncapResponse(IpSecManager.Status.RESOURCE_UNAVAILABLE); } - sockFd = Os.socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - mUidFdTagger.tag(sockFd, callingUid); + FileDescriptor sockFd = null; + try { + sockFd = Os.socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + pFd = ParcelFileDescriptor.dup(sockFd); + } finally { + IoUtils.closeQuietly(sockFd); + } + mUidFdTagger.tag(pFd.getFileDescriptor(), callingUid); // This code is common to both the unspecified and specified port cases Os.setsockoptInt( - sockFd, + pFd.getFileDescriptor(), OsConstants.IPPROTO_UDP, OsConstants.UDP_ENCAP, OsConstants.UDP_ENCAP_ESPINUDP); - mNetd.ipSecSetEncapSocketOwner(new ParcelFileDescriptor(sockFd), callingUid); + mNetd.ipSecSetEncapSocketOwner(pFd, callingUid); if (port != 0) { Log.v(TAG, "Binding to port " + port); - Os.bind(sockFd, INADDR_ANY, port); + Os.bind(pFd.getFileDescriptor(), INADDR_ANY, port); } else { - port = bindToRandomPort(sockFd); + port = bindToRandomPort(pFd.getFileDescriptor()); } userRecord.mEncapSocketRecords.put( resourceId, new RefcountedResource<EncapSocketRecord>( - new EncapSocketRecord(resourceId, sockFd, port), binder)); - return new IpSecUdpEncapResponse(IpSecManager.Status.OK, resourceId, port, sockFd); + new EncapSocketRecord(resourceId, pFd.getFileDescriptor(), port), + binder)); + return new IpSecUdpEncapResponse(IpSecManager.Status.OK, resourceId, port, + pFd.getFileDescriptor()); } catch (IOException | ErrnoException e) { - IoUtils.closeQuietly(sockFd); + try { + if (pFd != null) { + pFd.close(); + } + } catch (IOException ex) { + // Nothing can be done at this point + Log.e(TAG, "Failed to close pFd."); + } } // If we make it to here, then something has gone wrong and we couldn't open a socket. // The only reasonable condition that would cause that is resource unavailable. |