[PATCH 4/9] setpriv: dump no-new-privs info

Patrick Steinhardt ps at pks.im
Thu Jun 29 17:34:31 UTC 2017


Introduce the ability to dump the state of the no-new-privs flag, which
states whethere it is allowed to grant new privileges.
---
 util-linux/setpriv.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/util-linux/setpriv.c b/util-linux/setpriv.c
index ca31c0a77..c7be492a2 100644
--- a/util-linux/setpriv.c
+++ b/util-linux/setpriv.c
@@ -53,6 +53,10 @@
 #define PR_SET_NO_NEW_PRIVS 38
 #endif
 
+#ifndef PR_GET_NO_NEW_PRIVS
+#define PR_GET_NO_NEW_PRIVS 39
+#endif
+
 enum {
 	OPT_DUMP = (1 << 0),
 	OPT_NNP  = (1 << 1),
@@ -63,7 +67,7 @@ static int dump(void)
 	uid_t ruid, euid, suid;
 	gid_t rgid, egid, sgid;
 	gid_t *gids;
-	int ngids;
+	int ngids, nnp;
 
 	if (getresuid(&ruid, &euid, &suid) < 0)
 		bb_simple_perror_msg_and_die("getresgid");
@@ -77,6 +81,9 @@ static int dump(void)
 	if ((ngids = getgroups(ngids, gids)) < 0)
 		bb_simple_perror_msg_and_die("getgroups");
 
+	if ((nnp = prctl(PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0)) < 0)
+		bb_simple_perror_msg_and_die("prctl: GET_NO_NEW_PRIVS");
+
 	printf("uid: %d\n", ruid);
 	printf("euid: %d\n", euid);
 	printf("gid: %d\n", rgid);
@@ -95,6 +102,8 @@ static int dump(void)
 	}
 	putchar('\n');
 
+	printf("no_new_privs: %d\n", nnp);
+
 	free(gids);
 	return 0;
 }
-- 
2.13.2



More information about the busybox mailing list