mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-09 22:50:41 +00:00
clean overflow checks in count_mounts() a bit
Wraparound checks in there are redundant (x + y < x and x + y < y are equivalent when x and y are both unsigned int). IMO more straightforward code would be better here... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
90b2433edb
commit
124f75f864
@ -2069,22 +2069,23 @@ static int invent_group_ids(struct mount *mnt, bool recurse)
|
|||||||
int count_mounts(struct mnt_namespace *ns, struct mount *mnt)
|
int count_mounts(struct mnt_namespace *ns, struct mount *mnt)
|
||||||
{
|
{
|
||||||
unsigned int max = READ_ONCE(sysctl_mount_max);
|
unsigned int max = READ_ONCE(sysctl_mount_max);
|
||||||
unsigned int mounts = 0, old, pending, sum;
|
unsigned int mounts = 0;
|
||||||
struct mount *p;
|
struct mount *p;
|
||||||
|
|
||||||
|
if (ns->mounts >= max)
|
||||||
|
return -ENOSPC;
|
||||||
|
max -= ns->mounts;
|
||||||
|
if (ns->pending_mounts >= max)
|
||||||
|
return -ENOSPC;
|
||||||
|
max -= ns->pending_mounts;
|
||||||
|
|
||||||
for (p = mnt; p; p = next_mnt(p, mnt))
|
for (p = mnt; p; p = next_mnt(p, mnt))
|
||||||
mounts++;
|
mounts++;
|
||||||
|
|
||||||
old = ns->mounts;
|
if (mounts > max)
|
||||||
pending = ns->pending_mounts;
|
|
||||||
sum = old + pending;
|
|
||||||
if ((old > sum) ||
|
|
||||||
(pending > sum) ||
|
|
||||||
(max < sum) ||
|
|
||||||
(mounts > (max - sum)))
|
|
||||||
return -ENOSPC;
|
return -ENOSPC;
|
||||||
|
|
||||||
ns->pending_mounts = pending + mounts;
|
ns->pending_mounts += mounts;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user