git: 26105b4c13a0 - stable/13 - linux(4): make arch_prctl(2) support GET_CET_STATUS, report unknown codes

From: Edward Tomasz Napierala <trasz_at_FreeBSD.org>
Date: Mon, 21 Feb 2022 13:48:48 UTC
The branch stable/13 has been updated by trasz:

URL: https://cgit.FreeBSD.org/src/commit/?id=26105b4c13a0a810d5120e3a14e9e110b792cbc4

commit 26105b4c13a0a810d5120e3a14e9e110b792cbc4
Author:     Edward Tomasz Napierala <trasz@FreeBSD.org>
AuthorDate: 2021-05-06 08:33:35 +0000
Commit:     Edward Tomasz Napierala <trasz@FreeBSD.org>
CommitDate: 2022-02-21 12:44:26 +0000

    linux(4): make arch_prctl(2) support GET_CET_STATUS, report unknown codes
    
    This is largely a no-op, to make future debugging slightly easier.
    
    Sponsored By:   EPSRC
    Differential Revision:  https://reviews.freebsd.org/D30035
    
    (cherry picked from commit 916f3dba4523d1b2d478538875d45df56b20bcdb)
---
 sys/amd64/linux/linux.h         | 1 +
 sys/amd64/linux/linux_machdep.c | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/sys/amd64/linux/linux.h b/sys/amd64/linux/linux.h
index cf9f5cccb287..dc4986817d11 100644
--- a/sys/amd64/linux/linux.h
+++ b/sys/amd64/linux/linux.h
@@ -431,6 +431,7 @@ struct l_pollfd {
 #define LINUX_ARCH_SET_FS		0x1002
 #define LINUX_ARCH_GET_FS		0x1003
 #define LINUX_ARCH_GET_GS		0x1004
+#define LINUX_ARCH_CET_STATUS		0x3001
 
 #define	linux_copyout_rusage(r, u)	copyout(r, u, sizeof(*r))
 
diff --git a/sys/amd64/linux/linux_machdep.c b/sys/amd64/linux/linux_machdep.c
index 6c9f63b3a21c..c19d80b3b9a7 100644
--- a/sys/amd64/linux/linux_machdep.c
+++ b/sys/amd64/linux/linux_machdep.c
@@ -221,6 +221,7 @@ linux_sigaltstack(struct thread *td, struct linux_sigaltstack_args *uap)
 int
 linux_arch_prctl(struct thread *td, struct linux_arch_prctl_args *args)
 {
+	unsigned long long cet[3];
 	struct pcb *pcb;
 	int error;
 
@@ -254,7 +255,12 @@ linux_arch_prctl(struct thread *td, struct linux_arch_prctl_args *args)
 		error = copyout(&pcb->pcb_gsbase, PTRIN(args->addr),
 		    sizeof(args->addr));
 		break;
+	case LINUX_ARCH_CET_STATUS:
+		memset(cet, 0, sizeof(cet));
+		error = copyout(&cet, PTRIN(args->addr), sizeof(cet));
+		break;
 	default:
+		linux_msg(td, "unsupported arch_prctl code %#x", args->code);
 		error = EINVAL;
 	}
 	return (error);