Skip to content

Commit 4b1c784

Browse files
committed
device_cgroup: add lockdep asserts
device_cgroup uses RCU safe ->exceptions list which is write-protected by devcgroup_mutex and has had some issues using locking correctly. Add lockdep asserts to utility functions so that future errors can be easily detected. Signed-off-by: Tejun Heo <[email protected]> Acked-by: Serge E. Hallyn <[email protected]> Cc: Aristeu Rozanski <[email protected]> Cc: Li Zefan <[email protected]>
1 parent 5b805f2 commit 4b1c784

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

security/device_cgroup.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ static int dev_exceptions_copy(struct list_head *dest, struct list_head *orig)
8282
{
8383
struct dev_exception_item *ex, *tmp, *new;
8484

85+
lockdep_assert_held(&devcgroup_mutex);
86+
8587
list_for_each_entry(ex, orig, list) {
8688
new = kmemdup(ex, sizeof(*ex), GFP_KERNEL);
8789
if (!new)
@@ -107,6 +109,8 @@ static int dev_exception_add(struct dev_cgroup *dev_cgroup,
107109
{
108110
struct dev_exception_item *excopy, *walk;
109111

112+
lockdep_assert_held(&devcgroup_mutex);
113+
110114
excopy = kmemdup(ex, sizeof(*ex), GFP_KERNEL);
111115
if (!excopy)
112116
return -ENOMEM;
@@ -137,6 +141,8 @@ static void dev_exception_rm(struct dev_cgroup *dev_cgroup,
137141
{
138142
struct dev_exception_item *walk, *tmp;
139143

144+
lockdep_assert_held(&devcgroup_mutex);
145+
140146
list_for_each_entry_safe(walk, tmp, &dev_cgroup->exceptions, list) {
141147
if (walk->type != ex->type)
142148
continue;
@@ -163,6 +169,8 @@ static void dev_exception_clean(struct dev_cgroup *dev_cgroup)
163169
{
164170
struct dev_exception_item *ex, *tmp;
165171

172+
lockdep_assert_held(&devcgroup_mutex);
173+
166174
list_for_each_entry_safe(ex, tmp, &dev_cgroup->exceptions, list) {
167175
list_del_rcu(&ex->list);
168176
kfree_rcu(ex, rcu);
@@ -298,6 +306,10 @@ static int may_access(struct dev_cgroup *dev_cgroup,
298306
struct dev_exception_item *ex;
299307
bool match = false;
300308

309+
rcu_lockdep_assert(rcu_read_lock_held() ||
310+
lockdep_is_held(&devcgroup_mutex),
311+
"device_cgroup::may_access() called without proper synchronization");
312+
301313
list_for_each_entry_rcu(ex, &dev_cgroup->exceptions, list) {
302314
if ((refex->type & DEV_BLOCK) && !(ex->type & DEV_BLOCK))
303315
continue;

0 commit comments

Comments
 (0)