From nobody Mon Nov 23 04:40:00 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=itx.no ARC-Seal: i=1; a=rsa-sha256; t=1792755225; cv=none; d=zohomail.com; s=zohoarc; b=ZH/4LtEnmHQyhFvLV29X6h4CpTMA/zHJCDCt2pC96flmbStAeLQPTIMZqXE0+zdOjzmnOyvpgUHgn1x+4kj3Kio74qFpibgBt/mpnx1DLwzoKI/D2MfETm1KXHx5VUJ3VaasnfqtYr/j3gypw7POO2DVyZ3WgmuohUDpAGN+jbE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792755225; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wn4CS5YaZzFVFFfojGZK/+tFo9ll/QsXAwk0tLt9WNw=; b=dUIuf2l/JwVBtpVhziaacx3ZtEyufluJM5gxxGmtySTl9PttAtihzaYdGFmbXeYjqKujCppbydeJ7QbWm1Fs7fC1vKFMhzm4MXtfM+Sg2qFbkpoXO1/CEl4cei1HTaA28miwDtqjLwdnF0Ckknkhy4Cv1Yrww/2WYviOmkCYORE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792755224999139.9422584333529; Fri, 23 Oct 2026 04:33:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xKDWB-0005oA-2d; Fri, 23 Oct 2026 07:33:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xKDW8-0005nw-GA for qemu-devel@nongnu.org; Fri, 23 Oct 2026 07:33:00 -0400 Received: from itx-kvm-14.itxnorge.no ([91.189.121.228] helo=mx.itxnorge.no) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xKDW6-0005p3-Fg for qemu-devel@nongnu.org; Fri, 23 Oct 2026 07:33:00 -0400 From: Stian Halseth DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=itx.no; s=mx.itx.no; t=1792755174; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=wn4CS5YaZzFVFFfojGZK/+tFo9ll/QsXAwk0tLt9WNw=; b=A9OLy/Vhh++KZNjIvEnTczm+oYBMVrTxwbtmKsDiEq3kkvYDAUP4aeKTkAWo09SNOZFoks mxA9vTDMULmO/vr3HfxHYYmnb6shaXPdw96UOLPOATW6vKkabTIL2paN3f1MKFUN8WBcee VKrMoIMM9QxfJVQ8c1MSonIZEjPBUg8= To: qemu-devel@nongnu.org Cc: Richard Henderson , Paolo Bonzini , Matt Turner , Stian Halseth Subject: [PATCH] accel/tcg: Do not chain from a TB freed by tb_gen_code's flush Date: Fri, 23 Oct 2026 13:32:45 +0200 Message-ID: <20261023113245.562358-1-stian@itx.no> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=91.189.121.228; envelope-from=stian@itx.no; helo=mx.itxnorge.no X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @itx.no) X-ZM-MESSAGEID: 1792755228659158500 Content-Type: text/plain; charset="utf-8" In a serial context, tb_gen_code() flushes a full code buffer and retries in place. cpu_exec_loop() then chains its last_tb, now freed, into the new TB. When that TB is invalidated, tb_jmp_unlink() follows the stale entry and qemu crashes inside its SIGSEGV handler. Drop last_tb when tb_gen_code() has flushed. User-only builds hit this easily since cross-page goto_tb chaining, e.g. qemu-sparc64 -tb-size 1 on a program writing next to its PLT. Fixes: ebf7a5d294a3 ("accel/tcg: Improve buffer overflow in tb_gen_code") Fixes: 25e5c6a320db ("accel/tcg: Allow cross-page goto_tb chaining in user-= only builds") Signed-off-by: Stian Halseth Reviewed-by: Matt Turner --- 25e5c6a320db is not in a release yet (v11.1.x does not have it), so the crash is new in the 11.2 cycle. Reproducers available on request: on x86_64 the stale chain happens too but has stayed harmless; on sparc64 it crashes every time. accel/tcg/cpu-exec.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 5b4bca5084..600e8c5fa8 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -968,11 +968,17 @@ cpu_exec_loop(CPUState *cpu, SyncClocks *sc) if (tb =3D=3D NULL) { CPUJumpCache *jc; uint32_t h; + unsigned flush_count =3D qatomic_read(&tb_ctx.tb_flush_cou= nt); =20 mmap_lock(); tb =3D tb_gen_code(cpu, s); mmap_unlock(); =20 + /* tb_gen_code may have flushed, freeing last_tb. */ + if (flush_count !=3D qatomic_read(&tb_ctx.tb_flush_count))= { + last_tb =3D NULL; + } + /* * We add the TB in the virtual pc hash table * for the fast lookup --=20 2.43.0