From owner-svn-src-head@freebsd.org Tue May 14 20:59:45 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7D16515989DD; Tue, 14 May 2019 20:59:45 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2411F84565; Tue, 14 May 2019 20:59:45 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EEEAF2650C; Tue, 14 May 2019 20:59:44 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x4EKxi4O084787; Tue, 14 May 2019 20:59:44 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x4EKxieO084786; Tue, 14 May 2019 20:59:44 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201905142059.x4EKxieO084786@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Tue, 14 May 2019 20:59:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r347580 - head/sys/amd64/linux X-SVN-Group: head X-SVN-Commit-Author: trasz X-SVN-Commit-Paths: head/sys/amd64/linux X-SVN-Commit-Revision: 347580 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 2411F84565 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.956,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 May 2019 20:59:45 -0000 Author: trasz Date: Tue May 14 20:59:44 2019 New Revision: 347580 URL: https://svnweb.freebsd.org/changeset/base/347580 Log: Fix handling of r10 in Linux ptrace(2). This fixes decoding of the 'flags' argument to mmap(2) with Linux strace(1). Reviewed by: dchagin MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D20223 Modified: head/sys/amd64/linux/linux_ptrace.c Modified: head/sys/amd64/linux/linux_ptrace.c ============================================================================== --- head/sys/amd64/linux/linux_ptrace.c Tue May 14 20:41:24 2019 (r347579) +++ head/sys/amd64/linux/linux_ptrace.c Tue May 14 20:59:44 2019 (r347580) @@ -338,18 +338,27 @@ linux_ptrace_getregs(struct thread *td, pid_t pid, voi map_regs_to_linux(&b_reg, &l_reg); - /* - * The strace(1) utility depends on RAX being set to -ENOSYS - * on syscall entry. - */ error = kern_ptrace(td, PT_LWPINFO, pid, &lwpinfo, sizeof(lwpinfo)); if (error != 0) { printf("%s: PT_LWPINFO failed with error %d\n", __func__, error); return (error); } - if (lwpinfo.pl_flags & PL_FLAG_SCE) - l_reg.rax = -38; // XXX: Don't hardcode? + if (lwpinfo.pl_flags & PL_FLAG_SCE) { + /* + * The strace(1) utility depends on RAX being set to -ENOSYS + * on syscall entry; otherwise it loops printing those: + * + * [ Process PID=928 runs in 64 bit mode. ] + * [ Process PID=928 runs in x32 mode. ] + */ + l_reg.rax = -38; /* -ENOSYS */ + /* + * Undo the mangling done in exception.S:fast_syscall_common(). + */ + l_reg.r10 = l_reg.rcx; + } + error = copyout(&l_reg, (void *)data, sizeof(l_reg)); return (error); } @@ -399,21 +408,27 @@ linux_ptrace_getregset_prstatus(struct thread *td, pid map_regs_to_linux_regset(&b_reg, fsbase, gsbase, &l_regset); - /* - * The strace(1) utility depends on RAX being set to -ENOSYS - * on syscall entry; otherwise it loops printing those: - * - * [ Process PID=928 runs in 64 bit mode. ] - * [ Process PID=928 runs in x32 mode. ] - */ error = kern_ptrace(td, PT_LWPINFO, pid, &lwpinfo, sizeof(lwpinfo)); if (error != 0) { printf("%s: PT_LWPINFO failed with error %d\n", __func__, error); return (error); } - if (lwpinfo.pl_flags & PL_FLAG_SCE) - l_regset.rax = -38; // XXX: Don't hardcode? + if (lwpinfo.pl_flags & PL_FLAG_SCE) { + /* + * The strace(1) utility depends on RAX being set to -ENOSYS + * on syscall entry; otherwise it loops printing those: + * + * [ Process PID=928 runs in 64 bit mode. ] + * [ Process PID=928 runs in x32 mode. ] + */ + l_regset.rax = -38; /* -ENOSYS */ + + /* + * Undo the mangling done in exception.S:fast_syscall_common(). + */ + l_regset.r10 = l_regset.rcx; + } len = MIN(iov.iov_len, sizeof(l_regset)); error = copyout(&l_regset, (void *)iov.iov_base, len);