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 X-Spam-Level: X-Spam-Status: No, score=-6.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8A0AC433DB for ; Tue, 12 Jan 2021 16:55:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE18A2311A for ; Tue, 12 Jan 2021 16:55:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405687AbhALQyt (ORCPT ); Tue, 12 Jan 2021 11:54:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:43816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729472AbhALQys (ORCPT ); Tue, 12 Jan 2021 11:54:48 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 501F52311F for ; Tue, 12 Jan 2021 16:54:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1610470447; bh=cIWoPzrWZKqwpLcgp2Lr54R7c9LfFLyCAMdonQt2vgE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=tgEWjeXs6AyAnI4Ro6p62pMt7NbBaRs+TJaIbP2M3hvhgd7JapbJDW1TGnrDksu9+ YDTXs8x8VheC3DxH3NeMGmED5KeO/EiKE8FT0wiHDNGgS0AmbjWsj7JqLv97KJ9LPY dqN5IBDcJ1fO5WLf2bTBR2hnaFQiKqLgzIThV8v1mFd+JlljYH8luUMgk4ra4KTn7g 0t2usReo20GOenehbL2XdPWBe4NOwRRrERy2FR8h8n3YeCbUX2w1VY3uV8Lvvfv24w xaKefDxfACkOf8xXm4YIVpnDSJ3PKDEvGeDvxpx5BGVUO2v5EgWZcAFuRd55ujCFCT Szt27SOiLnnQA== Received: by mail-ed1-f50.google.com with SMTP id v26so3044707eds.13 for ; Tue, 12 Jan 2021 08:54:07 -0800 (PST) X-Gm-Message-State: AOAM5308myxh69MWTbblYiLIaZU6azjsldOpeofkQsjHsatjTmD0OIk2 y3xIHIht0XEOZpCZcjQp/9ykApuecop2V1XF+0F5VQ== X-Google-Smtp-Source: ABdhPJxq37O3y4EfXgFM1mhi298ZQhVcoSs/RBIgHLO8RRbq93NlZ+KfnWfibO/uMVsn7hxjGYXuHozK/yTY6RRGNPw= X-Received: by 2002:aa7:ca55:: with SMTP id j21mr67361edt.172.1610470445858; Tue, 12 Jan 2021 08:54:05 -0800 (PST) MIME-Version: 1.0 References: <20210111200027.GH25645@zn.tnic> <5B5C1F0A-9780-4E42-BC65-742BAEE920BF@intel.com> In-Reply-To: From: Andy Lutomirski Date: Tue, 12 Jan 2021 08:53:53 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: gdbserver + fsgsbase kaputt To: "Metzger, Markus T" Cc: "Bae, Chang Seok" , Borislav Petkov , Andy Lutomirski , "tdevries@suse.com" , x86-ml , lkml Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 12, 2021 at 3:39 AM Metzger, Markus T wrote: > > > The GDB behavior looks to be different between the two cases -- with vs > > without gdb server, when I checked the GS/GSBASE values on the ptrace front. > > 64-bit GDB doesn't support FSGSBASE for 32-bit inferiors and it looks like gdbserver > might not support FSGSBASE, at all. > > I had added support for the former as part of the tests I wrote about a year ago [1] > but never submitted the patch. Was the discussion ever concluded? > > The general behavior should be that GDB reads a regset, overwrites the registers it > knows about, and writes it back again to preserve the original values of registers it > doesn't know about. > > When I log the values that are read and written for FSGSBASE, however, it looks like > ptrace is returning a non-zero GS_BASE on a read and gdbserver is writing zero on > the next write. I instrumented the kernel, and I see: [ 26.990644] getreg: gs_base = 0xf7f8e000 [ 26.991694] getreg: GS=0x63, GSBASE=0xf7f8e000 [ 26.993117] PTRACE_SETREGS [ 26.993813] putreg: change gsbase from 0xf7f8e000 to 0x0 [ 26.995134] putreg: write GS=0x63; old GSBASE=0x0 [ 26.996235] PTRACE_SETREGS done That's gdbserver reading GS and GSBASE and then telling the kernel to set GS to the same value and GSBASE to 0. I can come up with horrible kernel hacks to try to work around this, but gdbserver is really giving the kernel bad instructions here. --Andy