Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp3211811pxb; Tue, 12 Jan 2021 08:59:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJyFGPDicnt78XU/Yj/DEdnE10rGR+HYnsWC8f7pVezHinEXYfOt4abD7Ct17+Pv54iJ8CBc X-Received: by 2002:a17:907:20a6:: with SMTP id pw6mr3930091ejb.73.1610470760315; Tue, 12 Jan 2021 08:59:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610470760; cv=none; d=google.com; s=arc-20160816; b=kIkNxuhFgURA6qWAsdrO55YZp7KklYUNTirhqGyVwXCOugx1byHQnGo6sje4UAjQL7 XfjORKEDeswshKROZHsc9rl9LSGzFh9zzKYlGRke+iteb9MBzFcMoeiqg+5Q2iEN3bLY PqsN2IIE5s1E3vguZ/qPRwdbS8dH03TKoo6Tk0w2ME3QQKOWFDpQ3Qok/2waWtr6FXM/ BLgEG/v+7X+YUX2TJLRuvNkShFe8VwDlXNu87GPFwgWIb6PlORXlqpcMD1SFSWckAPO6 qqFGdgTsFNh7D9OEUQoHv/1Lb4AlFlxOVM8PBuFvRGee2mB2zStYhhfrzhTFLr9EBBJp qt5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=95K+XOYDPJ9i0/BS169m0W0DQb+kHDm6kPuL1nkoX1A=; b=Qy0gA/2lUPgQqVNqW8ODYnbkHPELBRY7oNX7WCwfIfgQLsOHugPvWVf0yeelScGSqV caSDh6WMe21Z5hFByvf2fXbxyW1O+3TKSLMk+b5zcSF1SUexSJlCA5Kc5hHvTJK9xEE7 21DkNW6KxYZyN40yz9RyZJyQBV936dMAYna7MSY4vOkZEYkua7x1OBjI07/Vb01/6gtZ 1t05X+OYwbETmvxE7RK1+UaW83EVXw4x+lcPupa1bbDd6Ieu0e9foGlx7r6SKEKbhbwi riQCrOZNXA/87lzC+QaH+LfJebqJwaWlAlBnkjVtnXnIO8KhSmWLSpdKvt7wJ5y5K+J7 ttRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tgEWjeXs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u9si1547177edv.418.2021.01.12.08.58.56; Tue, 12 Jan 2021 08:59:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tgEWjeXs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405129AbhALQyt (ORCPT + 99 others); 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-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