user.h 1.8 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
2 3 4
#ifndef _LINUX_SCHED_USER_H
#define _LINUX_SCHED_USER_H

5 6
#include <linux/uidgid.h>
#include <linux/atomic.h>
7
#include <linux/refcount.h>
8
#include <linux/ratelimit.h>
9

10 11 12 13 14 15
struct key;

/*
 * Some day this will be a full-fledged user tracking system..
 */
struct user_struct {
16
	refcount_t __count;	/* reference count */
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
	atomic_t processes;	/* How many processes does this user have? */
	atomic_t sigpending;	/* How many pending signals does this user have? */
#ifdef CONFIG_FANOTIFY
	atomic_t fanotify_listeners;
#endif
#ifdef CONFIG_EPOLL
	atomic_long_t epoll_watches; /* The number of file descriptors currently watched */
#endif
#ifdef CONFIG_POSIX_MQUEUE
	/* protected by mq_lock	*/
	unsigned long mq_bytes;	/* How many bytes can be allocated to mqueue? */
#endif
	unsigned long locked_shm; /* How many pages of mlocked shm ? */
	unsigned long unix_inflight;	/* How many files in flight in unix sockets */
	atomic_long_t pipe_bufs;  /* how many pages are allocated in pipe buffers */

#ifdef CONFIG_KEYS
	struct key *uid_keyring;	/* UID specific keyring */
	struct key *session_keyring;	/* UID's default session keyring */
#endif

	/* Hash table maintenance information */
	struct hlist_node uidhash_node;
	kuid_t uid;

42 43
#if defined(CONFIG_PERF_EVENTS) || defined(CONFIG_BPF_SYSCALL) || \
    defined(CONFIG_NET)
44 45
	atomic_long_t locked_vm;
#endif
46 47 48

	/* Miscellaneous per-user rate limit */
	struct ratelimit_state ratelimit;
49 50 51 52 53 54 55 56 57 58 59 60 61 62
};

extern int uids_sysfs_init(void);

extern struct user_struct *find_user(kuid_t);

extern struct user_struct root_user;
#define INIT_USER (&root_user)


/* per-UID process charging. */
extern struct user_struct * alloc_uid(kuid_t);
static inline struct user_struct *get_uid(struct user_struct *u)
{
63
	refcount_inc(&u->__count);
64 65 66 67
	return u;
}
extern void free_uid(struct user_struct *);

68
#endif /* _LINUX_SCHED_USER_H */