Skip to content

Commit 6736fde

Browse files
committed
rfkill: fix rfkill_fop_read wait_event usage
The code within wait_event_interruptible() is called with !TASK_RUNNING, so mustn't call any functions that can sleep, like mutex_lock(). Since we re-check the list_empty() in a loop after the wait, it's safe to simply use list_empty() without locking. This bug has existed forever, but was only discovered now because all userspace implementations, including the default 'rfkill' tool, use poll() or select() to get a readable fd before attempting to read. Cc: stable@vger.kernel.org Fixes: c64fb01 ("rfkill: create useful userspace interface") Reported-by: Dmitry Vyukov <dvyukov@google.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 4fa11ec commit 6736fde

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

‎net/rfkill/core.c‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,17 +1095,6 @@ static unsigned int rfkill_fop_poll(struct file *file, poll_table *wait)
10951095
return res;
10961096
}
10971097

1098-
static bool rfkill_readable(struct rfkill_data *data)
1099-
{
1100-
bool r;
1101-
1102-
mutex_lock(&data->mtx);
1103-
r = !list_empty(&data->events);
1104-
mutex_unlock(&data->mtx);
1105-
1106-
return r;
1107-
}
1108-
11091098
static ssize_t rfkill_fop_read(struct file *file, char __user *buf,
11101099
size_t count, loff_t *pos)
11111100
{
@@ -1122,8 +1111,11 @@ static ssize_t rfkill_fop_read(struct file *file, char __user *buf,
11221111
goto out;
11231112
}
11241113
mutex_unlock(&data->mtx);
1114+
/* since we re-check and it just compares pointers,
1115+
* using !list_empty() without locking isn't a problem
1116+
*/
11251117
ret = wait_event_interruptible(data->read_wait,
1126-
rfkill_readable(data));
1118+
!list_empty(&data->events));
11271119
mutex_lock(&data->mtx);
11281120

11291121
if (ret)

0 commit comments

Comments
 (0)