net: rfkill: reduce data->mtx scope in rfkill_fop_open
authorJohannes Berg <johannes.berg@intel.com>
Wed, 11 Oct 2023 14:55:10 +0000 (16:55 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 11 Oct 2023 14:55:10 +0000 (16:55 +0200)
commitf2ac54ebf85615a6d78f5eb213a8bbeeb17ebe5d
tree2a05651d3033d9195c20ad0176464a4fdc43447e
parentb2f750c3a80b285cd60c9346f8c96bd0a2a66cde
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: syzbot+509238e523e032442b80@syzkaller.appspotmail.com
Fixes: 2c3dfba4cf84 ("rfkill: sync before userspace visibility/changes")
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/rfkill/core.c