kdbus: improve user quota accounting by using kdbus_domain_user_account()
authorDjalal Harouni <tixxdz@opendz.org>
Wed, 30 Jul 2014 20:11:55 +0000 (21:11 +0100)
committerKay Sievers <kay@vrfy.org>
Thu, 31 Jul 2014 14:29:56 +0000 (16:29 +0200)
commite8c7fddfb695c384c6ecfdd15b3066480f473a45
tree1c7ed1d5f1fde6dbfd21c27acbec97023e24e347
parent4ff47b39b30671ccca96cef951a2af12a02cb7df
kdbus: improve user quota accounting by using kdbus_domain_user_account()

Currently kdbus_domain_user_find_or_new() is used to find a user
domain or create a new one and link it into the domain.

kdbus_domain_user_find_or_new() may fail due to memory allocation
errors or if the domain was shutdown, but since callers will
receive only a NULL pointer on failure, they assume -ENOMEM and
ignore -ESHUTDOWN. Fix this in kdbus_domain_user_account() by returning
the appropriate error code.

There are also some races with kdbus_domain_user_find_or_new(), if it is
called with the same parameters and if we do not find a previously
linked domain user, then both threads will race to assign a different ID
for the same uid, thus, invalidating the users array. We fix this in the
new kdbus_domain_user_account() and __kdbus_domain_user_account() by
taking the domain lock only one time.

Replace some kdbus_domain_user_find_or_new() calls with
kdbus_domain_user_account(). The last one in bus.c is updated in the
next patch.

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
connection.c
handle.c