Skip to content

Commit f2ac54e

Browse files
committed
net: rfkill: reduce data->mtx scope in rfkill_fop_open
In syzbot runs, lockdep reports that there's a (potential) deadlock here of data->mtx being locked recursively. This isn't really a deadlock since they are different instances, but lockdep cannot know, and teaching it would be far more difficult than other fixes. At the same time we don't even really _need_ the mutex to be locked in rfkill_fop_open(), since we're modifying only a completely fresh instance of 'data' (struct rfkill_data) that's not yet added to the global list. However, to avoid any reordering etc. within the globally locked section, and to make the code look more symmetric, we should still lock the data->events list manipulation, but also need to lock _only_ that. So do that. Reported-by: [email protected] Fixes: 2c3dfba ("rfkill: sync before userspace visibility/changes") Signed-off-by: Johannes Berg <[email protected]>
1 parent b2f750c commit f2ac54e

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

net/rfkill/core.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,6 @@ static int rfkill_fop_open(struct inode *inode, struct file *file)
11801180
init_waitqueue_head(&data->read_wait);
11811181

11821182
mutex_lock(&rfkill_global_mutex);
1183-
mutex_lock(&data->mtx);
11841183
/*
11851184
* start getting events from elsewhere but hold mtx to get
11861185
* startup events added first
@@ -1192,18 +1191,18 @@ static int rfkill_fop_open(struct inode *inode, struct file *file)
11921191
goto free;
11931192
rfkill_sync(rfkill);
11941193
rfkill_fill_event(&ev->ev, rfkill, RFKILL_OP_ADD);
1194+
mutex_lock(&data->mtx);
11951195
list_add_tail(&ev->list, &data->events);
1196+
mutex_unlock(&data->mtx);
11961197
}
11971198
list_add(&data->list, &rfkill_fds);
1198-
mutex_unlock(&data->mtx);
11991199
mutex_unlock(&rfkill_global_mutex);
12001200

12011201
file->private_data = data;
12021202

12031203
return stream_open(inode, file);
12041204

12051205
free:
1206-
mutex_unlock(&data->mtx);
12071206
mutex_unlock(&rfkill_global_mutex);
12081207
mutex_destroy(&data->mtx);
12091208
list_for_each_entry_safe(ev, tmp, &data->events, list)

0 commit comments

Comments
 (0)