^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * fs/sdcardfs/packagelist.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2013 Samsung Electronics Co. Ltd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Authors: Daeho Jeong, Woojoong Lee, Seunghwan Hyun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Sunghwan Yun, Sungjong Seo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * This program has been developed as a stackable file system based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * the WrapFS which written by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Copyright (c) 1998-2011 Erez Zadok
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Copyright (c) 2009 Shrikar Archak
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Copyright (c) 2003-2011 Stony Brook University
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Copyright (c) 2003-2011 The Research Foundation of SUNY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * This file is dual licensed. It may be redistributed and/or modified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * under the terms of the Apache 2.0 License OR version 2 of the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * General Public License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "sdcardfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/hashtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/radix-tree.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/dcache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/configfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct hashtable_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct hlist_node hlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct hlist_node dlist; /* for deletion cleanup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct qstr key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) atomic_t value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static DEFINE_HASHTABLE(package_to_appid, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static DEFINE_HASHTABLE(package_to_userid, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static DEFINE_HASHTABLE(ext_to_groupid, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static struct kmem_cache *hashtable_entry_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static unsigned int full_name_case_hash(const void *salt, const unsigned char *name, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) unsigned long hash = init_name_hash(salt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) while (len--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) hash = partial_name_hash(tolower(*name++), hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return end_name_hash(hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static inline void qstr_init(struct qstr *q, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) q->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) q->len = strlen(q->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) q->hash = full_name_case_hash(0, q->name, q->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static inline int qstr_copy(const struct qstr *src, struct qstr *dest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) dest->name = kstrdup(src->name, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) dest->hash_len = src->hash_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return !!dest->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static appid_t __get_appid(const struct qstr *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct hashtable_entry *hash_cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) unsigned int hash = key->hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) appid_t ret_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) hash_for_each_possible_rcu(package_to_appid, hash_cur, hlist, hash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (qstr_case_eq(key, &hash_cur->key)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) ret_id = atomic_read(&hash_cur->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return ret_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) appid_t get_appid(const char *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct qstr q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) qstr_init(&q, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return __get_appid(&q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static appid_t __get_ext_gid(const struct qstr *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct hashtable_entry *hash_cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) unsigned int hash = key->hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) appid_t ret_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) hash_for_each_possible_rcu(ext_to_groupid, hash_cur, hlist, hash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (qstr_case_eq(key, &hash_cur->key)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) ret_id = atomic_read(&hash_cur->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return ret_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) appid_t get_ext_gid(const char *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct qstr q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) qstr_init(&q, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return __get_ext_gid(&q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static appid_t __is_excluded(const struct qstr *app_name, userid_t user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct hashtable_entry *hash_cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) unsigned int hash = app_name->hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) hash_for_each_possible_rcu(package_to_userid, hash_cur, hlist, hash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (atomic_read(&hash_cur->value) == user &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) qstr_case_eq(app_name, &hash_cur->key)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) appid_t is_excluded(const char *key, userid_t user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct qstr q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) qstr_init(&q, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return __is_excluded(&q, user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /* Kernel has already enforced everything we returned through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * derive_permissions_locked(), so this is used to lock down access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * even further, such as enforcing that apps hold sdcard_rw.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) int check_caller_access_to_name(struct inode *parent_node, const struct qstr *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct qstr q_autorun = QSTR_LITERAL("autorun.inf");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct qstr q__android_secure = QSTR_LITERAL(".android_secure");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct qstr q_android_secure = QSTR_LITERAL("android_secure");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* Always block security-sensitive files at root */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (parent_node && SDCARDFS_I(parent_node)->data->perm == PERM_ROOT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (qstr_case_eq(name, &q_autorun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) || qstr_case_eq(name, &q__android_secure)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) || qstr_case_eq(name, &q_android_secure)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /* Root always has access; access for any other UIDs should always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * be controlled through packages.list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (from_kuid(&init_user_ns, current_fsuid()) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* No extra permissions to enforce */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static struct hashtable_entry *alloc_hashtable_entry(const struct qstr *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) appid_t value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct hashtable_entry *ret = kmem_cache_alloc(hashtable_entry_cachep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) INIT_HLIST_NODE(&ret->dlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) INIT_HLIST_NODE(&ret->hlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (!qstr_copy(key, &ret->key)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) kmem_cache_free(hashtable_entry_cachep, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) atomic_set(&ret->value, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static int insert_packagelist_appid_entry_locked(const struct qstr *key, appid_t value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct hashtable_entry *hash_cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct hashtable_entry *new_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) unsigned int hash = key->hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) hash_for_each_possible_rcu(package_to_appid, hash_cur, hlist, hash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (qstr_case_eq(key, &hash_cur->key)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) atomic_set(&hash_cur->value, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) new_entry = alloc_hashtable_entry(key, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (!new_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) hash_add_rcu(package_to_appid, &new_entry->hlist, hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static int insert_ext_gid_entry_locked(const struct qstr *key, appid_t value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct hashtable_entry *hash_cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct hashtable_entry *new_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) unsigned int hash = key->hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /* An extension can only belong to one gid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) hash_for_each_possible_rcu(ext_to_groupid, hash_cur, hlist, hash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (qstr_case_eq(key, &hash_cur->key))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) new_entry = alloc_hashtable_entry(key, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (!new_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) hash_add_rcu(ext_to_groupid, &new_entry->hlist, hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static int insert_userid_exclude_entry_locked(const struct qstr *key, userid_t value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct hashtable_entry *hash_cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct hashtable_entry *new_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) unsigned int hash = key->hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /* Only insert if not already present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) hash_for_each_possible_rcu(package_to_userid, hash_cur, hlist, hash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (atomic_read(&hash_cur->value) == value &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) qstr_case_eq(key, &hash_cur->key))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) new_entry = alloc_hashtable_entry(key, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (!new_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) hash_add_rcu(package_to_userid, &new_entry->hlist, hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static void fixup_all_perms_name(const struct qstr *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct sdcardfs_sb_info *sbinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct limit_search limit = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) .flags = BY_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) .name = QSTR_INIT(key->name, key->len),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) list_for_each_entry(sbinfo, &sdcardfs_super_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (sbinfo_has_sdcard_magic(sbinfo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) fixup_perms_recursive(sbinfo->sb->s_root, &limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static void fixup_all_perms_name_userid(const struct qstr *key, userid_t userid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) struct sdcardfs_sb_info *sbinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct limit_search limit = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) .flags = BY_NAME | BY_USERID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) .name = QSTR_INIT(key->name, key->len),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) .userid = userid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) list_for_each_entry(sbinfo, &sdcardfs_super_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (sbinfo_has_sdcard_magic(sbinfo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) fixup_perms_recursive(sbinfo->sb->s_root, &limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static void fixup_all_perms_userid(userid_t userid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct sdcardfs_sb_info *sbinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct limit_search limit = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) .flags = BY_USERID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) .userid = userid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) list_for_each_entry(sbinfo, &sdcardfs_super_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (sbinfo_has_sdcard_magic(sbinfo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) fixup_perms_recursive(sbinfo->sb->s_root, &limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static int insert_packagelist_entry(const struct qstr *key, appid_t value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) mutex_lock(&sdcardfs_super_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) err = insert_packagelist_appid_entry_locked(key, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) fixup_all_perms_name(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) mutex_unlock(&sdcardfs_super_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static int insert_ext_gid_entry(const struct qstr *key, appid_t value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) mutex_lock(&sdcardfs_super_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) err = insert_ext_gid_entry_locked(key, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) mutex_unlock(&sdcardfs_super_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static int insert_userid_exclude_entry(const struct qstr *key, userid_t value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) mutex_lock(&sdcardfs_super_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) err = insert_userid_exclude_entry_locked(key, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) fixup_all_perms_name_userid(key, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) mutex_unlock(&sdcardfs_super_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static void free_hashtable_entry(struct hashtable_entry *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) kfree(entry->key.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) kmem_cache_free(hashtable_entry_cachep, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) static void remove_packagelist_entry_locked(const struct qstr *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct hashtable_entry *hash_cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) unsigned int hash = key->hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) struct hlist_node *h_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) HLIST_HEAD(free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) hash_for_each_possible_rcu(package_to_userid, hash_cur, hlist, hash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (qstr_case_eq(key, &hash_cur->key)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) hash_del_rcu(&hash_cur->hlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) hlist_add_head(&hash_cur->dlist, &free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) hash_for_each_possible_rcu(package_to_appid, hash_cur, hlist, hash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if (qstr_case_eq(key, &hash_cur->key)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) hash_del_rcu(&hash_cur->hlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) hlist_add_head(&hash_cur->dlist, &free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) hlist_for_each_entry_safe(hash_cur, h_t, &free_list, dlist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) free_hashtable_entry(hash_cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static void remove_packagelist_entry(const struct qstr *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) mutex_lock(&sdcardfs_super_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) remove_packagelist_entry_locked(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) fixup_all_perms_name(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) mutex_unlock(&sdcardfs_super_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static void remove_ext_gid_entry_locked(const struct qstr *key, gid_t group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) struct hashtable_entry *hash_cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) unsigned int hash = key->hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) hash_for_each_possible_rcu(ext_to_groupid, hash_cur, hlist, hash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (qstr_case_eq(key, &hash_cur->key) && atomic_read(&hash_cur->value) == group) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) hash_del_rcu(&hash_cur->hlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) free_hashtable_entry(hash_cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static void remove_ext_gid_entry(const struct qstr *key, gid_t group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) mutex_lock(&sdcardfs_super_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) remove_ext_gid_entry_locked(key, group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) mutex_unlock(&sdcardfs_super_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) static void remove_userid_all_entry_locked(userid_t userid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) struct hashtable_entry *hash_cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) struct hlist_node *h_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) HLIST_HEAD(free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) hash_for_each_rcu(package_to_userid, i, hash_cur, hlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if (atomic_read(&hash_cur->value) == userid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) hash_del_rcu(&hash_cur->hlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) hlist_add_head(&hash_cur->dlist, &free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) hlist_for_each_entry_safe(hash_cur, h_t, &free_list, dlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) free_hashtable_entry(hash_cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static void remove_userid_all_entry(userid_t userid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) mutex_lock(&sdcardfs_super_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) remove_userid_all_entry_locked(userid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) fixup_all_perms_userid(userid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) mutex_unlock(&sdcardfs_super_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) static void remove_userid_exclude_entry_locked(const struct qstr *key, userid_t userid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) struct hashtable_entry *hash_cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) unsigned int hash = key->hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) hash_for_each_possible_rcu(package_to_userid, hash_cur, hlist, hash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (qstr_case_eq(key, &hash_cur->key) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) atomic_read(&hash_cur->value) == userid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) hash_del_rcu(&hash_cur->hlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) free_hashtable_entry(hash_cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static void remove_userid_exclude_entry(const struct qstr *key, userid_t userid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) mutex_lock(&sdcardfs_super_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) remove_userid_exclude_entry_locked(key, userid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) fixup_all_perms_name_userid(key, userid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) mutex_unlock(&sdcardfs_super_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static void packagelist_destroy(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) struct hashtable_entry *hash_cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) struct hlist_node *h_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) HLIST_HEAD(free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) mutex_lock(&sdcardfs_super_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) hash_for_each_rcu(package_to_appid, i, hash_cur, hlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) hash_del_rcu(&hash_cur->hlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) hlist_add_head(&hash_cur->dlist, &free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) hash_for_each_rcu(package_to_userid, i, hash_cur, hlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) hash_del_rcu(&hash_cur->hlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) hlist_add_head(&hash_cur->dlist, &free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) hlist_for_each_entry_safe(hash_cur, h_t, &free_list, dlist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) free_hashtable_entry(hash_cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) mutex_unlock(&sdcardfs_super_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) pr_info("sdcardfs: destroyed packagelist pkgld\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) #define SDCARDFS_CONFIGFS_ATTR(_pfx, _name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) static struct configfs_attribute _pfx##attr_##_name = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) .ca_name = __stringify(_name), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) .ca_mode = S_IRUGO | S_IWUGO, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) .ca_owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) .show = _pfx##_name##_show, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) .store = _pfx##_name##_store, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) #define SDCARDFS_CONFIGFS_ATTR_RO(_pfx, _name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static struct configfs_attribute _pfx##attr_##_name = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) .ca_name = __stringify(_name), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) .ca_mode = S_IRUGO, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) .ca_owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) .show = _pfx##_name##_show, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) #define SDCARDFS_CONFIGFS_ATTR_WO(_pfx, _name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) static struct configfs_attribute _pfx##attr_##_name = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) .ca_name = __stringify(_name), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) .ca_mode = S_IWUGO, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) .ca_owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) .store = _pfx##_name##_store, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) struct package_details {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) struct config_item item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) struct qstr name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static inline struct package_details *to_package_details(struct config_item *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) return item ? container_of(item, struct package_details, item) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static ssize_t package_details_appid_show(struct config_item *item, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) return scnprintf(page, PAGE_SIZE, "%u\n", __get_appid(&to_package_details(item)->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static ssize_t package_details_appid_store(struct config_item *item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) const char *page, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) unsigned int tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) ret = kstrtouint(page, 10, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) ret = insert_packagelist_entry(&to_package_details(item)->name, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) static ssize_t package_details_excluded_userids_show(struct config_item *item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) struct package_details *package_details = to_package_details(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) struct hashtable_entry *hash_cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) unsigned int hash = package_details->name.hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) hash_for_each_possible_rcu(package_to_userid, hash_cur, hlist, hash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (qstr_case_eq(&package_details->name, &hash_cur->key))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) count += scnprintf(page + count, PAGE_SIZE - count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) "%d ", atomic_read(&hash_cur->value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) count += scnprintf(page + count, PAGE_SIZE - count, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) static ssize_t package_details_excluded_userids_store(struct config_item *item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) const char *page, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) unsigned int tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) ret = kstrtouint(page, 10, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) ret = insert_userid_exclude_entry(&to_package_details(item)->name, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) static ssize_t package_details_clear_userid_store(struct config_item *item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) const char *page, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) unsigned int tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) ret = kstrtouint(page, 10, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) remove_userid_exclude_entry(&to_package_details(item)->name, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) static void package_details_release(struct config_item *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) struct package_details *package_details = to_package_details(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) pr_info("sdcardfs: removing %s\n", package_details->name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) remove_packagelist_entry(&package_details->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) kfree(package_details->name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) kfree(package_details);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) SDCARDFS_CONFIGFS_ATTR(package_details_, appid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) SDCARDFS_CONFIGFS_ATTR(package_details_, excluded_userids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) SDCARDFS_CONFIGFS_ATTR_WO(package_details_, clear_userid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) static struct configfs_attribute *package_details_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) &package_details_attr_appid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) &package_details_attr_excluded_userids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) &package_details_attr_clear_userid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) static struct configfs_item_operations package_details_item_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) .release = package_details_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) static struct config_item_type package_appid_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) .ct_item_ops = &package_details_item_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) .ct_attrs = package_details_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) .ct_owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) struct extensions_value {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct config_group group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) unsigned int num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) struct extension_details {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) struct config_item item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) struct qstr name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) unsigned int num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) static inline struct extensions_value *to_extensions_value(struct config_item *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) return item ? container_of(to_config_group(item), struct extensions_value, group) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) static inline struct extension_details *to_extension_details(struct config_item *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) return item ? container_of(item, struct extension_details, item) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) static void extension_details_release(struct config_item *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) struct extension_details *extension_details = to_extension_details(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) pr_info("sdcardfs: No longer mapping %s files to gid %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) extension_details->name.name, extension_details->num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) remove_ext_gid_entry(&extension_details->name, extension_details->num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) kfree(extension_details->name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) kfree(extension_details);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) static struct configfs_item_operations extension_details_item_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) .release = extension_details_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) static struct config_item_type extension_details_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) .ct_item_ops = &extension_details_item_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) .ct_owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) static struct config_item *extension_details_make_item(struct config_group *group, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) struct extensions_value *extensions_value = to_extensions_value(&group->cg_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) struct extension_details *extension_details = kzalloc(sizeof(struct extension_details), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) const char *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) if (!extension_details)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) tmp = kstrdup(name, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) if (!tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) kfree(extension_details);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) qstr_init(&extension_details->name, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) extension_details->num = extensions_value->num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) ret = insert_ext_gid_entry(&extension_details->name, extensions_value->num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) kfree(extension_details->name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) kfree(extension_details);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) config_item_init_type_name(&extension_details->item, name, &extension_details_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) return &extension_details->item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) static struct configfs_group_operations extensions_value_group_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) .make_item = extension_details_make_item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) static struct config_item_type extensions_name_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) .ct_group_ops = &extensions_value_group_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) .ct_owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) static struct config_group *extensions_make_group(struct config_group *group, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) struct extensions_value *extensions_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) unsigned int tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) extensions_value = kzalloc(sizeof(struct extensions_value), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) if (!extensions_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) ret = kstrtouint(name, 10, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) kfree(extensions_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) extensions_value->num = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) config_group_init_type_name(&extensions_value->group, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) &extensions_name_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) return &extensions_value->group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) static void extensions_drop_group(struct config_group *group, struct config_item *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) struct extensions_value *value = to_extensions_value(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) pr_info("sdcardfs: No longer mapping any files to gid %d\n", value->num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) kfree(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) static struct configfs_group_operations extensions_group_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) .make_group = extensions_make_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) .drop_item = extensions_drop_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) static struct config_item_type extensions_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) .ct_group_ops = &extensions_group_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) .ct_owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) struct config_group extension_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) .cg_item = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) .ci_namebuf = "extensions",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) .ci_type = &extensions_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) static struct config_item *packages_make_item(struct config_group *group, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) struct package_details *package_details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) const char *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) package_details = kzalloc(sizeof(struct package_details), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if (!package_details)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) tmp = kstrdup(name, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) if (!tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) kfree(package_details);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) qstr_init(&package_details->name, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) config_item_init_type_name(&package_details->item, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) &package_appid_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) return &package_details->item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) static ssize_t packages_list_show(struct config_item *item, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) struct hashtable_entry *hash_cur_app;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) struct hashtable_entry *hash_cur_user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) int count = 0, written = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) const char errormsg[] = "<truncated>\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) unsigned int hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) hash_for_each_rcu(package_to_appid, i, hash_cur_app, hlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) written = scnprintf(page + count, PAGE_SIZE - sizeof(errormsg) - count, "%s %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) hash_cur_app->key.name, atomic_read(&hash_cur_app->value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) hash = hash_cur_app->key.hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) hash_for_each_possible_rcu(package_to_userid, hash_cur_user, hlist, hash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) if (qstr_case_eq(&hash_cur_app->key, &hash_cur_user->key)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) written += scnprintf(page + count + written - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) PAGE_SIZE - sizeof(errormsg) - count - written + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) " %d\n", atomic_read(&hash_cur_user->value)) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) if (count + written == PAGE_SIZE - sizeof(errormsg) - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) count += scnprintf(page + count, PAGE_SIZE - count, errormsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) count += written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) static ssize_t packages_remove_userid_store(struct config_item *item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) const char *page, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) unsigned int tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) ret = kstrtouint(page, 10, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) remove_userid_all_entry(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) static struct configfs_attribute packages_attr_packages_gid_list = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) .ca_name = "packages_gid.list",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) .ca_mode = S_IRUGO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) .ca_owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) .show = packages_list_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) SDCARDFS_CONFIGFS_ATTR_WO(packages_, remove_userid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) static struct configfs_attribute *packages_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) &packages_attr_packages_gid_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) &packages_attr_remove_userid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) * Note that, since no extra work is required on ->drop_item(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) * no ->drop_item() is provided.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) static struct configfs_group_operations packages_group_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) .make_item = packages_make_item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) static struct config_item_type packages_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) .ct_group_ops = &packages_group_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) .ct_attrs = packages_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) .ct_owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) struct config_group *sd_default_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) &extension_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) static struct configfs_subsystem sdcardfs_packages = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) .su_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) .cg_item = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) .ci_namebuf = "sdcardfs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) .ci_type = &packages_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) static int configfs_sdcardfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) struct configfs_subsystem *subsys = &sdcardfs_packages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) config_group_init(&subsys->su_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) for (i = 0; sd_default_groups[i]; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) config_group_init(sd_default_groups[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) configfs_add_default_group(sd_default_groups[i], &subsys->su_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) mutex_init(&subsys->su_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) ret = configfs_register_subsystem(subsys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) pr_err("Error %d while registering subsystem %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) subsys->su_group.cg_item.ci_namebuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) static void configfs_sdcardfs_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) configfs_unregister_subsystem(&sdcardfs_packages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) int packagelist_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) hashtable_entry_cachep =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) kmem_cache_create("packagelist_hashtable_entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) sizeof(struct hashtable_entry), 0, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) if (!hashtable_entry_cachep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) pr_err("sdcardfs: failed creating pkgl_hashtable entry slab cache\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) configfs_sdcardfs_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) void packagelist_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) configfs_sdcardfs_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) packagelist_destroy();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) kmem_cache_destroy(hashtable_entry_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) }