Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Ingo Molnar | 8703e8a | 2017-02-08 18:51:30 +0100 | [diff] [blame] | 2 | #ifndef _LINUX_SCHED_USER_H |
| 3 | #define _LINUX_SCHED_USER_H |
| 4 | |
Ingo Molnar | de8deb0 | 2017-02-08 18:51:55 +0100 | [diff] [blame] | 5 | #include <linux/uidgid.h> |
| 6 | #include <linux/atomic.h> |
Sebastian Andrzej Siewior | fc37191 | 2018-08-21 21:55:38 -0700 | [diff] [blame] | 7 | #include <linux/refcount.h> |
Luck, Tony | bef3efb | 2018-02-22 09:15:06 -0800 | [diff] [blame] | 8 | #include <linux/ratelimit.h> |
Ingo Molnar | 8703e8a | 2017-02-08 18:51:30 +0100 | [diff] [blame] | 9 | |
Ingo Molnar | bcbb6a5 | 2017-02-02 10:22:42 +0100 | [diff] [blame] | 10 | struct key; |
| 11 | |
| 12 | /* |
| 13 | * Some day this will be a full-fledged user tracking system.. |
| 14 | */ |
| 15 | struct user_struct { |
Sebastian Andrzej Siewior | fc37191 | 2018-08-21 21:55:38 -0700 | [diff] [blame] | 16 | refcount_t __count; /* reference count */ |
Ingo Molnar | bcbb6a5 | 2017-02-02 10:22:42 +0100 | [diff] [blame] | 17 | atomic_t processes; /* How many processes does this user have? */ |
| 18 | atomic_t sigpending; /* How many pending signals does this user have? */ |
| 19 | #ifdef CONFIG_FANOTIFY |
| 20 | atomic_t fanotify_listeners; |
| 21 | #endif |
| 22 | #ifdef CONFIG_EPOLL |
| 23 | atomic_long_t epoll_watches; /* The number of file descriptors currently watched */ |
| 24 | #endif |
| 25 | #ifdef CONFIG_POSIX_MQUEUE |
| 26 | /* protected by mq_lock */ |
| 27 | unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */ |
| 28 | #endif |
| 29 | unsigned long locked_shm; /* How many pages of mlocked shm ? */ |
| 30 | unsigned long unix_inflight; /* How many files in flight in unix sockets */ |
| 31 | atomic_long_t pipe_bufs; /* how many pages are allocated in pipe buffers */ |
| 32 | |
| 33 | #ifdef CONFIG_KEYS |
Jann Horn | 0b9dc6c | 2019-03-27 16:55:08 +0100 | [diff] [blame] | 34 | /* |
| 35 | * These pointers can only change from NULL to a non-NULL value once. |
| 36 | * Writes are protected by key_user_keyring_mutex. |
| 37 | * Unlocked readers should use READ_ONCE() unless they know that |
| 38 | * install_user_keyrings() has been called successfully (which sets |
| 39 | * these members to non-NULL values, preventing further modifications). |
| 40 | */ |
Ingo Molnar | bcbb6a5 | 2017-02-02 10:22:42 +0100 | [diff] [blame] | 41 | struct key *uid_keyring; /* UID specific keyring */ |
| 42 | struct key *session_keyring; /* UID's default session keyring */ |
| 43 | #endif |
| 44 | |
| 45 | /* Hash table maintenance information */ |
| 46 | struct hlist_node uidhash_node; |
| 47 | kuid_t uid; |
| 48 | |
Willem de Bruijn | a91dbff | 2017-08-03 16:29:43 -0400 | [diff] [blame] | 49 | #if defined(CONFIG_PERF_EVENTS) || defined(CONFIG_BPF_SYSCALL) || \ |
Jens Axboe | 2b188cc | 2019-01-07 10:46:33 -0700 | [diff] [blame] | 50 | defined(CONFIG_NET) || defined(CONFIG_IO_URING) |
Ingo Molnar | bcbb6a5 | 2017-02-02 10:22:42 +0100 | [diff] [blame] | 51 | atomic_long_t locked_vm; |
| 52 | #endif |
Luck, Tony | bef3efb | 2018-02-22 09:15:06 -0800 | [diff] [blame] | 53 | |
| 54 | /* Miscellaneous per-user rate limit */ |
| 55 | struct ratelimit_state ratelimit; |
Ingo Molnar | bcbb6a5 | 2017-02-02 10:22:42 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | extern int uids_sysfs_init(void); |
| 59 | |
| 60 | extern struct user_struct *find_user(kuid_t); |
| 61 | |
| 62 | extern struct user_struct root_user; |
| 63 | #define INIT_USER (&root_user) |
| 64 | |
| 65 | |
| 66 | /* per-UID process charging. */ |
| 67 | extern struct user_struct * alloc_uid(kuid_t); |
| 68 | static inline struct user_struct *get_uid(struct user_struct *u) |
| 69 | { |
Sebastian Andrzej Siewior | fc37191 | 2018-08-21 21:55:38 -0700 | [diff] [blame] | 70 | refcount_inc(&u->__count); |
Ingo Molnar | bcbb6a5 | 2017-02-02 10:22:42 +0100 | [diff] [blame] | 71 | return u; |
| 72 | } |
| 73 | extern void free_uid(struct user_struct *); |
| 74 | |
Ingo Molnar | 8703e8a | 2017-02-08 18:51:30 +0100 | [diff] [blame] | 75 | #endif /* _LINUX_SCHED_USER_H */ |