ucounts
struct ucounts *ucounts = current_ucounts();
if (user_shm_lock(size, ucounts)) {
user_shm_unlock(size, ucounts);
struct ucounts *ucounts;
static struct ucounts *inc_mnt_namespaces(struct user_namespace *ns)
static void dec_mnt_namespaces(struct ucounts *ucounts)
dec_ucount(ucounts, UCOUNT_MNT_NAMESPACES);
dec_mnt_namespaces(ns->ucounts);
struct ucounts *ucounts;
ucounts = inc_mnt_namespaces(user_ns);
if (!ucounts)
dec_mnt_namespaces(ucounts);
dec_mnt_namespaces(ucounts);
new_ns->ucounts = ucounts;
if (group->fanotify_data.ucounts)
dec_ucount(group->fanotify_data.ucounts,
dec_ucount(group->fanotify_data.ucounts, UCOUNT_FANOTIFY_MARKS);
struct ucounts *ucounts = group->fanotify_data.ucounts;
!inc_ucount(ucounts->ns, ucounts->uid, UCOUNT_FANOTIFY_MARKS))
dec_ucount(ucounts, UCOUNT_FANOTIFY_MARKS);
group->fanotify_data.ucounts = inc_ucount(user_ns, current_euid(),
if (!group->fanotify_data.ucounts)
static inline void dec_inotify_instances(struct ucounts *ucounts)
dec_ucount(ucounts, UCOUNT_INOTIFY_INSTANCES);
static inline struct ucounts *inc_inotify_watches(struct ucounts *ucounts)
return inc_ucount(ucounts->ns, ucounts->uid, UCOUNT_INOTIFY_WATCHES);
static inline void dec_inotify_watches(struct ucounts *ucounts)
dec_ucount(ucounts, UCOUNT_INOTIFY_WATCHES);
if (group->inotify_data.ucounts)
dec_inotify_instances(group->inotify_data.ucounts);
dec_inotify_watches(group->inotify_data.ucounts);
if (!inc_inotify_watches(group->inotify_data.ucounts)) {
dec_inotify_watches(group->inotify_data.ucounts);
group->inotify_data.ucounts = inc_ucount(current_user_ns(),
if (!group->inotify_data.ucounts) {
if (!xqc->ucounts)
counts = xqc->ucounts;
if (xqc->ucounts) {
error = xqcheck_update_incore_counts(xqc, xqc->ucounts, id, 1,
if (xqc->ucounts) {
xfarray_destroy(xqc->ucounts);
xqc->ucounts = NULL;
sizeof(struct xqcheck_dquot), &xqc->ucounts);
if (xqc->ucounts) {
struct xfarray *ucounts;
return xqc->ucounts;
if (xqc->ucounts) {
struct ucounts *ucounts;
struct ucounts *ucounts;
#define task_ucounts(task) (task_cred_xxx((task), ucounts))
#define current_ucounts() (current_cred_xxx(ucounts))
struct ucounts *ucounts;
struct ucounts *ucounts;
struct ucounts *ucounts;
extern int user_shm_lock(size_t, struct ucounts *);
extern void user_shm_unlock(size_t, struct ucounts *);
struct ucounts *ucounts;
extern int shmem_lock(struct file *file, int lock, struct ucounts *ucounts);
struct ucounts;
struct ucounts *ucounts;
struct ucounts *ucounts;
struct ucounts *ucounts;
extern struct ucounts init_ucounts;
struct ucounts *inc_ucount(struct user_namespace *ns, kuid_t uid, enum ucount_type type);
void dec_ucount(struct ucounts *ucounts, enum ucount_type type);
struct ucounts *alloc_ucounts(struct user_namespace *ns, kuid_t uid);
void put_ucounts(struct ucounts *ucounts);
static inline struct ucounts * __must_check get_ucounts(struct ucounts *ucounts)
if (rcuref_get(&ucounts->count))
return ucounts;
static inline long get_rlimit_value(struct ucounts *ucounts, enum rlimit_type type)
return atomic_long_read(&ucounts->rlimit[type]);
long inc_rlimit_ucounts(struct ucounts *ucounts, enum rlimit_type type, long v);
bool dec_rlimit_ucounts(struct ucounts *ucounts, enum rlimit_type type, long v);
long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type,
void dec_rlimit_put_ucounts(struct ucounts *ucounts, enum rlimit_type type);
bool is_rlimit_overlimit(struct ucounts *ucounts, enum rlimit_type type, unsigned long max);
struct ucounts;
struct ucounts *ucounts;
struct ucounts *ucounts;
.ucounts = &init_ucounts,
struct ucounts *ucounts; /* user who created, for accounting */
info->ucounts = NULL; /* set when all is ok */
info->ucounts = get_ucounts(current_ucounts());
if (info->ucounts) {
msgqueue = inc_rlimit_ucounts(info->ucounts, UCOUNT_RLIMIT_MSGQUEUE, mq_bytes);
dec_rlimit_ucounts(info->ucounts, UCOUNT_RLIMIT_MSGQUEUE, mq_bytes);
put_ucounts(info->ucounts);
info->ucounts = NULL;
if (info->ucounts) {
dec_rlimit_ucounts(info->ucounts, UCOUNT_RLIMIT_MSGQUEUE, mq_bytes);
put_ucounts(info->ucounts);
info->ucounts = NULL;
dec_ipc_namespaces(ucounts);
dec_ipc_namespaces(ns->ucounts);
static struct ucounts *inc_ipc_namespaces(struct user_namespace *ns)
static void dec_ipc_namespaces(struct ucounts *ucounts)
dec_ucount(ucounts, UCOUNT_IPC_NAMESPACES);
struct ucounts *ucounts;
ucounts = inc_ipc_namespaces(user_ns);
if (!ucounts) {
ns->ucounts = ucounts;
struct ucounts *ucounts = current_ucounts();
err = shmem_lock(shm_file, 1, ucounts);
shp->mlock_ucounts = ucounts;
struct ucounts *mlock_ucounts;
static struct ucounts *inc_cgroup_namespaces(struct user_namespace *ns)
static void dec_cgroup_namespaces(struct ucounts *ucounts)
dec_ucount(ucounts, UCOUNT_CGROUP_NAMESPACES);
dec_cgroup_namespaces(ns->ucounts);
struct ucounts *ucounts;
ucounts = inc_cgroup_namespaces(user_ns);
if (!ucounts)
dec_cgroup_namespaces(ucounts);
new_ns->ucounts = ucounts;
new->ucounts = get_ucounts(new->ucounts);
if (!new->ucounts)
inc_rlimit_ucounts(new->ucounts, UCOUNT_RLIMIT_NPROC, 1);
dec_rlimit_ucounts(old->ucounts, UCOUNT_RLIMIT_NPROC, 1);
struct ucounts *new_ucounts, *old_ucounts = new->ucounts;
new->ucounts = new_ucounts;
if (cred->ucounts)
new->ucounts = get_ucounts(new->ucounts);
if (!new->ucounts)
put_ucounts(cred->ucounts);
ns->ucounts = ucounts;
dec_pid_namespaces(ucounts);
dec_pid_namespaces(ns->ucounts);
static struct ucounts *inc_pid_namespaces(struct user_namespace *ns)
static void dec_pid_namespaces(struct ucounts *ucounts)
dec_ucount(ucounts, UCOUNT_PID_NAMESPACES);
struct ucounts *ucounts;
ucounts = inc_pid_namespaces(user_ns);
if (!ucounts)
struct ucounts *ucounts = sig_get_ucounts(current, -1, 0);
if (!ucounts)
__sigqueue_init(q, ucounts, SIGQUEUE_PREALLOC);
static struct ucounts *sig_get_ucounts(struct task_struct *t, int sig,
struct ucounts *ucounts;
ucounts = task_ucounts(t);
sigpending = inc_rlimit_get_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING,
dec_rlimit_put_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING);
return ucounts;
static void __sigqueue_init(struct sigqueue *q, struct ucounts *ucounts,
q->ucounts = ucounts;
struct ucounts *ucounts = sig_get_ucounts(t, sig, override_rlimit);
if (!ucounts)
dec_rlimit_put_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING);
__sigqueue_init(q, ucounts, 0);
if (q->ucounts) {
dec_rlimit_put_ucounts(q->ucounts, UCOUNT_RLIMIT_SIGPENDING);
q->ucounts = NULL;
if (new->ucounts == current_ucounts())
if (is_rlimit_overlimit(new->ucounts, UCOUNT_RLIMIT_NPROC, rlimit(RLIMIT_NPROC)) &&
ns->ucounts = ucounts;
dec_time_namespaces(ucounts);
dec_time_namespaces(ns->ucounts);
static struct ucounts *inc_time_namespaces(struct user_namespace *ns)
static void dec_time_namespaces(struct ucounts *ucounts)
dec_ucount(ucounts, UCOUNT_TIME_NAMESPACES);
struct ucounts *ucounts;
ucounts = inc_time_namespaces(user_ns);
if (!ucounts)
if (tmr->sigq.ucounts)
dec_rlimit_put_ucounts(tmr->sigq.ucounts, UCOUNT_RLIMIT_SIGPENDING);
struct ucounts init_ucounts = {
static struct ucounts *find_ucounts(struct user_namespace *ns, kuid_t uid,
struct ucounts *ucounts;
hlist_nulls_for_each_entry_rcu(ucounts, pos, hashent, node) {
if (uid_eq(ucounts->uid, uid) && (ucounts->ns == ns)) {
if (rcuref_get(&ucounts->count))
return ucounts;
static void hlist_add_ucounts(struct ucounts *ucounts)
struct hlist_nulls_head *hashent = ucounts_hashentry(ucounts->ns, ucounts->uid);
hlist_nulls_add_head_rcu(&ucounts->node, hashent);
struct ucounts *alloc_ucounts(struct user_namespace *ns, kuid_t uid)
struct ucounts *ucounts, *new;
ucounts = find_ucounts(ns, uid, hashent);
if (ucounts)
return ucounts;
ucounts = find_ucounts(ns, uid, hashent);
if (ucounts) {
return ucounts;
void put_ucounts(struct ucounts *ucounts)
if (rcuref_put(&ucounts->count)) {
hlist_nulls_del_rcu(&ucounts->node);
put_user_ns(ucounts->ns);
kfree_rcu(ucounts, rcu);
struct ucounts *inc_ucount(struct user_namespace *ns, kuid_t uid,
struct ucounts *ucounts, *iter, *bad;
ucounts = alloc_ucounts(ns, uid);
for (iter = ucounts; iter; iter = tns->ucounts) {
return ucounts;
for (iter = ucounts; iter != bad; iter = iter->ns->ucounts)
put_ucounts(ucounts);
void dec_ucount(struct ucounts *ucounts, enum ucount_type type)
struct ucounts *iter;
for (iter = ucounts; iter; iter = iter->ns->ucounts) {
put_ucounts(ucounts);
long inc_rlimit_ucounts(struct ucounts *ucounts, enum rlimit_type type, long v)
struct ucounts *iter;
for (iter = ucounts; iter; iter = iter->ns->ucounts) {
else if (iter == ucounts)
bool dec_rlimit_ucounts(struct ucounts *ucounts, enum rlimit_type type, long v)
struct ucounts *iter;
for (iter = ucounts; iter; iter = iter->ns->ucounts) {
if (iter == ucounts)
static void do_dec_rlimit_put_ucounts(struct ucounts *ucounts,
struct ucounts *last, enum rlimit_type type)
struct ucounts *iter, *next;
for (iter = ucounts; iter != last; iter = next) {
next = iter->ns->ucounts;
void dec_rlimit_put_ucounts(struct ucounts *ucounts, enum rlimit_type type)
do_dec_rlimit_put_ucounts(ucounts, NULL, type);
long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type,
struct ucounts *iter;
for (iter = ucounts; iter; iter = iter->ns->ucounts) {
if (iter == ucounts)
do_dec_rlimit_put_ucounts(ucounts, iter, type);
bool is_rlimit_overlimit(struct ucounts *ucounts, enum rlimit_type type, unsigned long rlimit)
struct ucounts *iter;
for (iter = ucounts; iter; iter = iter->ns->ucounts) {
ns->ucounts = ucounts;
dec_user_namespaces(ucounts);
struct ucounts *ucounts = ns->ucounts;
dec_user_namespaces(ucounts);
static struct ucounts *inc_user_namespaces(struct user_namespace *ns, kuid_t uid)
static void dec_user_namespaces(struct ucounts *ucounts)
return dec_ucount(ucounts, UCOUNT_USER_NAMESPACES);
struct ucounts *ucounts;
ucounts = inc_user_namespaces(parent_ns, owner);
if (!ucounts)
static struct ucounts *inc_uts_namespaces(struct user_namespace *ns)
static void dec_uts_namespaces(struct ucounts *ucounts)
dec_ucount(ucounts, UCOUNT_UTS_NAMESPACES);
struct ucounts *ucounts;
ucounts = inc_uts_namespaces(user_ns);
if (!ucounts)
ns->ucounts = ucounts;
dec_uts_namespaces(ucounts);
dec_uts_namespaces(ns->ucounts);
int user_shm_lock(size_t size, struct ucounts *ucounts)
memlock = inc_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_MEMLOCK, locked);
dec_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_MEMLOCK, locked);
if (!get_ucounts(ucounts)) {
dec_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_MEMLOCK, locked);
void user_shm_unlock(size_t size, struct ucounts *ucounts)
dec_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_MEMLOCK, (size + PAGE_SIZE - 1) >> PAGE_SHIFT);
put_ucounts(ucounts);
int shmem_lock(struct file *file, int lock, struct ucounts *ucounts)
if (!user_shm_lock(inode->i_size, ucounts))
if (!lock && (info->flags & SHMEM_F_LOCKED) && ucounts) {
user_shm_unlock(inode->i_size, ucounts);
int shmem_lock(struct file *file, int lock, struct ucounts *ucounts)
static struct ucounts *inc_net_namespaces(struct user_namespace *ns)
static void dec_net_namespaces(struct ucounts *ucounts)
dec_ucount(ucounts, UCOUNT_NET_NAMESPACES);
struct ucounts *ucounts;
ucounts = inc_net_namespaces(user_ns);
if (!ucounts)
net->ucounts = ucounts;
dec_net_namespaces(ucounts);
dec_net_namespaces(net->ucounts);
if (unlikely(!get_ucounts(old->ucounts))) {
new->ucounts = old->ucounts;