]> git.baikalelectronics.ru Git - kernel.git/commit
ucount: Remove the atomicity from ucount->count
authorEric W. Biederman <ebiederm@xmission.com>
Sun, 5 Mar 2017 21:03:22 +0000 (15:03 -0600)
committerEric W. Biederman <ebiederm@xmission.com>
Mon, 6 Mar 2017 21:26:37 +0000 (15:26 -0600)
commit359df9e6155512970a2f87fa06f5a0582df26f58
treed2254d13ea030261eb3d894f8d7c3401f3e8a5e3
parent8a17c7afe9fb246fbdf434a8c4a84cdc5bada8cb
ucount: Remove the atomicity from ucount->count

Always increment/decrement ucount->count under the ucounts_lock.  The
increments are there already and moving the decrements there means the
locking logic of the code is simpler.  This simplification in the
locking logic fixes a race between put_ucounts and get_ucounts that
could result in a use-after-free because the count could go zero then
be found by get_ucounts and then be freed by put_ucounts.

A bug presumably this one was found by a combination of syzkaller and
KASAN.  JongWhan Kim reported the syzkaller failure and Dmitry Vyukov
spotted the race in the code.

Cc: stable@vger.kernel.org
Fixes: 551ebabcb29a ("userns: Make the count of user namespaces per user")
Reported-by: JongHwan Kim <zzoru007@gmail.com>
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Reviewed-by: Andrei Vagin <avagin@gmail.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
include/linux/user_namespace.h
kernel/ucount.c