Skip to content

Commit f9eb06c

Browse files
committed
frameworks/base: Cap the number of toasts that a package can post.
NotificationManagerService keeps track of requested toasts in a queue. Any package can trigger a DoS by repeated enqueue of toasts which eventually results in a leak of WeakReferences in system_server and causes dalvik (hosting system_server) to abort the same. Change-Id: I5e23c1bf7e195b07344711d2c6719fa568f2dfaf
1 parent f247e54 commit f9eb06c

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

services/java/com/android/server/NotificationManagerService.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,24 @@ public void enqueueToast(String pkg, ITransientNotification callback, int durati
519519
record = mToastQueue.get(index);
520520
record.update(duration);
521521
} else {
522+
// Limit the number of toasts that any given package except the android
523+
// package can enqueue. Prevents DOS attacks and deals with leaks.
524+
if (!"android".equals(pkg)) {
525+
int count = 0;
526+
final int N = mToastQueue.size();
527+
for (int i=0; i<N; i++) {
528+
final ToastRecord r = mToastQueue.get(i);
529+
if (r.pkg.equals(pkg)) {
530+
count++;
531+
if (count >= MAX_PACKAGE_NOTIFICATIONS) {
532+
Slog.e(TAG, "Package has already posted " + count
533+
+ " toasts. Not showing more. Package=" + pkg);
534+
return;
535+
}
536+
}
537+
}
538+
}
539+
522540
record = new ToastRecord(callingPid, pkg, callback, duration);
523541
mToastQueue.add(record);
524542
index = mToastQueue.size() - 1;

0 commit comments

Comments
 (0)