From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3ECCC83F01 for ; Thu, 31 Aug 2023 14:21:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbiXY-0005xS-II; Thu, 31 Aug 2023 10:20:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbiXV-0005wt-UZ for qemu-devel@nongnu.org; Thu, 31 Aug 2023 10:20:54 -0400 Received: from smtp-relay-services-0.canonical.com ([185.125.188.250]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbiXR-0003gq-3n for qemu-devel@nongnu.org; Thu, 31 Aug 2023 10:20:53 -0400 Received: from juju-98d295-prod-launchpad-16.localdomain (unknown [10.131.215.246]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-services-0.canonical.com (Postfix) with ESMTPSA id E96DB43213 for ; Thu, 31 Aug 2023 14:20:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=launchpad.net; s=20210803; t=1693491646; bh=gJGjQnbKEb0vQePQlYUB7PCnwyTqOHixej3loDUvK7Q=; h=MIME-Version:Content-Type:Date:From:To:Reply-To:References: Message-Id:Subject; b=T9BDS02qMG6aPLWDvIdDdMf4ckzTHPZbaTPod/EE4z2cgjYfLG+HkDAwC+lms2KQQ Z8LrPHFzLiUWbABHr8EieTPZ1S6nH3cE17gZ56bzL0NtoDpAZfigvz9Ma8bHWDgRR0 h28e37oQury+1nSV9MOCQ1RK/yq4aXRas1Wg3RZPocLUIa7WTZv4vszY7yGQGfCP// Y4eAAtosqLXZpsCUVYQ15eDDkIkzEQ5VSdc5iDx0TktIs8EyXWaDqie87aBLFjYHsz iikPqmqlotsmMJZDkodxovpiHTohOX6YI2b01+IEIBgjHZRfOcJQ1HOD2bf3rykA2B UWmLEsiYghHzw== Received: from [10.131.215.246] (localhost [127.0.0.1]) by juju-98d295-prod-launchpad-16.localdomain (Postfix) with ESMTP id CA5507E00E for ; Thu, 31 Aug 2023 14:20:46 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Date: Thu, 31 Aug 2023 14:12:13 -0000 From: Mauro Matteo Cascella <1863025@bugs.launchpad.net> To: qemu-devel@nongnu.org X-Launchpad-Notification-Type: bug X-Launchpad-Bug: product=qemu; status=Fix Released; importance=Undecided; assignee=alex.bennee@linaro.org; X-Launchpad-Bug-Tags: mttcg tcg X-Launchpad-Bug-Information-Type: Public X-Launchpad-Bug-Private: no X-Launchpad-Bug-Security-Vulnerability: no X-Launchpad-Bug-Commenters: ajbennee berrange laurent-vivier mauro-cascella samueloph yifanlu X-Launchpad-Bug-Reporter: Yifan (yifanlu) X-Launchpad-Bug-Modifier: Mauro Matteo Cascella (mauro-cascella) References: <158154486735.14935.3370403781300872079.malonedeb@soybean.canonical.com> Message-Id: <169349113346.586224.11228191307241880221.launchpad@juju-98d295-prod-launchpad-16> Subject: [Bug 1863025] Re: Use-after-free after flush in TCG accelerator X-Launchpad-Message-Rationale: Subscriber (QEMU) @qemu-devel-ml X-Launchpad-Message-For: qemu-devel-ml Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="5e6925a96ee17ce45a766139d74108c2c83abbc9"; Instance="launchpad-scripts" X-Launchpad-Hash: edce14a9d6c1cda06a4a28b99fb7afa933d03119 Received-SPF: pass client-ip=185.125.188.250; envelope-from=noreply@launchpad.net; helo=smtp-relay-services-0.canonical.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Bug 1863025 <1863025@bugs.launchpad.net> Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org ** CVE added: https://cve.mitre.org/cgi-bin/cvename.cgi?name=3D2022-36648 --=20 You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1863025 Title: Use-after-free after flush in TCG accelerator Status in QEMU: Fix Released Bug description: I believe I found a UAF in TCG that can lead to a guest VM escape. The security list informed me "This can not be treated as a security issue." and to post it here. I am looking at the 4.2.0 source code. The issue requires a race and I will try to describe it in terms of three concurrent threads. Thread A: A1. qemu_tcg_cpu_thread_fn runs work loop A2. qemu_wait_io_event =3D> qemu_wait_io_event_common =3D> process_queued= _cpu_work A3. start_exclusive critical section entered A4. do_tb_flush is called, TB memory freed/re-allocated A5. end_exclusive exits critical section Thread B: B1. qemu_tcg_cpu_thread_fn runs work loop B2. tcg_cpu_exec =3D> cpu_exec =3D> tb_find =3D> tb_gen_code B3. tcg_tb_alloc obtains a new TB Thread C: C1. qemu_tcg_cpu_thread_fn runs work loop C2. cpu_exec_step_atomic executes C3. TB obtained with tb_lookup__cpu_state or tb_gen_code C4. start_exclusive critical section entered C5. cpu_tb_exec executes the TB code C6. end_exclusive exits critical section Consider the following sequence of events: =C2=A0=C2=A0B2 =3D> B3 =3D> C3 (same TB as B2) =3D> A3 =3D> A4 (TB freed)= =3D> A5 =3D> B2 =3D> =C2=A0=C2=A0B3 (re-allocates TB from B2) =3D> C4 =3D> C5 (freed/reused TB= now executing) =3D> C6 In short, because thread C uses the TB in the critical section, there is no guarantee that the pointer has not been "freed" (rather the memory is marked as re-usable) and therefore a use-after-free occurs. Since the TCG generated code can be in the same memory as the TB data structure, it is possible for an attacker to overwrite the UAF pointer with code generated from TCG. This can overwrite key pointer values and could lead to code execution on the host outside of the TCG sandbox. To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1863025/+subscriptions