From nobody Sat Oct 23 22:12:34 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id D5760181DF08; Sat, 23 Oct 2021 22:12:48 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (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 mx1.freebsd.org (Postfix) with ESMTPS id 4HcFp84MKsz4l7D; Sat, 23 Oct 2021 22:12:48 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 19NMCY1P084186 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sun, 24 Oct 2021 01:12:37 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 19NMCY1P084186 Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 19NMCYM1084185; Sun, 24 Oct 2021 01:12:34 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 24 Oct 2021 01:12:34 +0300 From: Konstantin Belousov To: Edward Tomasz Napierala Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 6e66030c4c05 - main - linux: implement PTRACE_EVENT_EXEC Message-ID: References: <202110231846.19NIkYg9047888@gitrepo.freebsd.org> List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202110231846.19NIkYg9047888@gitrepo.freebsd.org> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.5 X-Spam-Checker-Version: SpamAssassin 3.4.5 (2021-03-20) on tom.home X-Rspamd-Queue-Id: 4HcFp84MKsz4l7D X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-ThisMailContainsUnwantedMimeParts: N On Sat, Oct 23, 2021 at 06:46:34PM +0000, Edward Tomasz Napierala wrote: > The branch main has been updated by trasz: > > URL: https://cgit.FreeBSD.org/src/commit/?id=6e66030c4c05331f9b0adf87c31f2f233dd3ae1f > > commit 6e66030c4c05331f9b0adf87c31f2f233dd3ae1f > Author: Edward Tomasz Napierala > AuthorDate: 2021-10-23 18:13:14 +0000 > Commit: Edward Tomasz Napierala > CommitDate: 2021-10-23 18:46:26 +0000 > > linux: implement PTRACE_EVENT_EXEC > > This fixes strace(1) from Ubuntu Focal. > > Reviewed By: jhb > Sponsored By: EPSRC > Differential Revision: https://reviews.freebsd.org/D32367 > --- > sys/amd64/linux/linux_ptrace.c | 9 +++++++-- > sys/kern/subr_syscall.c | 12 ++++++++++++ > 2 files changed, 19 insertions(+), 2 deletions(-) > > diff --git a/sys/amd64/linux/linux_ptrace.c b/sys/amd64/linux/linux_ptrace.c > index 37f136856ef0..d7dffc92dd11 100644 > --- a/sys/amd64/linux/linux_ptrace.c > +++ b/sys/amd64/linux/linux_ptrace.c > @@ -71,6 +71,7 @@ __FBSDID("$FreeBSD$"); > #define LINUX_PTRACE_SEIZE 0x4206 > #define LINUX_PTRACE_GET_SYSCALL_INFO 0x420e > > +#define LINUX_PTRACE_EVENT_EXEC 4 > #define LINUX_PTRACE_EVENT_EXIT 6 > > #define LINUX_PTRACE_O_TRACESYSGOOD 1 > @@ -151,8 +152,12 @@ linux_ptrace_status(struct thread *td, pid_t pid, int status) > lwpinfo.pl_flags & PL_FLAG_SCE) > status |= (LINUX_SIGTRAP | 0x80) << 8; > if ((pem->ptrace_flags & LINUX_PTRACE_O_TRACESYSGOOD) && > - lwpinfo.pl_flags & PL_FLAG_SCX) > - status |= (LINUX_SIGTRAP | 0x80) << 8; > + lwpinfo.pl_flags & PL_FLAG_SCX) { > + if (lwpinfo.pl_flags & PL_FLAG_EXEC) > + status |= (LINUX_SIGTRAP | LINUX_PTRACE_EVENT_EXEC << 8) << 8; > + else > + status |= (LINUX_SIGTRAP | 0x80) << 8; > + } > if ((pem->ptrace_flags & LINUX_PTRACE_O_TRACEEXIT) && > lwpinfo.pl_flags & PL_FLAG_EXITED) > status |= (LINUX_SIGTRAP | LINUX_PTRACE_EVENT_EXIT << 8) << 8; > diff --git a/sys/kern/subr_syscall.c b/sys/kern/subr_syscall.c > index ada2053bc87c..fab67a68b0a3 100644 > --- a/sys/kern/subr_syscall.c > +++ b/sys/kern/subr_syscall.c > @@ -254,6 +254,18 @@ syscallret(struct thread *td) > if (__predict_false(traced || > (td->td_dbgflags & (TDB_EXEC | TDB_FORK)) != 0)) { > PROC_LOCK(p); > + /* > + * Linux debuggers expect an additional stop for exec, > + * between the usual syscall entry and exit. Raise > + * the exec event now and then clear TDB_EXEC so that > + * the next stop is reported as a syscall exit by > + * linux_ptrace_status(). > + */ > + if ((td->td_dbgflags & TDB_EXEC) != 0 && > + SV_PROC_ABI(td->td_proc) == SV_ABI_LINUX) { > + ptracestop(td, SIGTRAP, NULL); > + td->td_dbgflags &= ~TDB_EXEC; > + } > /* > * If tracing the execed process, trap to the debugger > * so that breakpoints can be set before the program You committed before we finished the discussion. In fact I do not think it is right. Now it generates spurious stop for FreeBSD native debugger, and probably de-synchronize SCX/SCE pairing for it as well. In other words, you need to generate this stop based on ABI of the debugger, not debuggeeeeee.