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

Commit 6597fa6f authored by qqzhou's avatar qqzhou Committed by Linux Build Service Account
Browse files

base: fix native crash in system_server

Currently PackageManagerService uses multi-thread to scan
packages to speed up, when scan each package, it sometimes
will call SELinux's restorecon, then libselinux uses global
variable fc_sehandle to selabel_lookup and write in compile_regex,
so it's not thread-safe, so will cause invalid address with
possibility. From backtrace, the final crash happens in pcre_exec.

Add one lock in NativeLibraryHelper to make restorecon safe.

Change-Id: I2f00b4d66d968642f1726c28f4f6dc766c1cdad7
CRs-Fixed: 1002406, 1027381
parent 8da16915
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -62,6 +62,8 @@ public class NativeLibraryHelper {
    // that the cpuAbiOverride must be clear.
    public static final String CLEAR_ABI_OVERRIDE = "-";

    private static final Object mRestoreconSync = new Object();

    /**
     * A handle to an opened package, consisting of one or more APKs. Used as
     * input to the various NativeLibraryHelper methods. Allows us to scan and
@@ -275,10 +277,14 @@ public class NativeLibraryHelper {
                throw new IOException("Cannot chmod native library directory "
                        + path.getPath(), e);
            }
        } else if (!SELinux.restorecon(path)) {
        } else {
            synchronized (mRestoreconSync) {
                if (!SELinux.restorecon(path)) {
                    throw new IOException("Cannot set SELinux context for " + path.getPath());
                }
            }
        }
    }

    private static long sumNativeBinariesForSupportedAbi(Handle handle, String[] abiList) {
        int abi = findSupportedAbi(handle, abiList);