From nobody Mon Nov 23 04:36:04 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=1792825462; cv=none; d=zohomail.com; s=zohoarc; b=YaQR5T6nxd216JobWEJYNYGtvRDS4kk9/hpraw46s/Uhz9jESoC1/kgsqWVK74xiCbjxWAfjlEKMf+ve73f32JVuXdDMzmepsKJBQp5ILG9CLEKjVydQnDyTuetZwL79LkP69TWD0F5gO2JFI3Sf3W/8mfDnFEwQNgAcLdLQctc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792825462; 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=UybR/c4eJ3nqQgKXE31f5NtX/slPcOQRxgAYRyW9/RA=; b=MxZeb4pt6c2/Wnq6KlW5YMi2eT0Z9Yv+QXS32j/Vknk7srqJAdjSZkxxKASLEX+tOOPgjs6wopcA3LqU+NG6DFpXKNXVwjLzXTGhl4YS5Kk9x0q4jABJxe4zei0H7bO1VgKH4BeammeAI287lWtkDF2vWGzRb6RhHNeURx+yltI= 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 1792825461956164.66560959097296; Sat, 24 Oct 2026 00:04:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xKVnT-0007OZ-Fw; Sat, 24 Oct 2026 03:04:07 -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 1xKVnQ-0007OM-3j; Sat, 24 Oct 2026 03:04:04 -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 1xKVnN-000835-Vd; Sat, 24 Oct 2026 03:04:03 -0400 From: Stian Halseth DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=itx.no; s=mx.itx.no; t=1792825438; 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=UybR/c4eJ3nqQgKXE31f5NtX/slPcOQRxgAYRyW9/RA=; b=ZjJl96ZV0AVbFzwZM7GkY3LGEHXb0Z0w5sS3wVdCNrIq9awD6B2uiJX5p+hYSyWJyBmq7c Hu+5KIRGVQXYKOfRUCHW+sYY7eb0QmgwtkeyWvUhOUeRkAWKXOAmfGytqxGOoU2xJ2/oCU JQNKldy3WQCvxVAaNlcXQLp8V6Y0/y4= To: qemu-devel@nongnu.org Cc: Richard Henderson , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Matt Turner , Stian Halseth , qemu-stable@nongnu.org Subject: [PATCH v2] accel/tcg: Do not chain from a TB freed by tb_gen_code's flush Date: Sat, 24 Oct 2026 09:03:47 +0200 Message-ID: <20261024070347.1202239-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: 1792825466402158500 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. Since commit 25e5c6a320db ("accel/tcg: Allow cross-page goto_tb chaining in user-only builds"), user-only builds hit this easily, e.g. qemu-sparc64 -tb-size 1 on a program writing next to its PLT. Cc: qemu-stable@nongnu.org Fixes: ebf7a5d294a3 ("accel/tcg: Improve buffer overflow in tb_gen_code") Signed-off-by: Stian Halseth Reviewed-by: Matt Turner --- v2: - Drop the second Fixes: tag. 25e5c6a320db only makes it easy to hit (Matt) - Cc qemu-stable (Matt) - Rebased on master, code unchanged v1: https://lore.kernel.org/qemu-devel/20261023113245.562358-1-stian@itx.no/ 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