From nobody Mon Nov 23 04:34:13 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1792972123; cv=none; d=zohomail.com; s=zohoarc; b=ELKUyJHYOo5RplFbSD19xRdbYGzkOy9TT19A/kXTzE5UZlMaASXitROPJN94n427o+9Yp2JY2rkf+4Q4cUjUl9xvaF7/fUri/HQIwL60SI3Q6ybVNrUUZ2mzatVjxFSGZ8SRU6+PfYimtZHbbIHqS2mXjNbh3mslA51/amb4nPo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792972123; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To: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=E4EBPkvJT4HHZM+hkOnpPZ8ektePktmQrTRgK4EQrB8=; b=X7hNami+BjP+psy8e+2qVPoNm6BHlnJ+sii4SgQGucHk+drJ4vRXQXyEtGZb+sQs56PIAIhBfoNYSDLWoTAxINuHIT1zFU9tfes2hvAouu7SYn69eX/48mR3f97+bL372wI+8byJovnxm6ASutTJHWeoJSoHM5Lzs3F+slZRaTI= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17929721234471019.2453781214605; Sun, 25 Oct 2026 16:48:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xL7we-0000El-Do; Sun, 25 Oct 2026 19:48:08 -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 1xL7Uo-0006iw-QB for qemu-devel@nongnu.org; Sun, 25 Oct 2026 19:19:23 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xL7Un-00029q-6P for qemu-devel@nongnu.org; Sun, 25 Oct 2026 19:19:22 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-48b042c0759so1368041f8f.2 for ; Sun, 25 Oct 2026 16:19:20 -0700 (PDT) Received: from DESKTOP-ECOGLG7 (ppp079166142084.access.hol.gr. [79.166.142.84]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e3ecdfb8esm12767886f8f.54.2026.10.25.16.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2026 16:19:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792970359; x=1793575159; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=E4EBPkvJT4HHZM+hkOnpPZ8ektePktmQrTRgK4EQrB8=; b=JDF4h4pSfK+yJDDPGugwDXpdJp1Ah6gecnwezzjRmDQwa901Pmmpleg2F31gdu3eeN ltQDpLYB5Y1DvptQS+UnH3N0CUnrAVXi4Psto7VqjdDMaKzysZCKPNgjF0sQatLnfirP 6hDYuCRaY5I0IWE2l2zTrrPySVYRfk9bIIFNUwRxu6DBaKDmoR4t1bqXEi9m+A0J5m4T 7OTps06E48m2Os1j9SofIWylqjmMbYRu40Ct+jtqnf7YfePxGPfdHkXu6VULiVAkZSWM Iw9/uwdzrKZHG56TunBXvFl4g4gUFlnQpdndXPcVDot/jw4bf35PkdaOhbmywLX31Pox sDrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792970359; x=1793575159; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=E4EBPkvJT4HHZM+hkOnpPZ8ektePktmQrTRgK4EQrB8=; b=FULlHOJYdnCmWEWaN0Pvcp+aLuTwfmHyCFFDAMUmsSaJ8xcjGofFUjuQiKfPZbNysF cVAM+r2XXXbdKUmP2OcAH9hhrOAwohCFIV7FfkEJ/ReegHS06JAE0CUAjiLm6sDrTIFQ vuXZq5vKDJglFh0E6ApnA0ENPVJWBO5mpHJSp88BIBFu3ZUu4WqDrkmwe4oXLiaEfJuj PhXtcLRnJBEGN+dsg5Lwz87wuTSvetIb5lqt6lhUIA8k72eho28X39hyvKyNQNaF7XEI ZKFwtY+cc2tKNKWbJYQwLsPlHhZ5VY2EAGysDehwoe9a417PX4xKzn0KpwJK7p1FwXZr mLZQ== X-Gm-Message-State: AFq9FYI8y4MFOte1TGmmjN/R9flylBNVRAgxY73iR39Y2QqOcbvkS+PO ClQI+iGAnsJTwPrQ9MdBxxw9p5/kgP8u3mbTsc/5a4GyiASfxd3csmnfakKrFnB2 X-Gm-Gg: AYBFou1rtLt/fHiXSCMRfzcwWWDvrODh/ECfpby56uKKpyzEcilVRp/Bk4/3uIuDzaq 962s0G71E9znWci9EV2af2xmzxXLONfBNRVQfa3kF/6MU/HXi6RYS4FoFJeYP7KKr6PqLxkmrnw 1SFwDBvLPn5Hp/jKAo23Ebshn9lqHYVtRfEkSDslJiTvbQjXkShrlte7iHcXXPqUWecJ0cqdEM4 c9v8y9w6WaRbT8QDIYwr9fBCarLtiQtvhA5IEyLN1Qe0h7mctxU1FKLf7BKqVgCrZes1hFi52+f vWCL2U1UXuYwTwACTDLzS4XVkPFpFx3HjDDAthVH20UHgBvowpx2RPzbgLUrVShjHVGvXzw7Im2 E6wlrwupx7s1RUhUVqXLDhBLl98LJyd/Q4NkuBMI3eV/BRlVupsxlGB6hClAWJrQt/IVw/9TO9S rDYvIAqzrF2N8a8JXUtAH6MGYg1gbFDS/0Rn88NLUQJDkPv3JAxrleJEKRI8fTl9XuFRSjXWPdp eZhtYSaGW5JegCjzfOgCjShmbyt8qdiALR8B3/7pP63OLxOMhB9jOidNcZqscgpcJoVc12AFEHJ YK6DNvh+8OKXxHN2Ede+K//9YiVLt2w= X-Received: by 2002:a05:6000:2c0b:b0:48d:c15c:94a5 with SMTP id ffacd0b85a97d-48e3eb8671dmr8377707f8f.14.1792970359501; Sun, 25 Oct 2026 16:19:19 -0700 (PDT) From: NickSampanis To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, richard.henderson@linaro.org, NickSampanis Subject: [PATCH v1 1/3] target/i386/tcg: Fix 64-bit RSP truncation on retf in 64-bit mode Date: Mon, 26 Oct 2026 01:18:01 +0200 Message-ID: <20261025231803.870-2-nicksampanis@gmail.com> X-Mailer: git-send-email 2.51.0.windows.2 In-Reply-To: <20261025231803.870-1-nicksampanis@gmail.com> References: <20261025231803.870-1-nicksampanis@gmail.com> 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=2a00:1450:4864:20::42a; envelope-from=nicksampanis@gmail.com; helo=mail-wr1-x42a.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 25 Oct 2026 19:48:05 -0400 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 @gmail.com) X-ZM-MESSAGEID: 1792972124995158500 Content-Type: text/plain; charset="utf-8" When executing retf in 64-bit mode with a 16- or 32-bit operand size, `helper_ret_protected()` is invoked with a shift of 0 or 1. While in long mode the stack uses the full RSP and the SS attributes are ignored. This caused the code to fall back to `get_sp_mask(SS.flags)`. With `SS.B` clear, this applied a 16-bit mask (`0xffff`); with `SS.B` set, it applied a 32-bit mask (`0xffffffff`). As a result, a 64-bit RSP pointing above 4 GiB was truncated. As observed in testing, the truncated stack pop read the wrong address, loading corrupted values for the new CS and RIP which resulted in a `#GP` fault and then a triple fault. Fix this by ensuring that `helper_ret_protected()` uses the full 64-bit stack pointer with no mask applied whenever the active code segment (CS) is running in 64-bit mode. Signed-off-by: NickSampanis --- target/i386/tcg/seg_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/tcg/seg_helper.c b/target/i386/tcg/seg_helper.c index 45bffcd738..af18aec694 100644 --- a/target/i386/tcg/seg_helper.c +++ b/target/i386/tcg/seg_helper.c @@ -2056,7 +2056,7 @@ static inline void helper_ret_protected(CPUX86State *= env, int shift, sa.mmu_index =3D x86_mmu_index_pl(env, cpl); =20 #ifdef TARGET_X86_64 - if (shift =3D=3D 2) { + if (shift =3D=3D 2 || (env->hflags & HF_CS64_MASK)) { sa.sp_mask =3D -1; } else #endif --=20 2.51.0.windows.2 From nobody Mon Nov 23 04:34:13 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1792972123; cv=none; d=zohomail.com; s=zohoarc; b=bvXtoeGTiT93+hUnybh9pMO9HGhiNv2BPhN5kugAdlBOzalM36ofyzJiZyu0s/8NCHEdctgGwGJJcVmZ44p+n2z3IkfdbOWuyuEd12Li7AnaHy11mFF50kuanPmUBhpvDYE4mNcdLgrbKWdVq2iCPntihPW2+3r/tMWnlVDonn4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792972123; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To: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=kEYJvAqBfYlkI4cuWFKUiPqYc0nd1Y+i/MMABj65Dsg=; b=UoPcAVuBBd1fNd78AKtwd2xN2l3CPfey7VnkdaLtKNiaOxiTixgzol8U5ntHknyZJo0u2yZF8qUAR8tbk9BDf+LBLeDQBhAVeUNI6ywQk2q7LpmTOhd0ULFelZRf9x85wfvIBb1HFaE1Jpu4AeIVoPUvuhuhU0iXmnGyyILynq4= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179297212347050.1182881173404; Sun, 25 Oct 2026 16:48:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xL7we-0000Em-ER; Sun, 25 Oct 2026 19:48:08 -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 1xL7Uq-0006jC-9L for qemu-devel@nongnu.org; Sun, 25 Oct 2026 19:19:24 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xL7Uo-00029w-PI for qemu-devel@nongnu.org; Sun, 25 Oct 2026 19:19:24 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4a214af2076so16478865e9.0 for ; Sun, 25 Oct 2026 16:19:22 -0700 (PDT) Received: from DESKTOP-ECOGLG7 (ppp079166142084.access.hol.gr. [79.166.142.84]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e3ecdfb8esm12767886f8f.54.2026.10.25.16.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2026 16:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792970361; x=1793575161; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=kEYJvAqBfYlkI4cuWFKUiPqYc0nd1Y+i/MMABj65Dsg=; b=O2UXxwYZWFWbS0eWD6N5GoT0s02rXIIWBymQfl1g1cP3sO+DIPIKlrO4kyMmwOHDwv oECoggGqG5pTZZ5MPGf9iZ1D/va1KXNy2XHaAgy68PrrXA8kke7HzZojt2xO/DISvGRE RGpH5obqLv7AFlBnhwGSKiYX5BXQUHn454rmKJKTkO6Sk5qxpF17n7uL9qbYd0yMPmoB G+3/Ny4ryrbLiXlPD/LRiAfVFEYKf8tYygxl5zjFzpZmA40hbDFPd9GlS15wAVUdufCv GIyn/F1NUYK822u5gCN0P3nvTDgbXCucqFH9y1eH7nB6mAup5Nxve/jcvcL77lXwClvi xnwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792970361; x=1793575161; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=kEYJvAqBfYlkI4cuWFKUiPqYc0nd1Y+i/MMABj65Dsg=; b=MZHpyMi9HyvwKRMOjDQfIqpJMakTMHjsZoMeF7xjE1kHfIvNr+TATWJZPVzsfFFHdG KLceIKsOjb7bOhHnmFul7dum/88aPQ+e3RZLPE98RPGy5+VTQcWtWFkwB+Yuw25GSnml Fb6ZN0UT/6iiY6HTg5mOnzakiPJIn6P//rqcb0SEoAPkeXCh6EPsZlgNpIOP0K5YL7ze dif4QA02nFNcKiypZ9yw4fWPN0VYi6SSQ9qiY3fWNFIZR/Mn+8T0fMAPBc8b9OfGnaYj XvOMPBQj8PN+e/A5mvdU+93a00GU4heKgt8qvAA11+HjbJyFFod8RFAmy7xnMbW0f9Te +ooA== X-Gm-Message-State: AFq9FYJIXc4ap+qZytsFo17ohhb00FEjosBsrHZLw+x+se7XrAj4JZxu WTy0poxbcezZrCrQ5e0Q5ATJDg6BRhAm5aPpntvFvdkl1y44EnCz4zNSTzax1jkr X-Gm-Gg: AYBFou3d4CwysgpsVPTeuSWZ78FYslpWnPJ4BZvsk52tlh4QwfjwB/rp0beC72KbvRP au6DnpL4vi3qlajj89QEZm94b5VUNO+9zaBHlygCLHLDLZXrIA9mz5rGt7GaCKHLK4aP6gcJ2Id NbOY6/jQs0hxHfjIVptMkMN4bWrfVvEqgYy68K7Gr1C1f50IGAyGCuRsAWpOVWafc9AQgmsnM6H r9C7vMO8N9nAhntKqgplHLDjjFCuTiA+7bGzeqDqHZGLKWkjDNdPZ5scND0TEaaO9xwDAHUWvkw /s5UyGkvUtkcrnf8b6zm/e2YUTBd8HSTw/rPJdjP9xgZO4L1dckkMYJdsFrb+M3LDs0jkHHnqn5 K6kDman/w2OfvOgoB/Qz6Hosa8sydtodZl/mDnhg4ljlryJIZeeZTiibiJT0W26Fc13Ac0WXsPy KLu8I9AUK8lBrksKVdCyi0a8EOTJNHxPOOXC2o1jOBnSPtPVMI2jfVwB+SJKBsltuI85m+ELAaa f5WxbRJuUyBJha9WOxMWzMOvjxEwuw9YEfThLNUe8JTIN/5R8XjabfouVaUGqmV/Ykiv3QGWnAh iVR8xd227ieHJGALvUreuqfPxzXmoxc= X-Received: by 2002:a05:600c:3e10:b0:4a1:80d8:aed5 with SMTP id 5b1f17b1804b1-4a35ac8bc6amr86102295e9.6.1792970361160; Sun, 25 Oct 2026 16:19:21 -0700 (PDT) From: NickSampanis To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, richard.henderson@linaro.org, NickSampanis Subject: [PATCH v1 2/3] target/i386/tcg: Fix 64-bit RSP truncation on far call in 64-bit mode Date: Mon, 26 Oct 2026 01:18:02 +0200 Message-ID: <20261025231803.870-3-nicksampanis@gmail.com> X-Mailer: git-send-email 2.51.0.windows.2 In-Reply-To: <20261025231803.870-1-nicksampanis@gmail.com> References: <20261025231803.870-1-nicksampanis@gmail.com> 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=2a00:1450:4864:20::32c; envelope-from=nicksampanis@gmail.com; helo=mail-wm1-x32c.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 25 Oct 2026 19:48:05 -0400 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 @gmail.com) X-ZM-MESSAGEID: 1792972124991158500 Content-Type: text/plain; charset="utf-8" When executing a direct far call to a code segment (no call gate involved) in 64-bit mode with a 16- or 32-bit operand size, `lcall_protected` falls back to `get_sp_mask(SS.flags)`. This gives a 16- or 32-bit mask, but in 64-bit mode the stack always uses the full RSP. As a result, the pushes of the return address and the stack pointer update (`SET_ESP`) truncate RSP. This is the same bug fixed for retf in the previous patch. Use the full stack pointer, with no mask, for a direct far call when CS is 64-bit. Signed-off-by: NickSampanis --- target/i386/tcg/seg_helper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/target/i386/tcg/seg_helper.c b/target/i386/tcg/seg_helper.c index af18aec694..87492a2f64 100644 --- a/target/i386/tcg/seg_helper.c +++ b/target/i386/tcg/seg_helper.c @@ -1731,7 +1731,11 @@ void HELPER(lcall_protected)(CPUX86State *env, int n= ew_cs, target_ulong new_eip, #endif { sa.sp =3D env->regs[R_ESP]; - sa.sp_mask =3D get_sp_mask(env->segs[R_SS].flags); + if (env->hflags & HF_CS64_MASK) { + sa.sp_mask =3D -1; + } else { + sa.sp_mask =3D get_sp_mask(env->segs[R_SS].flags); + } sa.ss_base =3D env->segs[R_SS].base; if (shift) { pushl(&sa, env->segs[R_CS].selector); --=20 2.51.0.windows.2 From nobody Mon Nov 23 04:34:13 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1792972123; cv=none; d=zohomail.com; s=zohoarc; b=YuYYsDoU4UN80B1NGJU50YUQcVIspGZo9YQ0d/yTAXw/DQZs6fi4csF9024gwbDj8mKNV8De6b8atxq0g5kt8qmv7RktR/jQU4HPFs9QYeh+eqAT+t/HvIfOhc23oBXZY9oPk7r+BlunkR50VxT6j/xPB8aVybcJgs3d1m0J1Xk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792972123; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To: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=Sj5derNeFHp8EGmJKxNHuj+datGr10zGAX5suWbv+GY=; b=as04Rs1D75gwinMaYvzCt3GXUzwY+m2ZINN6bVrjgPN2UjVS+DeIqWvWLBrByFME7TbpNw22QJOHvNPuQQlS7bHxe/wcaDpyAZfJQSX8qN+jS7n8+YVysdfYvzutqh7OW+KWIqH0sXJaN/aHRNkTdXEwPavRfhNB34ICA7lkUco= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792972123358216.55046868825445; Sun, 25 Oct 2026 16:48:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xL7wc-0000ED-Pm; Sun, 25 Oct 2026 19:48:06 -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 1xL7Ur-0006jW-Tb for qemu-devel@nongnu.org; Sun, 25 Oct 2026 19:19:25 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xL7Uq-0002AM-Aq for qemu-devel@nongnu.org; Sun, 25 Oct 2026 19:19:25 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4a214c5c4c0so17885495e9.3 for ; Sun, 25 Oct 2026 16:19:23 -0700 (PDT) Received: from DESKTOP-ECOGLG7 (ppp079166142084.access.hol.gr. [79.166.142.84]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e3ecdfb8esm12767886f8f.54.2026.10.25.16.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2026 16:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792970363; x=1793575163; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Sj5derNeFHp8EGmJKxNHuj+datGr10zGAX5suWbv+GY=; b=UWUycLvdWD1SXjeIQKD1cKb8ZDH6gsop4Gm8Kjklw81mY1cXrey+KRBi943CdiV/JG io3rpxd7TKPU4PqQDo+nOLaFFEMQrrcfZgCYYA1o0A+iIotQmQpzyVKixeyVQa5rXYxj qfMQ3yWCH7hJNdZ7FyIV2jD+LZVzyzJwNpoEP9whlxI0Wu748wdt3sReXwAXYVZWsrPi flBVLA2/zv50ZLSt/xfNrPcVpLehK/oXx9iBHSyEUQD/dj4yuXY1RGz8lXQx80h/xyFz /iDj1NFgPKn1rvYobIC/PiLqOP0RQKcyp6DkYWI5qUsYobDCLfnmAmgiEuODrS/pilMr /C2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792970363; x=1793575163; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Sj5derNeFHp8EGmJKxNHuj+datGr10zGAX5suWbv+GY=; b=Cl5+Ift07NZjAnu9K6RqYCg9renPobP1uZplyJbWJvBUZtp2EAC2l+ZJHGn+VgySO+ xSlsDpk91yxT4TiR61/3uGnfuRvUTUyZoCz56LJjCmQRYV9AxXfkAvg39U8dQ+hY76MM EsPbVpKsVb7IlKrVHW9neXlsSqnkPT9XzdxMZkd63KI36aUuU4H06EaW8eEFFmFDXW8r 2BKGBdTeMSVQLWII2q+N6qfJAdYKWtC0kIStkC5x4UorovLu/qOXHTxJiRg4hzQQnguC +7EhQFtUTpDV7CL6/5nWRg9dEDFk1MVn0IYRtNvBu9cnLc5GNz4XFr2tglcA10EXAWLf fqrg== X-Gm-Message-State: AFq9FYINQYSoJxqv0AxhjdOpl9M2oVPnoHx0gxzC6mIYDIYCoysD4+1n Rsvw+iTcCU2zYJ+VS99sk5MxkpKXdfySV/LLBgMosWeFp79r2T+eW8wdi09ofwP6 X-Gm-Gg: AYBFou0itmytQUJHU7UWbtSnEaRmzQ7SEPF1/OZP7OIK86RjykbKtJwcQs2/oawsdey YgWFu96awayMIjRuHnRXjRmF05Kead+GV7BV36koSzYYViIK7Mk05bVhA+i9ijlR1udWRdIsE4x EEteWekSIkQizu/PiU+21yp+fxHVz00AYOVIfdKl1DC2BdeM1OFJbR0ZGaYSxADGyhmTCfJwPF9 RaMfGQk4iYCXz+bjN8PV3IvW4jbm6S9Y/JmZrpNedg59CoxgfZ7HQNCk6lLiZJWy6kXxiwTV9kg be2eqCQHtndh1lScRKGnqanKnFxO172Rm0zyrz+d5ve5M/0k0UsVqCZbUYo960C/ikhxFoPfrf5 h6+AdPpmfZm/7dlX6lT6/5+YnIgT3aR5r/HmwRpPgP4/SPgSnf5dbEl5srrQSijirnf0RLBCmHr lgTD2qsZIYxh4/QsFBMiusKIvkiKNN2Wk5EfneWEGBSjRkL6V3yG1GWE4zjvpi7crV4KkHCmowD ZrNx5C+GeSUSVbYH59x9BllwjLXC3ck2V05ADep2CfIIH7ouEDeG2p1UCcjBFqhv3U34vsDhn0v UxzA3G0fNQpmC3a2gUajTfPU0ZlFNhU= X-Received: by 2002:a05:600c:6217:b0:49c:d019:70c5 with SMTP id 5b1f17b1804b1-4a35aae5c3amr84642615e9.0.1792970362872; Sun, 25 Oct 2026 16:19:22 -0700 (PDT) From: NickSampanis To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, richard.henderson@linaro.org, NickSampanis Subject: [PATCH v1 3/3] target/i386/tcg: Fix 64-bit RSP truncation on far call through a call gate Date: Mon, 26 Oct 2026 01:18:03 +0200 Message-ID: <20261025231803.870-4-nicksampanis@gmail.com> X-Mailer: git-send-email 2.51.0.windows.2 In-Reply-To: <20261025231803.870-1-nicksampanis@gmail.com> References: <20261025231803.870-1-nicksampanis@gmail.com> 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=2a00:1450:4864:20::32f; envelope-from=nicksampanis@gmail.com; helo=mail-wm1-x32f.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 25 Oct 2026 19:48:05 -0400 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 @gmail.com) X-ZM-MESSAGEID: 1792972125167158500 Content-Type: text/plain; charset="utf-8" In long mode, a call gate is 16 bytes and always has a 64-bit target. For a same-privilege call through a call gate, which can also be reached by a compatibility-mode caller, lcall_protected uses get_sp_mask(SS.flags) even though the pushes are 8 bytes. Consequently, the pushes and the stack pointer update (SET_ESP) truncate RSP. This is the same bug as in the previous two patches. Use the full stack pointer when shift =3D=3D 2, the same as the inner-privilege branch. This condition tests the gate's own size rather than the caller's mode, which is why it checks shift =3D=3D 2 instead of HF_CS64_MASK. Signed-off-by: NickSampanis --- target/i386/tcg/seg_helper.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/target/i386/tcg/seg_helper.c b/target/i386/tcg/seg_helper.c index 87492a2f64..f11b55d136 100644 --- a/target/i386/tcg/seg_helper.c +++ b/target/i386/tcg/seg_helper.c @@ -1925,7 +1925,12 @@ void HELPER(lcall_protected)(CPUX86State *env, int n= ew_cs, target_ulong new_eip, /* to same privilege */ sa.mmu_index =3D x86_mmu_index_pl(env, cpl); sa.sp =3D env->regs[R_ESP]; - sa.sp_mask =3D get_sp_mask(env->segs[R_SS].flags); +#ifdef TARGET_X86_64 + if (shift =3D=3D 2) { + sa.sp_mask =3D -1; + } else +#endif + sa.sp_mask =3D get_sp_mask(env->segs[R_SS].flags); sa.ss_base =3D env->segs[R_SS].base; /* push_size =3D (4 << shift); */ new_stack =3D 0; --=20 2.51.0.windows.2