diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java index 6feb860367912..914945b2f64a9 100644 --- a/core/java/android/content/pm/ApplicationInfo.java +++ b/core/java/android/content/pm/ApplicationInfo.java @@ -531,12 +531,14 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { /** * String retrieved from the seinfo tag found in selinux policy. This value - * is useful in setting an SELinux security context on the process as well - * as its data directory. + * can be overridden with a value set through the mac_permissions.xml policy + * construct. This value is useful in setting an SELinux security context on + * the process as well as its data directory. The String default is being used + * here to represent a catchall label when no policy matches. * * {@hide} */ - public String seinfo; + public String seinfo = "default"; /** * Paths to all shared libraries this application is linked against. This diff --git a/services/core/java/com/android/server/pm/SELinuxMMAC.java b/services/core/java/com/android/server/pm/SELinuxMMAC.java index c75a1d306a872..66170d453260c 100644 --- a/services/core/java/com/android/server/pm/SELinuxMMAC.java +++ b/services/core/java/com/android/server/pm/SELinuxMMAC.java @@ -136,9 +136,6 @@ public final class SELinuxMMAC { case "signer": policies.add(readSignerOrThrow(parser)); break; - case "default": - policies.add(readDefaultOrThrow(parser)); - break; default: skip(parser); } @@ -232,45 +229,6 @@ public final class SELinuxMMAC { return pb.build(); } - /** - * Loop over a default element looking for seinfo child tags. A {@link Policy} - * instance will be created and returned in the process. All other tags encountered - * will be skipped. - * - * @param parser an XmlPullParser object representing a default element. - * @return the constructed {@link Policy} instance - * @throws IOException - * @throws XmlPullParserException - * @throws IllegalArgumentException if any of the validation checks fail while - * parsing tag values. - * @throws IllegalStateException if any of the invariants fail when constructing - * the {@link Policy} instance. - */ - private static Policy readDefaultOrThrow(XmlPullParser parser) throws IOException, - XmlPullParserException { - - parser.require(XmlPullParser.START_TAG, null, "default"); - Policy.PolicyBuilder pb = new Policy.PolicyBuilder(); - pb.setAsDefaultPolicy(); - - while (parser.next() != XmlPullParser.END_TAG) { - if (parser.getEventType() != XmlPullParser.START_TAG) { - continue; - } - - String tagName = parser.getName(); - if ("seinfo".equals(tagName)) { - String seinfo = parser.getAttributeValue(null, "value"); - pb.setGlobalSeinfoOrThrow(seinfo); - readSeinfo(parser); - } else { - skip(parser); - } - } - - return pb.build(); - } - /** * Loop over a package element looking for seinfo child tags. If found return the * value attribute of the seinfo tag, otherwise return null. All other tags encountered @@ -337,35 +295,28 @@ public final class SELinuxMMAC { /** * Applies a security label to a package based on an seinfo tag taken from a matched - * policy. All signature based policy stanzas are consulted first and, if no match - * is found, the default policy stanza is then consulted. The security label is - * attached to the ApplicationInfo instance of the package in the event that a matching - * policy was found. + * policy. All signature based policy stanzas are consulted and, if no match is + * found, the default seinfo label of 'default' (set in ApplicationInfo object) is + * used. The security label is attached to the ApplicationInfo instance of the package + * in the event that a matching policy was found. * * @param pkg object representing the package to be labeled. - * @return boolean which determines whether a non null seinfo label was assigned - * to the package. A null value simply represents that no policy matched. */ - public static boolean assignSeinfoValue(PackageParser.Package pkg) { + public static void assignSeinfoValue(PackageParser.Package pkg) { synchronized (sPolicies) { for (Policy policy : sPolicies) { String seinfo = policy.getMatchedSeinfo(pkg); if (seinfo != null) { pkg.applicationInfo.seinfo = seinfo; - if (DEBUG_POLICY_INSTALL) { - Slog.i(TAG, "package (" + pkg.packageName + ") labeled with " + - "seinfo=" + seinfo); - } - return true; + break; } } } if (DEBUG_POLICY_INSTALL) { - Slog.i(TAG, "package (" + pkg.packageName + ") doesn't match any policy; " + - "seinfo will remain null"); + Slog.i(TAG, "package (" + pkg.packageName + ") labeled with " + + "seinfo=" + pkg.applicationInfo.seinfo); } - return false; } /** @@ -506,30 +457,16 @@ public final class SELinuxMMAC { * .build(); * } * - *
- * The following is an example of how to use {@link Policy.PolicyBuilder} to create a - * default based Policy instance. - *
- *
- * {@code
- * Policy policy = new Policy.PolicyBuilder()
- * .setAsDefaultPolicy()
- * .setGlobalSeinfoOrThrow("default")
- * .build();
- * }
- *
*/
final class Policy {
private final String mSeinfo;
- private final boolean mDefaultStanza;
private final Set
@@ -636,37 +553,34 @@ final class Policy {
* A value of null can also be returned if no match occured.
*/
public String getMatchedSeinfo(PackageParser.Package pkg) {
- if (!mDefaultStanza) {
- // Check for exact signature matches across all certs.
- Signature[] certs = mCerts.toArray(new Signature[0]);
- if (!Signature.areExactMatch(certs, pkg.mSignatures)) {
- return null;
- }
-
- // Check for inner package name matches given that the
- // signature checks already passed.
- String seinfoValue = mPkgMap.get(pkg.packageName);
- if (seinfoValue != null) {
- return seinfoValue;
- }
+ // Check for exact signature matches across all certs.
+ Signature[] certs = mCerts.toArray(new Signature[0]);
+ if (!Signature.areExactMatch(certs, pkg.mSignatures)) {
+ return null;
}
- // Return the global seinfo value (even if it's null).
+ // Check for inner package name matches given that the
+ // signature checks already passed.
+ String seinfoValue = mPkgMap.get(pkg.packageName);
+ if (seinfoValue != null) {
+ return seinfoValue;
+ }
+
+ // Return the global seinfo value.
return mSeinfo;
}
/**
* A nested builder class to create {@link Policy} instances. A {@link Policy}
* class instance represents one valid policy stanza found in a mac_permissions.xml
- * file. A valid policy stanza is defined to be either a signer or default stanza
- * which obeys the rules outlined in external/sepolicy/mac_permissions.xml. The
- * {@link #build} method ensures a set of invariants are upheld enforcing the correct
- * stanza structure before returning a valid Policy object.
+ * file. A valid policy stanza is defined to be a signer stanza which obeys the rules
+ * outlined in external/sepolicy/mac_permissions.xml. The {@link #build} method
+ * ensures a set of invariants are upheld enforcing the correct stanza structure
+ * before returning a valid Policy object.
*/
public static final class PolicyBuilder {
private String mSeinfo;
- private boolean mDefaultStanza;
private final Set