Skip to content

Commit f9c82a4

Browse files
legionusebiederm
authored andcommitted
Increase size of ucounts to atomic_long_t
RLIMIT_MSGQUEUE and RLIMIT_MEMLOCK use unsigned long to store their counters. As a preparation for moving rlimits based on ucounts, we need to increase the size of the variable to long. Signed-off-by: Alexey Gladkov <[email protected]> Link: https://lkml.kernel.org/r/257aa5fb1a7d81cf0f4c34f39ada2320c4284771.1619094428.git.legion@kernel.org Signed-off-by: Eric W. Biederman <[email protected]>
1 parent 9f4ad9e commit f9c82a4

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

include/linux/user_namespace.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ struct user_namespace {
8888
struct ctl_table_header *sysctls;
8989
#endif
9090
struct ucounts *ucounts;
91-
int ucount_max[UCOUNT_COUNTS];
91+
long ucount_max[UCOUNT_COUNTS];
9292
} __randomize_layout;
9393

9494
struct ucounts {
9595
struct hlist_node node;
9696
struct user_namespace *ns;
9797
kuid_t uid;
9898
int count;
99-
atomic_t ucount[UCOUNT_COUNTS];
99+
atomic_long_t ucount[UCOUNT_COUNTS];
100100
};
101101

102102
extern struct user_namespace init_user_ns;

kernel/ucount.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,14 @@ static void put_ucounts(struct ucounts *ucounts)
175175
kfree(ucounts);
176176
}
177177

178-
static inline bool atomic_inc_below(atomic_t *v, int u)
178+
static inline bool atomic_long_inc_below(atomic_long_t *v, int u)
179179
{
180-
int c, old;
181-
c = atomic_read(v);
180+
long c, old;
181+
c = atomic_long_read(v);
182182
for (;;) {
183183
if (unlikely(c >= u))
184184
return false;
185-
old = atomic_cmpxchg(v, c, c+1);
185+
old = atomic_long_cmpxchg(v, c, c+1);
186186
if (likely(old == c))
187187
return true;
188188
c = old;
@@ -196,17 +196,17 @@ struct ucounts *inc_ucount(struct user_namespace *ns, kuid_t uid,
196196
struct user_namespace *tns;
197197
ucounts = get_ucounts(ns, uid);
198198
for (iter = ucounts; iter; iter = tns->ucounts) {
199-
int max;
199+
long max;
200200
tns = iter->ns;
201201
max = READ_ONCE(tns->ucount_max[type]);
202-
if (!atomic_inc_below(&iter->ucount[type], max))
202+
if (!atomic_long_inc_below(&iter->ucount[type], max))
203203
goto fail;
204204
}
205205
return ucounts;
206206
fail:
207207
bad = iter;
208208
for (iter = ucounts; iter != bad; iter = iter->ns->ucounts)
209-
atomic_dec(&iter->ucount[type]);
209+
atomic_long_dec(&iter->ucount[type]);
210210

211211
put_ucounts(ucounts);
212212
return NULL;
@@ -216,7 +216,7 @@ void dec_ucount(struct ucounts *ucounts, enum ucount_type type)
216216
{
217217
struct ucounts *iter;
218218
for (iter = ucounts; iter; iter = iter->ns->ucounts) {
219-
int dec = atomic_dec_if_positive(&iter->ucount[type]);
219+
long dec = atomic_long_dec_if_positive(&iter->ucount[type]);
220220
WARN_ON_ONCE(dec < 0);
221221
}
222222
put_ucounts(ucounts);

0 commit comments

Comments
 (0)