uid_cputime: Check for the range while removing range of UIDs.
authorRuchi Kandoi <kandoiruchi@google.com>
Sat, 24 Oct 2015 00:49:11 +0000 (17:49 -0700)
committerDanny Wood <danwood76@gmail.com>
Sun, 31 Mar 2019 08:48:09 +0000 (09:48 +0100)
Checking if the uid_entry->uid matches the uid intended to be removed will
prevent deleting unwanted uid_entry.
Type cast the key for the hashtable to the same size, as when they were
inserted. This will make sure that we can find the uid_entry we want.

Bug: 25195548
Change-Id: I567942123cfb20e4b61ad624da19ec4cc84642c1
Signed-off: Ruchi kandoi <kandoiruchi@google.com>

drivers/misc/uid_cputime.c

index a8bd0916f54a2fc2e4fe0001ad270084ba7c8e14..0068c2066cc5fd40777b0dc2ec2ed190cd3b6278 100644 (file)
@@ -170,14 +170,15 @@ static ssize_t uid_remove_write(struct file *file,
                kstrtol(end_uid, 10, &uid_end) != 0) {
                return -EINVAL;
        }
-
        mutex_lock(&uid_lock);
 
        for (; uid_start <= uid_end; uid_start++) {
                hash_for_each_possible_safe(hash_table, uid_entry, tmp,
-                                                       hash, uid_start) {
-                       hash_del(&uid_entry->hash);
-                       kfree(uid_entry);
+                                                       hash, (uid_t)uid_start) {
+                       if (uid_start == uid_entry->uid) {
+                               hash_del(&uid_entry->hash);
+                               kfree(uid_entry);
+                       }
                }
        }