summaryrefslogtreecommitdiff
path: root/include/sound
diff options
context:
space:
mode:
authorDaniel Rosenberg <drosen@google.com>2017-10-31 16:55:26 -0700
committerGerrit - the friendly Code Review server <code-review@localhost>2018-05-02 05:13:18 -0700
commit742017e8de6a8d221470ced85a2a481e89b9719d (patch)
treeff9d9f3964e92748f74f72f47927a04508279d74 /include/sound
parentd1507b1236caee1b7efdbffb1f2d16ab387164f5 (diff)
ANDROID: sound: rawmidi: Hold lock around realloc
The SNDRV_RAWMIDI_STREAM_{OUTPUT,INPUT} ioctls may reallocate runtime->buffer while other kernel threads are accessing it. If the underlying krealloc() call frees the original buffer, then this can turn into a use-after-free. Most of these accesses happen while the thread is holding runtime->lock, and can be fixed by just holding the same lock while replacing runtime->buffer, however we can't hold this spinlock while snd_rawmidi_kernel_{read1,write1} are copying to/from userspace. We need to add and acquire a new mutex to prevent this from happening concurrently with reallocation. We hold this mutex during the entire reallocation process, to also prevent multiple concurrent reallocations leading to a double-free. Signed-off-by: Daniel Rosenberg <drosen@google.com> bug: 64315347 Change-Id: I05764d4f1a38f373eb7c0ac1c98607ee5ff0eded [dcagle@codeaurora.org: Resolve trivial merge conflict] Git-repo: https://android.googlesource.com/kernel/msm Git-commit: d7193540482d11ff0ad3a07fc18717811641c6eb Signed-off-by: Dennis Cagle <dcagle@codeaurora.org>
Diffstat (limited to 'include/sound')
-rw-r--r--include/sound/rawmidi.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/include/sound/rawmidi.h b/include/sound/rawmidi.h
index 3b91ad5d5115..2dd096eea935 100644
--- a/include/sound/rawmidi.h
+++ b/include/sound/rawmidi.h
@@ -78,6 +78,7 @@ struct snd_rawmidi_runtime {
size_t xruns; /* over/underruns counter */
/* misc */
spinlock_t lock;
+ struct mutex realloc_mutex;
wait_queue_head_t sleep;
/* event handler (new bytes, input only) */
void (*event)(struct snd_rawmidi_substream *substream);