From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27534 invoked by alias); 4 Sep 2019 19:31:44 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 27525 invoked by uid 89); 4 Sep 2019 19:31:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=Notice X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 04 Sep 2019 19:31:42 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6494F335D7; Wed, 4 Sep 2019 19:31:41 +0000 (UTC) Received: from localhost (unused-10-15-17-196.yyz.redhat.com [10.15.17.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1E155D721; Wed, 4 Sep 2019 19:31:40 +0000 (UTC) From: Sergio Durigan Junior To: Pedro Alves Cc: GDB Patches , Eli Zaretskii , Ruslan Kabatsayev Subject: Re: [PATCH v2] Improve ptrace-error detection on Linux targets References: <20190819032918.3536-1-sergiodj@redhat.com> <20190826183205.19008-1-sergiodj@redhat.com> <28c4f743-91f1-59c3-83ff-3f791811f996@redhat.com> <87mufrai1z.fsf@redhat.com> Date: Wed, 04 Sep 2019 19:31:00 -0000 In-Reply-To: (Pedro Alves's message of "Fri, 30 Aug 2019 13:45:37 +0100") Message-ID: <87zhjjrh7n.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg00034.txt.bz2 On Friday, August 30 2019, Pedro Alves wrote: > Which is exactly what happened. Here's a patch implementing > the idea. Notice how gdbserver/linux-low.c:linux_attach > has a spot where it is currently using linux_ptrace_attach_fail_reason_string > after attaching to the main thread fails. That spot should be including > the new ptrace restrictions fail reasons, but it wasn't due to use of > linux_ptrace_attach_fail_reason_string: > > @@ -1202,7 +1202,7 @@ linux_attach (unsigned long pid) > { > remove_process (proc); > > - std::string reason = linux_ptrace_attach_fail_reason_string (ptid, err); > + std::string reason = linux_ptrace_attach_fail_reason (pid, err); > error ("Cannot attach to process %ld: %s", pid, reason.c_str ()); > } > > I haven't checked whether the resulting error message looks good as is, > or whether we need to tweak that error call in addition. Can you take it > from here? I forgot to say, but the way my patch works now prevents the code path above to be executed. My patch catches the ptrace failure very early in gdbserver initialization the process, when linux_child_function is called during the execution of linux_check_ptrace_features. Since linux_child_function will try to perform a PTRACE_TRACEME (and fail if there are any restrictions in place), gdbserver will error out before it even tries to spawn/attach. Nevertheless, during my tests I bypassed linux_check_ptrace_features and confirmed that the error message from linux_attach (above) is correctly displayed: [sergio@fedora-rawhide build]$ sleep 120 & [5] 2732388 [sergio@fedora-rawhide build]$ ./gdb/gdbserver/gdbserver :9911 --attach 2732388 gdbserver: linux_ptrace_test_ret_to_nx: Cannot PTRACE_TRACEME: Operation not permitted gdbserver: linux_ptrace_test_ret_to_nx: status 256 is not WIFSTOPPED! gdbserver: linux_ptrace_test_ret_to_nx: failed to kill child pid 2732391 No such process Cannot attach to process 2732388: The SELinux 'deny_ptrace' option is enabled and preventing GDB from using 'ptrace'. You can disable it by executing (as root): setsebool deny_ptrace off The Linux kernel's Yama ptrace scope is in effect, which can prevent GDB from using 'ptrace'. You can disable it by executing (as root): echo 0 > /proc/sys/kernel/yama/ptrace_scope Exiting Thanks, -- Sergio GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36 Please send encrypted e-mail if possible http://sergiodj.net/