Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 23 Mar 2019 11:51:12 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r345447 - stable/12/usr.bin/proccontrol
Message-ID:  <201903231151.x2NBpCN8031936@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Sat Mar 23 11:51:12 2019
New Revision: 345447
URL: https://svnweb.freebsd.org/changeset/base/345447

Log:
  MFC r345229:
  proccontrol(1): Add kpti control mode.

Modified:
  stable/12/usr.bin/proccontrol/proccontrol.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.bin/proccontrol/proccontrol.c
==============================================================================
--- stable/12/usr.bin/proccontrol/proccontrol.c	Sat Mar 23 11:47:13 2019	(r345446)
+++ stable/12/usr.bin/proccontrol/proccontrol.c	Sat Mar 23 11:51:12 2019	(r345447)
@@ -43,6 +43,9 @@ enum {
 	MODE_INVALID,
 	MODE_TRACE,
 	MODE_TRAPCAP,
+#ifdef PROC_KPTI_CTL
+	MODE_KPTI,
+#endif
 };
 
 static pid_t
@@ -59,11 +62,18 @@ str2pid(const char *str)
 	return (res);
 }
 
+#ifdef PROC_KPTI_CTL
+#define	KPTI_USAGE "|kpti"
+#else
+#define	KPTI_USAGE
+#endif
+
 static void __dead2
 usage(void)
 {
 
-	fprintf(stderr, "Usage: proccontrol -m (aslr|trace|trapcap) [-q] "
+	fprintf(stderr, "Usage: proccontrol -m (aslr|trace|trapcap"
+	    KPTI_USAGE") [-q] "
 	    "[-s (enable|disable)] [-p pid | command]\n");
 	exit(1);
 }
@@ -88,6 +98,10 @@ main(int argc, char *argv[])
 				mode = MODE_TRACE;
 			else if (strcmp(optarg, "trapcap") == 0)
 				mode = MODE_TRAPCAP;
+#ifdef PROC_KPTI_CTL
+			else if (strcmp(optarg, "kpti") == 0)
+				mode = MODE_KPTI;
+#endif
 			else
 				usage();
 			break;
@@ -133,6 +147,11 @@ main(int argc, char *argv[])
 		case MODE_TRAPCAP:
 			error = procctl(P_PID, pid, PROC_TRAPCAP_STATUS, &arg);
 			break;
+#ifdef PROC_KPTI_CTL
+		case MODE_KPTI:
+			error = procctl(P_PID, pid, PROC_KPTI_STATUS, &arg);
+			break;
+#endif
 		default:
 			usage();
 			break;
@@ -175,6 +194,22 @@ main(int argc, char *argv[])
 				break;
 			}
 			break;
+#ifdef PROC_KPTI_CTL
+		case MODE_KPTI:
+			switch (arg & ~PROC_KPTI_STATUS_ACTIVE) {
+			case PROC_KPTI_CTL_ENABLE_ON_EXEC:
+				printf("enabled");
+				break;
+			case PROC_KPTI_CTL_DISABLE_ON_EXEC:
+				printf("disabled");
+				break;
+			}
+			if ((arg & PROC_KPTI_STATUS_ACTIVE) != 0)
+				printf(", active\n");
+			else
+				printf(", not active\n");
+			break;
+#endif
 		}
 	} else {
 		switch (mode) {
@@ -193,6 +228,13 @@ main(int argc, char *argv[])
 			    PROC_TRAPCAP_CTL_DISABLE;
 			error = procctl(P_PID, pid, PROC_TRAPCAP_CTL, &arg);
 			break;
+#ifdef PROC_KPTI_CTL
+		case MODE_KPTI:
+			arg = enable ? PROC_KPTI_CTL_ENABLE_ON_EXEC :
+			    PROC_KPTI_CTL_DISABLE_ON_EXEC;
+			error = procctl(P_PID, pid, PROC_KPTI_CTL, &arg);
+			break;
+#endif
 		default:
 			usage();
 			break;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201903231151.x2NBpCN8031936>