From nobody Thu May 18 17:02:51 2023 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 4QMbrX2hfBz4Bn61; Thu, 18 May 2023 17:02:52 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QMbrX0kmyz4VRx; Thu, 18 May 2023 17:02:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684429372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5AbGUYN+wAavqCb0kuy0/5u9hs0onxPZEiNERE7USwM=; b=xmmw5dktRNbr7IX+Lr8ixQU0w36Irggqa/OubqF2CVwx4FH4vqIbyKSN/C+hTfpSgWvAB6 nZhkITumLMYK3jCq9f/vmJT3PkPDRVMKoQ6VLyLncxTKe4Wj8g6LQC11nID+VoI3Rcf36t O8S5j6Ov7JOtwAw0W4L3SyFsblxR8T2H8f1eci0akgm1kuW18pWntQgh4wKKNWaAkcbKml VstXOjSkI1y6k/MJ6/7Ki7G+geSTs0My0M+PS8ZgT54cOST/Fi4PjRJrfPfdX8bbTEHlMj /+bJcSwVhg5xJt2t5elcAp91VICvFbzkqyKDSi+bcN3KgPEsCAlgZcKLjauCnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684429372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5AbGUYN+wAavqCb0kuy0/5u9hs0onxPZEiNERE7USwM=; b=iiGnbiIF0S8iK7mWnTToxVBPMMlbsRoVFTkyB8XwY2i/nYS/s39C8E5YReycerjzy5doU4 rXAzKz0htBpEfeSSReUYYY3nNubQZ+ihxDjF48DCaQyLfKa30Ads33BGIAlq82+wOAske0 n4Ce4Isw1j0KBv/ZgF5HWMt74XoRLVZGHo+gQqJZKRF1PwvTdip89rAs3aZP0x58k3OZzo MXxFTcYxMFrS4tjBA2HDeaHaF6a6Rh5vQE1XFYPW0crinoqI904j9n4jai+Lv1jwq1oOiI HxB1mGvQbfSDHSMDpL3Gbu/y918eYZIAA92clTVZSBZQx/zWGQ+XIKo4xapozA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684429372; a=rsa-sha256; cv=none; b=WNfjP1gu+J+FLC5/Vkl1iTlJZ8ArAvDRX07lzc6RWsdTNIfVpZfdd4bsmE4I1iCahBV/Ka 3w5subApKWiuM9ALmwA6wYAFn57ZtV+mDTvm9K3KZ0udKYaEYzaY43tzTHvY68fNhv1VxT 5JJ8k4uPzHvvjAtdF4Dj4MK0YoG9d5u8sBuM5mBhaOd9nGlnQIIMa6+G/zhGAaO/Co5brl WJWPmB8mabZZsfF0EEl7b6KfUVOPqppIu4jX5PolQQpiWCRuBBBPsoSXjB0AVmFJc+UqnL h1EBhTklsB3CVDpVo4399ovLwGAl2yh3AzKnU7ObKNsDMBP0aibIlaK+7tSDcQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QMbrW6wryztvb; Thu, 18 May 2023 17:02:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 34IH2p3K018643; Thu, 18 May 2023 17:02:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34IH2pCi018642; Thu, 18 May 2023 17:02:51 GMT (envelope-from git) Date: Thu, 18 May 2023 17:02:51 GMT Message-Id: <202305181702.34IH2pCi018642@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dmitry Chagin Subject: git: dd2a6cd701ae - main - linux(4): Make ptrace_peekusr machine dependend 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=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: dd2a6cd701aea5a6ced59b9947e087304f7d7238 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=dd2a6cd701aea5a6ced59b9947e087304f7d7238 commit dd2a6cd701aea5a6ced59b9947e087304f7d7238 Author: Dmitry Chagin AuthorDate: 2023-05-18 17:00:12 +0000 Commit: Dmitry Chagin CommitDate: 2023-05-18 17:00:12 +0000 linux(4): Make ptrace_peekusr machine dependend And partially implement it for x86_64. Differential Revision: https://reviews.freebsd.org/D40095 MFC after: 1 week --- sys/amd64/linux/linux.h | 2 ++ sys/amd64/linux/linux_machdep.c | 31 ++++++++++++++++++++++++++ sys/amd64/linux32/linux.h | 2 ++ sys/amd64/linux32/linux32_machdep.c | 9 ++++++++ sys/arm64/linux/linux.h | 2 ++ sys/arm64/linux/linux_machdep.c | 8 +++++++ sys/compat/linux/linux_ptrace.c | 43 ------------------------------------- 7 files changed, 54 insertions(+), 43 deletions(-) diff --git a/sys/amd64/linux/linux.h b/sys/amd64/linux/linux.h index c15381dc1e86..698c560154ec 100644 --- a/sys/amd64/linux/linux.h +++ b/sys/amd64/linux/linux.h @@ -277,6 +277,8 @@ void linux_ptrace_get_syscall_info_machdep(const struct reg *reg, struct syscall_info *si); int linux_ptrace_getregs_machdep(struct thread *td, pid_t pid, struct linux_pt_regset *l_regset); +int linux_ptrace_peekuser(struct thread *td, pid_t pid, + void *addr, void *data); #endif /* _KERNEL */ #endif /* !_AMD64_LINUX_H_ */ diff --git a/sys/amd64/linux/linux_machdep.c b/sys/amd64/linux/linux_machdep.c index 6c96dd496fdc..233d66a40899 100644 --- a/sys/amd64/linux/linux_machdep.c +++ b/sys/amd64/linux/linux_machdep.c @@ -367,3 +367,34 @@ linux_ptrace_getregs_machdep(struct thread *td, pid_t pid, return (0); } + +#define LINUX_URO(a,m) ((uintptr_t)a == offsetof(struct linux_pt_regset, m)) + +int +linux_ptrace_peekuser(struct thread *td, pid_t pid, void *addr, void *data) +{ + struct linux_pt_regset reg; + struct reg b_reg; + uint64_t val; + int error; + + if ((uintptr_t)addr & (sizeof(data) -1) || (uintptr_t)addr < 0) + return (EIO); + if ((uintptr_t)addr >= sizeof(struct linux_pt_regset)) { + LINUX_RATELIMIT_MSG_OPT1("PTRACE_PEEKUSER offset %ld " + "not implemented; returning EINVAL", (uintptr_t)addr); + return (EINVAL); + } + + if (LINUX_URO(addr, fs_base)) + return (kern_ptrace(td, PT_GETFSBASE, pid, data, 0)); + if (LINUX_URO(addr, gs_base)) + return (kern_ptrace(td, PT_GETGSBASE, pid, data, 0)); + if ((error = kern_ptrace(td, PT_GETREGS, pid, &b_reg, 0)) != 0) + return (error); + bsd_to_linux_regset(&b_reg, ®); + val = *(®.r15 + ((uintptr_t)addr / sizeof(reg.r15))); + return (copyout(&val, data, sizeof(val))); +} + +#undef LINUX_URO diff --git a/sys/amd64/linux32/linux.h b/sys/amd64/linux32/linux.h index 652dfccd75f1..23cba6aa2e2c 100644 --- a/sys/amd64/linux32/linux.h +++ b/sys/amd64/linux32/linux.h @@ -431,6 +431,8 @@ struct reg32; void bsd_to_linux_regset32(const struct reg32 *b_reg, struct linux_pt_regset32 *l_regset); +int linux_ptrace_peekuser(struct thread *td, pid_t pid, + void *addr, void *data); extern bool linux32_emulate_i386; #endif /* _KERNEL */ diff --git a/sys/amd64/linux32/linux32_machdep.c b/sys/amd64/linux32/linux32_machdep.c index 0bd398042c3f..afc60fb7e822 100644 --- a/sys/amd64/linux32/linux32_machdep.c +++ b/sys/amd64/linux32/linux32_machdep.c @@ -742,3 +742,12 @@ DEFINE_IFUNC(, int, futex_xorl, (int, uint32_t *, int *)) return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ? futex_xorl_smap : futex_xorl_nosmap); } + +int +linux_ptrace_peekuser(struct thread *td, pid_t pid, void *addr, void *data) +{ + + LINUX_RATELIMIT_MSG_OPT1("PTRACE_PEEKUSER offset %ld not implemented; " + "returning EINVAL", (uintptr_t)addr); + return (EINVAL); +} diff --git a/sys/arm64/linux/linux.h b/sys/arm64/linux/linux.h index 423f1fb0acb8..9ef50bce42a5 100644 --- a/sys/arm64/linux/linux.h +++ b/sys/arm64/linux/linux.h @@ -204,6 +204,8 @@ void linux_ptrace_get_syscall_info_machdep(const struct reg *reg, struct syscall_info *si); int linux_ptrace_getregs_machdep(struct thread *td, pid_t pid, struct linux_pt_regset *l_regset); +int linux_ptrace_peekuser(struct thread *td, pid_t pid, + void *addr, void *data); #endif /* _KERNEL */ #endif /* _ARM64_LINUX_H_ */ diff --git a/sys/arm64/linux/linux_machdep.c b/sys/arm64/linux/linux_machdep.c index 91eea2c6c5e0..2c0445bbed5d 100644 --- a/sys/arm64/linux/linux_machdep.c +++ b/sys/arm64/linux/linux_machdep.c @@ -152,3 +152,11 @@ linux_ptrace_getregs_machdep(struct thread *td __unused, pid_t pid __unused, return (0); } +int +linux_ptrace_peekuser(struct thread *td, pid_t pid, void *addr, void *data) +{ + + LINUX_RATELIMIT_MSG_OPT1("PTRACE_PEEKUSER offset %ld not implemented; " + "returning EINVAL", (uintptr_t)addr); + return (EINVAL); +} diff --git a/sys/compat/linux/linux_ptrace.c b/sys/compat/linux/linux_ptrace.c index 75b616b7258a..bc595ce106dc 100644 --- a/sys/compat/linux/linux_ptrace.c +++ b/sys/compat/linux/linux_ptrace.c @@ -100,11 +100,6 @@ __FBSDID("$FreeBSD$"); #define LINUX_PTRACE_SYSCALL_INFO_ENTRY 1 #define LINUX_PTRACE_SYSCALL_INFO_EXIT 2 -#define LINUX_PTRACE_PEEKUSER_ORIG_RAX 120 -#define LINUX_PTRACE_PEEKUSER_RIP 128 -#define LINUX_PTRACE_PEEKUSER_CS 136 -#define LINUX_PTRACE_PEEKUSER_DS 184 - static int map_signum(int lsig, int *bsigp) { @@ -179,44 +174,6 @@ linux_ptrace_peek(struct thread *td, pid_t pid, void *addr, void *data) return (error); } -static int -linux_ptrace_peekuser(struct thread *td, pid_t pid, void *addr, void *data) -{ - struct reg b_reg; - uint64_t val; - int error; - - error = kern_ptrace(td, PT_GETREGS, pid, &b_reg, 0); - if (error != 0) - return (error); - - switch ((uintptr_t)addr) { -#ifdef __amd64__ - case LINUX_PTRACE_PEEKUSER_ORIG_RAX: - val = b_reg.r_rax; - break; - case LINUX_PTRACE_PEEKUSER_RIP: - val = b_reg.r_rip; - break; - case LINUX_PTRACE_PEEKUSER_CS: - val = b_reg.r_cs; - break; - case LINUX_PTRACE_PEEKUSER_DS: - val = b_reg.r_ds; - break; -#endif /* __amd64__ */ - default: - linux_msg(td, "PTRACE_PEEKUSER offset %ld not implemented; " - "returning EINVAL", (uintptr_t)addr); - return (EINVAL); - } - - error = copyout(&val, data, sizeof(val)); - td->td_retval[0] = error; - - return (error); -} - static int linux_ptrace_pokeuser(struct thread *td, pid_t pid, void *addr, void *data) {