Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2d5b4c9d authored by Hyeeun Jun's avatar Hyeeun Jun Committed by Martijn Coenen
Browse files

Fix AppFuse deadlock.

If there are more than two applications having different UID using
openProxyFileDescriptor (AppFuse), it can cause a deadlock between
AppFuseBridge (system_server) and vold process.

We separate calling umount to a background thread from AppFuseBridge.

Bug: 300351508
Test: atest AppFusePerfTest
Change-Id: Id8b51a847a46e3deaaf26473a9601cf28004e5b8
parent 67890dbe
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -3623,7 +3623,26 @@ class StorageManagerService extends IStorageManager.Stub
        @Override
        public void close() throws Exception {
            if (mMounted) {
                BackgroundThread.getHandler().post(() -> {
                    try {
                        // We need to run the unmount on a separate thread to
                        // prevent a possible deadlock, where:
                        // 1. AppFuseThread (this thread) tries to call into vold
                        // 2. the vold lock is held by another thread, which called:
                        //    mVold.openAppFuseFile()
                        //    as part of that call, vold calls open() on the
                        //    underlying file, which is a call that needs to be
                        //    handled by the AppFuseThread, which is stuck waiting
                        //    for the vold lock (see 1.)
                        // It is safe to do the unmount asynchronously, because the mount
                        // path we use is never reused during the current boot cycle;
                        // see mNextAppFuseName. Also,we have anyway stopped serving
                        // requests at this point.
                        mVold.unmountAppFuse(uid, mountId);
                    } catch (RemoteException e) {
                        throw e.rethrowAsRuntimeException();
                    }
                });
                mMounted = false;
            }
        }