[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 24/30] audio/jackaudio: Avoid dynamic stack allocation in qjack_pr
From: |
Peter Maydell |
Subject: |
[PULL 24/30] audio/jackaudio: Avoid dynamic stack allocation in qjack_process() |
Date: |
Thu, 21 Sep 2023 18:37:14 +0100 |
Avoid a dynamic stack allocation in qjack_process(). Since this
function is a JACK process callback, we are not permitted to malloc()
here, so we allocate a working buffer in qjack_client_init() instead.
The codebase has very few VLAs, and if we can get rid of them all we
can make the compiler error on new additions. This is a defensive
measure against security bugs where an on-stack dynamic allocation
isn't correctly size-checked (e.g. CVE-2021-3527).
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Francisco Iglesias <frasse.iglesias@gmail.com>
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Message-id: 20230818155846.1651287-3-peter.maydell@linaro.org
---
audio/jackaudio.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/audio/jackaudio.c b/audio/jackaudio.c
index 7cb2a49f971..e1eaa3477dc 100644
--- a/audio/jackaudio.c
+++ b/audio/jackaudio.c
@@ -70,6 +70,9 @@ typedef struct QJackClient {
int buffersize;
jack_port_t **port;
QJackBuffer fifo;
+
+ /* Used as workspace by qjack_process() */
+ float **process_buffers;
}
QJackClient;
@@ -267,22 +270,21 @@ static int qjack_process(jack_nframes_t nframes, void
*arg)
}
/* get the buffers for the ports */
- float *buffers[c->nchannels];
for (int i = 0; i < c->nchannels; ++i) {
- buffers[i] = jack_port_get_buffer(c->port[i], nframes);
+ c->process_buffers[i] = jack_port_get_buffer(c->port[i], nframes);
}
if (c->out) {
if (likely(c->enabled)) {
- qjack_buffer_read_l(&c->fifo, buffers, nframes);
+ qjack_buffer_read_l(&c->fifo, c->process_buffers, nframes);
} else {
for (int i = 0; i < c->nchannels; ++i) {
- memset(buffers[i], 0, nframes * sizeof(float));
+ memset(c->process_buffers[i], 0, nframes * sizeof(float));
}
}
} else {
if (likely(c->enabled)) {
- qjack_buffer_write_l(&c->fifo, buffers, nframes);
+ qjack_buffer_write_l(&c->fifo, c->process_buffers, nframes);
}
}
@@ -448,6 +450,9 @@ static int qjack_client_init(QJackClient *c)
jack_get_client_name(c->client));
}
+ /* Allocate working buffer for process callback */
+ c->process_buffers = g_new(float *, c->nchannels);
+
jack_set_process_callback(c->client, qjack_process , c);
jack_set_port_registration_callback(c->client, qjack_port_registration, c);
jack_set_xrun_callback(c->client, qjack_xrun, c);
@@ -579,6 +584,7 @@ static void qjack_client_fini_locked(QJackClient *c)
qjack_buffer_free(&c->fifo);
g_free(c->port);
+ g_free(c->process_buffers);
c->state = QJACK_STATE_DISCONNECTED;
/* fallthrough */
--
2.34.1
- [PULL 20/30] target/arm: Implement MTE tag-checking functions for FEAT_MOPS copies, (continued)
- [PULL 20/30] target/arm: Implement MTE tag-checking functions for FEAT_MOPS copies, Peter Maydell, 2023/09/21
- [PULL 16/30] target/arm: Implement MTE tag-checking functions for FEAT_MOPS, Peter Maydell, 2023/09/21
- [PULL 13/30] target/arm: Pass unpriv bool to get_a64_user_mem_index(), Peter Maydell, 2023/09/21
- [PULL 06/30] linux-user/elfload.c: Report previously missing arm32 hwcaps, Peter Maydell, 2023/09/21
- [PULL 23/30] audio/jackaudio: Avoid dynamic stack allocation in qjack_client_init, Peter Maydell, 2023/09/21
- [PULL 21/30] target/arm: Implement the CPY* instructions, Peter Maydell, 2023/09/21
- [PULL 18/30] target/arm: Define new TB flag for ATA0, Peter Maydell, 2023/09/21
- [PULL 28/30] elf2dmp: introduce merging of physical memory runs, Peter Maydell, 2023/09/21
- [PULL 15/30] target/arm: New function allocation_tag_mem_probe(), Peter Maydell, 2023/09/21
- [PULL 29/30] elf2dmp: use Linux mmap with MAP_NORESERVE when possible, Peter Maydell, 2023/09/21
- [PULL 24/30] audio/jackaudio: Avoid dynamic stack allocation in qjack_process(),
Peter Maydell <=
- [PULL 30/30] elf2dmp: rework PDB_STREAM_INDEXES::segments obtaining, Peter Maydell, 2023/09/21
- [PULL 27/30] elf2dmp: introduce physical block alignment, Peter Maydell, 2023/09/21
- [PULL 25/30] sbsa-ref: add non-secure EL2 virtual timer, Peter Maydell, 2023/09/21
- [PULL 26/30] elf2dmp: replace PE export name check with PDB name check, Peter Maydell, 2023/09/21
- [PULL 22/30] target/arm: Enable FEAT_MOPS for CPU 'max', Peter Maydell, 2023/09/21
- Re: [PULL 00/30] target-arm queue, Stefan Hajnoczi, 2023/09/25