-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SECURITY FIX: Fix package uids being reused between uninstall and rei…
…nstall of different packages. Policies for older packages were being granted to the newly installed package that got the recyled uid. Change-Id: I73d2beea8bd3497a9ea5c61a9e7a97ac9e599c82
- Loading branch information
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
Superuser/src/com/koushikdutta/superuser/PackageChangeReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.koushikdutta.superuser; | ||
|
||
import java.util.ArrayList; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.text.TextUtils; | ||
|
||
import com.koushikdutta.superuser.db.SuDatabaseHelper; | ||
import com.koushikdutta.superuser.db.UidPolicy; | ||
|
||
public class PackageChangeReceiver extends BroadcastReceiver { | ||
@Override | ||
public void onReceive(final Context context, Intent intent) { | ||
new Thread() { | ||
public void run() { | ||
ArrayList<UidPolicy> policies = SuDatabaseHelper.getPolicies(context); | ||
|
||
if (policies == null) | ||
return; | ||
|
||
final PackageManager pm = context.getPackageManager(); | ||
for (UidPolicy policy: policies) { | ||
// if the uid did not have a package name at creation time, | ||
// it may be a nameless or unresolveable uid... | ||
// ie, I can do something like: | ||
// su - 5050 | ||
// # 5050 has no name, so the following su will be an empty package name | ||
// su | ||
// | ||
// ignore this null package name as valid. | ||
if (TextUtils.isEmpty(policy.packageName)) | ||
continue; | ||
try { | ||
boolean found = false; | ||
String[] names = pm.getPackagesForUid(policy.uid); | ||
for (String name: names) { | ||
if (name.equals(policy.packageName)) | ||
found = true; | ||
} | ||
if (!found) | ||
throw new Exception("no package name match"); | ||
} | ||
catch (Exception e) { | ||
SuDatabaseHelper.delete(context, policy); | ||
} | ||
} | ||
}; | ||
}.start(); | ||
} | ||
} |
3dcccd3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3dcccd3