git: 6547153e4618 - main - linux: Fix ptrace panic with ERESTART

From: Edward Tomasz Napierala <trasz_at_FreeBSD.org>
Date: Fri, 29 Oct 2021 13:56:15 UTC
The branch main has been updated by trasz:

URL: https://cgit.FreeBSD.org/src/commit/?id=6547153e4618c3b57e5f76062de006a04ecbd64b

commit 6547153e4618c3b57e5f76062de006a04ecbd64b
Author:     Edward Tomasz Napierala <trasz@FreeBSD.org>
AuthorDate: 2021-10-29 13:21:21 +0000
Commit:     Edward Tomasz Napierala <trasz@FreeBSD.org>
CommitDate: 2021-10-29 13:55:59 +0000

    linux: Fix ptrace panic with ERESTART
    
    Translate ERESTART into Linux "internal" errno ERESTARTSYS.
    This fixes the erestartsys.gen.test from strace(1).
    
    Reviewed By:    kib
    Sponsored By:   EPSRC
    Differential Revision:  https://reviews.freebsd.org/D32623
---
 sys/amd64/linux/linux_ptrace.c | 4 ++++
 sys/compat/linux/linux_errno.h | 6 ++++++
 2 files changed, 10 insertions(+)

diff --git a/sys/amd64/linux/linux_ptrace.c b/sys/amd64/linux/linux_ptrace.c
index b7d0838fb054..d16e875ba5cf 100644
--- a/sys/amd64/linux/linux_ptrace.c
+++ b/sys/amd64/linux/linux_ptrace.c
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
 #include <amd64/linux/linux.h>
 #include <amd64/linux/linux_proto.h>
 #include <compat/linux/linux_emul.h>
+#include <compat/linux/linux_errno.h>
 #include <compat/linux/linux_misc.h>
 #include <compat/linux/linux_signal.h>
 #include <compat/linux/linux_util.h>
@@ -639,6 +640,9 @@ linux_ptrace_get_syscall_info(struct thread *td, pid_t pid,
 			 * the ptracing process fall back to another method.
 			 */
 			si.op = LINUX_PTRACE_SYSCALL_INFO_NONE;
+		} else if (sr.sr_error == ERESTART) {
+			si.exit.rval = -LINUX_ERESTARTSYS;
+			si.exit.is_error = 1;
 		} else {
 			si.exit.rval = bsd_to_linux_errno(sr.sr_error);
 			si.exit.is_error = 1;
diff --git a/sys/compat/linux/linux_errno.h b/sys/compat/linux/linux_errno.h
index 46e6f46e202b..0eae6684ce44 100644
--- a/sys/compat/linux/linux_errno.h
+++ b/sys/compat/linux/linux_errno.h
@@ -182,4 +182,10 @@
 
 #define	LINUX_ELAST		LINUX_EHWPOISON
 
+/*
+ * This is a special "internal" errno that must never be returned
+ * to a Linux process, but might be observed via ptrace(2).
+ */
+#define	LINUX_ERESTARTSYS	512
+
 #endif /* _LINUX_ERRNO_H_ */