Currently we have neither proper check nor protection against the concurrent calls of PCM hw_params and hw_free ioctls, which may result in a UAF. Since the existing PCM stream lock can't be used for protecting the whole ioctl operations, we need a new mutex to protect those racy calls. This patch introduced a new mutex, runtime->buffer_mutex, and applies it to both hw_params and hw_free ioctl code paths. Along with it, the both functions are slightly modified (the mmap_count check is moved into the state-check block) for code simplicity.
Showing the changes to include (1 of 3 files). Show all
Unified · Split
| @@ -401,6 +401,7 @@ struct snd_pcm_runtime { · 400 unmodified lines | ||
| 401 | 401 | wait_queue_head_t tsleep; /* transfer sleep */ |
| 402 | 402 | struct fasync_struct *fasync; |
| 403 | 403 | bool stop_operating; /* sync_stop will be called */ |
| 404 | + struct mutex buffer_mutex; /* protect for buffer changes */ | |
| 404 | 405 | |
| 405 | 406 | /* -- private section -- */ |
| 406 | 407 | void *private_data; |