| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * The "user cache". |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 17 | 18 | #include <linux/interrupt.h> |
|---|
| 18 | 19 | #include <linux/export.h> |
|---|
| 19 | 20 | #include <linux/user_namespace.h> |
|---|
| 20 | | -#include <linux/proc_fs.h> |
|---|
| 21 | 21 | #include <linux/proc_ns.h> |
|---|
| 22 | 22 | |
|---|
| 23 | 23 | /* |
|---|
| .. | .. |
|---|
| 63 | 63 | .ns.ops = &userns_operations, |
|---|
| 64 | 64 | #endif |
|---|
| 65 | 65 | .flags = USERNS_INIT_FLAGS, |
|---|
| 66 | | -#ifdef CONFIG_PERSISTENT_KEYRINGS |
|---|
| 67 | | - .persistent_keyring_register_sem = |
|---|
| 68 | | - __RWSEM_INITIALIZER(init_user_ns.persistent_keyring_register_sem), |
|---|
| 66 | +#ifdef CONFIG_KEYS |
|---|
| 67 | + .keyring_name_list = LIST_HEAD_INIT(init_user_ns.keyring_name_list), |
|---|
| 68 | + .keyring_sem = __RWSEM_INITIALIZER(init_user_ns.keyring_sem), |
|---|
| 69 | 69 | #endif |
|---|
| 70 | 70 | }; |
|---|
| 71 | 71 | EXPORT_SYMBOL_GPL(init_user_ns); |
|---|
| .. | .. |
|---|
| 82 | 82 | #define uidhashentry(uid) (uidhash_table + __uidhashfn((__kuid_val(uid)))) |
|---|
| 83 | 83 | |
|---|
| 84 | 84 | static struct kmem_cache *uid_cachep; |
|---|
| 85 | | -struct hlist_head uidhash_table[UIDHASH_SZ]; |
|---|
| 85 | +static struct hlist_head uidhash_table[UIDHASH_SZ]; |
|---|
| 86 | 86 | |
|---|
| 87 | 87 | /* |
|---|
| 88 | 88 | * The uidhash_lock is mostly taken from process context, but it is |
|---|
| .. | .. |
|---|
| 141 | 141 | { |
|---|
| 142 | 142 | uid_hash_remove(up); |
|---|
| 143 | 143 | spin_unlock_irqrestore(&uidhash_lock, flags); |
|---|
| 144 | | - key_put(up->uid_keyring); |
|---|
| 145 | | - key_put(up->session_keyring); |
|---|
| 146 | 144 | kmem_cache_free(uid_cachep, up); |
|---|
| 147 | 145 | } |
|---|
| 148 | 146 | |
|---|
| .. | .. |
|---|
| 162 | 160 | spin_unlock_irqrestore(&uidhash_lock, flags); |
|---|
| 163 | 161 | return ret; |
|---|
| 164 | 162 | } |
|---|
| 163 | +EXPORT_SYMBOL_GPL(find_user); |
|---|
| 165 | 164 | |
|---|
| 166 | 165 | void free_uid(struct user_struct *up) |
|---|
| 167 | 166 | { |
|---|
| .. | .. |
|---|
| 173 | 172 | if (refcount_dec_and_lock_irqsave(&up->__count, &uidhash_lock, &flags)) |
|---|
| 174 | 173 | free_user(up, flags); |
|---|
| 175 | 174 | } |
|---|
| 175 | +EXPORT_SYMBOL_GPL(free_uid); |
|---|
| 176 | 176 | |
|---|
| 177 | 177 | struct user_struct *alloc_uid(kuid_t uid) |
|---|
| 178 | 178 | { |
|---|
| .. | .. |
|---|
| 186 | 186 | if (!up) { |
|---|
| 187 | 187 | new = kmem_cache_zalloc(uid_cachep, GFP_KERNEL); |
|---|
| 188 | 188 | if (!new) |
|---|
| 189 | | - goto out_unlock; |
|---|
| 189 | + return NULL; |
|---|
| 190 | 190 | |
|---|
| 191 | 191 | new->uid = uid; |
|---|
| 192 | 192 | refcount_set(&new->__count, 1); |
|---|
| .. | .. |
|---|
| 200 | 200 | spin_lock_irq(&uidhash_lock); |
|---|
| 201 | 201 | up = uid_hash_find(uid, hashent); |
|---|
| 202 | 202 | if (up) { |
|---|
| 203 | | - key_put(new->uid_keyring); |
|---|
| 204 | | - key_put(new->session_keyring); |
|---|
| 205 | 203 | kmem_cache_free(uid_cachep, new); |
|---|
| 206 | 204 | } else { |
|---|
| 207 | 205 | uid_hash_insert(new, hashent); |
|---|
| .. | .. |
|---|
| 209 | 207 | } |
|---|
| 210 | 208 | spin_unlock_irq(&uidhash_lock); |
|---|
| 211 | 209 | } |
|---|
| 212 | | - proc_register_uid(uid); |
|---|
| 213 | 210 | |
|---|
| 214 | 211 | return up; |
|---|
| 215 | | - |
|---|
| 216 | | -out_unlock: |
|---|
| 217 | | - return NULL; |
|---|
| 218 | 212 | } |
|---|
| 219 | 213 | |
|---|
| 220 | 214 | static int __init uid_cache_init(void) |
|---|
| .. | .. |
|---|
| 231 | 225 | spin_lock_irq(&uidhash_lock); |
|---|
| 232 | 226 | uid_hash_insert(&root_user, uidhashentry(GLOBAL_ROOT_UID)); |
|---|
| 233 | 227 | spin_unlock_irq(&uidhash_lock); |
|---|
| 234 | | - proc_register_uid(GLOBAL_ROOT_UID); |
|---|
| 235 | 228 | |
|---|
| 236 | 229 | return 0; |
|---|
| 237 | 230 | } |
|---|