{"id":2221192,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2221192/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260408012341.16131-1-yujun@kylinos.cn/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.1/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260408012341.16131-1-yujun@kylinos.cn>","date":"2026-04-08T01:23:41","name":"audio/pipewire: Fix stack overflow by moving buffer to heap","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"6aaca2302a508369f28336f8441c88873899b785","submitter":{"id":93090,"url":"http://patchwork.ozlabs.org/api/1.1/people/93090/?format=json","name":"Jun Yu","email":"yujun@kylinos.cn"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260408012341.16131-1-yujun@kylinos.cn/mbox/","series":[{"id":499202,"url":"http://patchwork.ozlabs.org/api/1.1/series/499202/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=499202","date":"2026-04-08T01:23:41","name":"audio/pipewire: Fix stack overflow by moving buffer to heap","version":1,"mbox":"http://patchwork.ozlabs.org/series/499202/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2221192/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2221192/checks/","tags":{},"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":"legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)","Received":["from lists.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4frYMd1ZX2z1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 09 Apr 2026 05:41:01 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wAYdQ-0002go-0D; Wed, 08 Apr 2026 15:32:20 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <yujun@kylinos.cn>) id 1wAYJO-00088t-US\n for qemu-devel@nongnu.org; Wed, 08 Apr 2026 15:11:39 -0400","from mailgw.kylinos.cn ([124.126.103.232])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <yujun@kylinos.cn>) id 1wAHeP-00056h-3P\n for qemu-devel@nongnu.org; Tue, 07 Apr 2026 21:24:17 -0400","from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn\n (envelope-from <yujun@kylinos.cn>)\n (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256)\n with ESMTP id 1573712403; Wed, 08 Apr 2026 09:23:56 +0800"],"X-UUID":["9ce9225c32e911f1aa26b74ffac11d73-20260408","9ce9225c32e911f1aa26b74ffac11d73-20260408"],"X-CID-P-RULE":"Release_Ham","X-CID-O-INFO":"VERSION:1.3.12, REQID:232959a4-facd-47cb-91cd-aa8f8797d01a,\n IP:0,\n U\n RL:0,TC:0,Content:-5,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION\n :release,TS:-5","X-CID-META":"VersionHash:e7bac3a, CLOUDID:1486a81185f24feb4d20892f30c03bf4,\n BulkI\n D:nil,BulkQuantity:0,Recheck:0,SF:102|850|898,TC:nil,Content:0|15|50,EDM:-\n 3,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,A\n V:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0","X-CID-BVR":"2,SSN|SDN","X-CID-BAS":"2,SSN|SDN,0,_","X-CID-FACTOR":"TF_CID_SPAM_SNR","X-CID-RHF":"D41D8CD98F00B204E9800998ECF8427E","X-User":"yujun@kylinos.cn","From":"Jun Yu <yujun@kylinos.cn>","To":"marcandre.lureau@redhat.com,\n\todaki@rsg.ci.i.u-tokyo.ac.jp","Cc":"mark.caveayland@nutanix.com, philmd@linaro.org, thuth@redhat.com,\n qemu-devel@nongnu.org, Jun Yu <yujun@kylinos.cn>","Subject":"[PATCH] audio/pipewire: Fix stack overflow by moving buffer to heap","Date":"Wed,  8 Apr 2026 09:23:41 +0800","Message-Id":"<20260408012341.16131-1-yujun@kylinos.cn>","X-Mailer":"git-send-email 2.25.1","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=124.126.103.232; envelope-from=yujun@kylinos.cn;\n helo=mailgw.kylinos.cn","X-Spam_score_int":"-18","X-Spam_score":"-1.9","X-Spam_bar":"-","X-Spam_report":"(-1.9 / 5.0 requ) BAYES_00=-1.9,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,\n SPF_HELO_NONE=0.001, SPF_PASS=-0.001,\n UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no","X-Spam_action":"no action","X-Mailman-Approved-At":"Wed, 08 Apr 2026 15:32:16 -0400","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"},"content":"The PWVoice struct was allocating a large 4MB buffer on the stack using\nuint8_t buffer[RINGBUFFER_SIZE], which could cause stack overflow.\n\nThis commit:\n1. Changes the buffer from stack allocation to heap allocation by replacing\n   uint8_t buffer[RINGBUFFER_SIZE] with uint8_t *buffer\n2. Adds g_malloc() calls in qpw_init_out() and qpw_init_in() to allocate\n   the buffer on the heap\n3. Adds g_free() in qpw_voice_fini() to properly clean up the buffer\n4. Adds error handling for allocation failures\n\nThis fix prevents stack overflow while maintaining the same functionality,\nas each audio stream (input/output) still gets its own independent buffer\nfor the ringbuffer operations.\n\nSigned-off-by: Jun Yu <yujun@kylinos.cn>\n---\n audio/pwaudio.c | 20 +++++++++++++++++++-\n 1 file changed, 19 insertions(+), 1 deletion(-)","diff":"diff --git a/audio/pwaudio.c b/audio/pwaudio.c\nindex a59c22e60b..ff75ec2af2 100644\n--- a/audio/pwaudio.c\n+++ b/audio/pwaudio.c\n@@ -56,7 +56,7 @@ typedef struct PWVoice {\n     uint32_t highwater_mark;\n     uint32_t frame_size, req;\n     struct spa_ringbuffer ring;\n-    uint8_t buffer[RINGBUFFER_SIZE];\n+    uint8_t *buffer;\n \n     pwvolume volume;\n     bool muted;\n@@ -532,6 +532,12 @@ qpw_init_out(HWVoiceOut *hw, struct audsettings *as)\n     AudiodevPipewirePerDirectionOptions *ppdo = popts->out;\n     int r;\n \n+    v->buffer = g_malloc(RINGBUFFER_SIZE);\n+    if (!v->buffer) {\n+        error_report(\"pipewire: failed to allocate buffer\");\n+        return -1;\n+    }\n+\n     pw_thread_loop_lock(c->thread_loop);\n \n     v->info.format = audfmt_to_pw(as->fmt, as->big_endian);\n@@ -551,6 +557,8 @@ qpw_init_out(HWVoiceOut *hw, struct audsettings *as)\n                        ppdo->name, SPA_DIRECTION_OUTPUT);\n     if (r < 0) {\n         pw_thread_loop_unlock(c->thread_loop);\n+        g_free(v->buffer);\n+        v->buffer = NULL;\n         return -1;\n     }\n \n@@ -579,6 +587,12 @@ qpw_init_in(HWVoiceIn *hw, struct audsettings *as)\n     AudiodevPipewirePerDirectionOptions *ppdo = popts->in;\n     int r;\n \n+    v->buffer = g_malloc(RINGBUFFER_SIZE);\n+    if (!v->buffer) {\n+        error_report(\"pipewire: failed to allocate buffer\");\n+        return -1;\n+    }\n+\n     pw_thread_loop_lock(c->thread_loop);\n \n     v->info.format = audfmt_to_pw(as->fmt, as->big_endian);\n@@ -595,6 +609,8 @@ qpw_init_in(HWVoiceIn *hw, struct audsettings *as)\n                        ppdo->name, SPA_DIRECTION_INPUT);\n     if (r < 0) {\n         pw_thread_loop_unlock(c->thread_loop);\n+        g_free(v->buffer);\n+        v->buffer = NULL;\n         return -1;\n     }\n \n@@ -619,6 +635,8 @@ qpw_voice_fini(AudioPw *c, PWVoice *v)\n     pw_stream_destroy(v->stream);\n     v->stream = NULL;\n     pw_thread_loop_unlock(c->thread_loop);\n+    g_free(v->buffer);\n+    v->buffer = NULL;\n }\n \n static void\n","prefixes":[]}