From 87fd250c5fa2aad3738f6b03fa7e16d274abb506 Mon Sep 17 00:00:00 2001 From: mqi Date: Mon, 1 Jun 2015 14:59:31 +0800 Subject: Improve the scan process Use multi task to speed up the scan process CRs-Fixed: 984513 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: Ida43fcda01d3450befea6afa0be5da27bb195def CRs-Fixed: 1002406, 1027381 --- .../java/com/android/internal/content/NativeLibraryHelper.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/java/com/android/internal/content/NativeLibraryHelper.java b/core/java/com/android/internal/content/NativeLibraryHelper.java index f479f4f..f5b948f 100644 --- a/core/java/com/android/internal/content/NativeLibraryHelper.java +++ b/core/java/com/android/internal/content/NativeLibraryHelper.java @@ -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,8 +277,12 @@ public class NativeLibraryHelper { throw new IOException("Cannot chmod native library directory " + path.getPath(), e); } - } else if (!SELinux.restorecon(path)) { - throw new IOException("Cannot set SELinux context for " + path.getPath()); + } else { + synchronized (mRestoreconSync) { + if (!SELinux.restorecon(path)) { + throw new IOException("Cannot set SELinux context for " + path.getPath()); + } + } } } -- cgit v1.1