From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ZND7ES9GCGB8WgAAWB0awg (envelope-from ) for ; Wed, 20 Jan 2021 10:03:11 -0500 Received: by simark.ca (Postfix, from userid 112) id 3A9B21EF80; Wed, 20 Jan 2021 10:03:11 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 simark.ca (Postfix) with ESMTPS id 350F01E590 for ; Wed, 20 Jan 2021 10:03:10 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C7EF3857831; Wed, 20 Jan 2021 15:03:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C7EF3857831 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611154989; bh=9sILzVg+JeRPNkKF8wjkJBd81ykkDXe0UpyMty9ydD8=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=YrR83H63xbb5addjxnlNMXDtQeKaKEG888/GcsuyYBw4IVnqdMnNvcDli+uBvtXLU 2J6fQAZlVpIZLHEarw6JX1JMZeQKrvPneZ7Xd1R9q9/lUhGxw1fFJpKjXIS3/ZBeAa 3A5phR7maJKUHSU6mkbru7t+YcOzyBI4YLJ6unTY= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id A5E2C3857C7E for ; Wed, 20 Jan 2021 15:03:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A5E2C3857C7E Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 10KF2soM008527 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Jan 2021 10:02:59 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 10KF2soM008527 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 2A39E1E590; Wed, 20 Jan 2021 10:02:54 -0500 (EST) Subject: Re: [PATCH][gdb/server] Don't overwrite fs/gs_base with -m32 To: Tom de Vries , gdb-patches@sourceware.org References: <20210120125910.GA23080@delia> Message-ID: <717c43f6-639a-ded4-d324-3ab97ce297e7@polymtl.ca> Date: Wed, 20 Jan 2021 10:02:53 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20210120125910.GA23080@delia> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 20 Jan 2021 15:02:54 +0000 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 2021-01-20 7:59 a.m., Tom de Vries wrote: > Hi, > > Consider a minimal test-case test.c: > ... > int main (void) { return 0; } > ... > compiled with -m32: > ... > $ gcc test.c -m32 > ... > > When running the exec using gdbserver on openSUSE Factory (currently running a > linux kernel version 5.10.5): > ... > $ gdbserver localhost:12345 a.out > ... > to which we connect in a gdb session, we run into a segfault in the inferior: > ... > $ gdb -batch -q -ex "target remote localhost:12345" -ex continue > Program received signal SIGSEGV, Segmentation fault. > 0xf7dd8bd2 in init_cacheinfo () at ../sysdeps/x86/cacheinfo.c:761 > ... > > The segfault is caused by gdbserver overwriting $gs_base with 0 using > PTRACE_SETREGS. After it is overwritten, the next use of $gs in the inferior > will trigger the segfault. > > Before linux kernel version 5.9, the value used by PTRACE_SETREGS for $gs_base > was ignored, but starting version 5.9, the linux kernel has support for > intel architecture extension FSGSBASE, which allows users to modify $gs_base, > and consequently PTRACE_SETREGS can no longer ignore the $gs_base value. > > The overwrite of $gs_base with 0 is done by a memset in x86_fill_gregset, > which was added in commit 9e0aa64f551 "Fix gdbserver qGetTLSAddr for > x86_64 -m32". The memset intends to zero-extend 32-bit registers that are > tracked in the regcache to 64-bit when writing them into the PTRACE_SETREGS > data argument. But in addition, it overwrites other registers that are > not tracked in the regcache, such as $gs_base. > > Fix the segfault by redoing the fix from commit 9e0aa64f551 in minimal form. > > Tested on x86_64-linux: > - openSUSE Leap 15.2 (using kernel version 5.3.18): > - native > - gdbserver -m32 > - -m32 > - openSUSE Factory (using kernel version 5.10.5): > - native > - m32 > > Any comments? > > Thanks, > - Tom This looks good as far as I can tell, but please wait for Markus' to chime in as well. Simon