Port of sdcardfs to 4.4
[firefly-linux-kernel-4.4.55.git] / fs / sdcardfs / packagelist.c
index c786d8f92203d648963ad34b110f9de29d3d7da6..d7ba8d4a423e1f8fafed819cadc0bf43ca18a0ec 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "sdcardfs.h"
 #include "strtok.h"
-#include "hashtable.h"
+#include <linux/hashtable.h>
 #include <linux/syscalls.h>
 #include <linux/kthread.h>
 #include <linux/inotify.h>
@@ -29,8 +29,8 @@
 #define STRING_BUF_SIZE                (512)
 
 struct hashtable_entry {
-        struct hlist_node hlist;
-        void *key;
+       struct hlist_node hlist;
+       void *key;
        int value;
 };
 
@@ -67,12 +67,12 @@ static unsigned int str_hash(void *key) {
 }
 
 static int contain_appid_key(struct packagelist_data *pkgl_dat, void *appid) {
-        struct hashtable_entry *hash_cur;
-       struct hlist_node *h_n;
+       struct hashtable_entry *hash_cur;
+
+       hash_for_each_possible(pkgl_dat->appid_with_rw, hash_cur, hlist, (unsigned int)appid)
 
-        hash_for_each_possible(pkgl_dat->appid_with_rw,        hash_cur, hlist, (unsigned int)appid, h_n)
-                if (appid == hash_cur->key)
-                        return 1;
+               if (appid == hash_cur->key)
+                       return 1;
        return 0;
 }
 
@@ -87,7 +87,7 @@ int get_caller_has_rw_locked(void *pkgl_id, derive_t derive) {
                return 1;
        }
 
-       appid = multiuser_get_app_id(current_fsuid());
+       appid = multiuser_get_app_id(from_kuid(&init_user_ns, current_fsuid()));
        mutex_lock(&pkgl_dat->hashtable_lock);
        ret = contain_appid_key(pkgl_dat, (void *)appid);
        mutex_unlock(&pkgl_dat->hashtable_lock);
@@ -98,13 +98,12 @@ appid_t get_appid(void *pkgl_id, const char *app_name)
 {
        struct packagelist_data *pkgl_dat = (struct packagelist_data *)pkgl_id;
        struct hashtable_entry *hash_cur;
-       struct hlist_node *h_n;
        unsigned int hash = str_hash((void *)app_name);
        appid_t ret_id;
 
        //printk(KERN_INFO "sdcardfs: %s: %s, %u\n", __func__, (char *)app_name, hash);
        mutex_lock(&pkgl_dat->hashtable_lock);
-       hash_for_each_possible(pkgl_dat->package_to_appid, hash_cur, hlist, hash, h_n) {
+       hash_for_each_possible(pkgl_dat->package_to_appid, hash_cur, hlist, hash) {
                //printk(KERN_INFO "sdcardfs: %s: %s\n", __func__, (char *)hash_cur->key);
                if (!strcasecmp(app_name, hash_cur->key)) {
                        ret_id = (appid_t)hash_cur->value;
@@ -140,7 +139,7 @@ int check_caller_access_to_name(struct inode *parent_node, const char* name,
 
        /* Root always has access; access for any other UIDs should always
         * be controlled through packages.list. */
-       if (current_fsuid() == 0) {
+       if (from_kuid(&init_user_ns, current_fsuid()) == 0) {
                return 1;
        }
 
@@ -148,7 +147,8 @@ int check_caller_access_to_name(struct inode *parent_node, const char* name,
         * parent or holds sdcard_rw. */
        if (w_ok) {
                if (parent_node &&
-                       (current_fsuid() == SDCARDFS_I(parent_node)->d_uid)) {
+                       (from_kuid(&init_user_ns, current_fsuid()) ==
+                        SDCARDFS_I(parent_node)->d_uid)) {
                        return 1;
                }
                return has_rw;
@@ -174,11 +174,10 @@ int open_flags_to_access_mode(int open_flags) {
 static int insert_str_to_int(struct packagelist_data *pkgl_dat, void *key, int value) {
        struct hashtable_entry *hash_cur;
        struct hashtable_entry *new_entry;
-       struct hlist_node *h_n;
        unsigned int hash = str_hash(key);
 
        //printk(KERN_INFO "sdcardfs: %s: %s: %d, %u\n", __func__, (char *)key, value, hash);
-       hash_for_each_possible(pkgl_dat->package_to_appid, hash_cur, hlist, hash, h_n) {
+       hash_for_each_possible(pkgl_dat->package_to_appid, hash_cur, hlist, hash) {
                if (!strcasecmp(key, hash_cur->key)) {
                        hash_cur->value = value;
                        return 0;
@@ -202,11 +201,10 @@ static void remove_str_to_int(struct hashtable_entry *h_entry) {
 static int insert_int_to_null(struct packagelist_data *pkgl_dat, void *key, int value) {
        struct hashtable_entry *hash_cur;
        struct hashtable_entry *new_entry;
-       struct hlist_node *h_n;
 
        //printk(KERN_INFO "sdcardfs: %s: %d: %d\n", __func__, (int)key, value);
        hash_for_each_possible(pkgl_dat->appid_with_rw, hash_cur, hlist,
-                                       (unsigned int)key, h_n) {
+                                       (unsigned int)key) {
                if (key == hash_cur->key) {
                        hash_cur->value = value;
                        return 0;
@@ -230,14 +228,13 @@ static void remove_int_to_null(struct hashtable_entry *h_entry) {
 static void remove_all_hashentrys(struct packagelist_data *pkgl_dat)
 {
        struct hashtable_entry *hash_cur;
-       struct hlist_node *h_n;
        struct hlist_node *h_t;
        int i;
 
-       hash_for_each_safe(pkgl_dat->package_to_appid, i, h_t, hash_cur, hlist, h_n)
+       hash_for_each_safe(pkgl_dat->package_to_appid, i, h_t, hash_cur, hlist)
                remove_str_to_int(hash_cur);
-       hash_for_each_safe(pkgl_dat->appid_with_rw, i, h_t, hash_cur, hlist, h_n)
-                remove_int_to_null(hash_cur);
+       hash_for_each_safe(pkgl_dat->appid_with_rw, i, h_t, hash_cur, hlist)
+               remove_int_to_null(hash_cur);
 
        hash_init(pkgl_dat->package_to_appid);
        hash_init(pkgl_dat->appid_with_rw);