From owner-freebsd-bugs@freebsd.org Fri Oct 2 06:44:36 2020 Return-Path: Delivered-To: freebsd-bugs@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6ABF03F89E5 for ; Fri, 2 Oct 2020 06:44:36 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mailman.nyi.freebsd.org (mailman.nyi.freebsd.org [IPv6:2610:1c1:1:606c::50:13]) by mx1.freebsd.org (Postfix) with ESMTP id 4C2gTJ2FT7z4FvT for ; Fri, 2 Oct 2020 06:44:36 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: by mailman.nyi.freebsd.org (Postfix) id 4B6E03F89EA; Fri, 2 Oct 2020 06:44:36 +0000 (UTC) Delivered-To: bugs@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4B3563F8C14 for ; Fri, 2 Oct 2020 06:44:36 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4C2gTJ1G80z4Fp7 for ; Fri, 2 Oct 2020 06:44:36 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 09CD71DF20 for ; Fri, 2 Oct 2020 06:44:36 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 0926iZNs074258 for ; Fri, 2 Oct 2020 06:44:35 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 0926iZr2074257 for bugs@FreeBSD.org; Fri, 2 Oct 2020 06:44:35 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 250043] ptrace() GETFPREGS/SETFPREGS uses 32-bit version of *XSAVE*/*XRSTOR* truncating FIP/FDP Date: Fri, 02 Oct 2020 06:44:35 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: Unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: mgorny@gentoo.org X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter cc Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Oct 2020 06:44:36 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D250043 Bug ID: 250043 Summary: ptrace() GETFPREGS/SETFPREGS uses 32-bit version of *XSAVE*/*XRSTOR* truncating FIP/FDP Product: Base System Version: Unspecified Hardware: amd64 OS: Any Status: New Severity: Affects Only Me Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: mgorny@gentoo.org CC: emaste@freebsd.org This is a problem discovered while working on new FreeBSD plugin for LLDB, = as contracted to Moritz Systems by FreeBSD Foundation. TL;DR: We'd need to replace 'plain' *xsave* and *xrstor* calls used to popu= late GETFPREGS/SETFPREGS on amd64 (or possibly all of them) with *xsave*64 and *xrstor*64. This changes the FIP/FDP representation inside the struct not = to be truncated to 32 bits (without changing anything else). Long version: The fxsave, xsave... and fxrstor, xrstor... instructions have two variants = on amd64. The variant without prefix uses a 32-bit compatible x87 register du= mp structure while the variant prefixed by rex.w=3D1 uses a 64-bit x87 register dump. The latter can be done in gas by appending '64' suffix to the comman= d, e.g. fxsave64. The only difference in these two variants is how FIP/FDP registers are writ= ten. In the 32-bit compatible variant, they are written as a 16-bit segment register (FCS/FDS) and an actual pointer truncated to 32 bits (FIP[31:0], FDP[31:0]), plus 16 bits of padding. In the 64-bit version, they are writt= en as full 64-bit register instead. FreeBSD currently calls the 32-bit compatible variant of instructions. Thi= s is problematic because it means that pointers exceeding 2^32 are truncated.=20 Switching to the 64-bit variant would solve that. This is a potentially breaking change but we don't think it is likely to br= eak anything. The FIP/FDP registers are used to locate instruction and its mem= ory operand (if any) when software handling of x87 exceptions is used. We don't think modern debuggers are used often in that context and even if they are,= the current state is broken as they get a truncated pointer. We'd lose access to respective segment registers but unless I'm mistaken th= ey aren't really used much these days. The problem also affects current versions of gdb. Linux gdb and lldb are u= sing the 64-bit variant. Although it is displayed split as fiseg/fioff, foseg/fooff, the *seg register does not contain the 16-bit segment but inst= ead FIP[63:32], FDP[63:32]. --=20 You are receiving this mail because: You are the assignee for the bug.=