Blame SOURCES/1360898-mpo-7.3.2-prctl.2-capabilities.7.patch

1bb262
From 7a536207483e677f1075e529cbd396dd649b2cdc Mon Sep 17 00:00:00 2001
1bb262
From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nforro@redhat.com>
1bb262
Date: Wed, 3 Aug 2016 12:58:59 +0200
1bb262
Subject: [PATCH] prctl.2, capabilities.7: document ambient capabilities
1bb262
1bb262
---
1bb262
 man-pages/man2/prctl.2        | 77 +++++++++++++++++++++++++++++++++++++++++++
1bb262
 man-pages/man7/capabilities.7 | 51 ++++++++++++++++++++++++----
1bb262
 2 files changed, 122 insertions(+), 6 deletions(-)
1bb262
1bb262
diff --git a/man-pages/man2/prctl.2 b/man-pages/man2/prctl.2
1bb262
index 92eecf9..cd6daef 100644
1bb262
--- a/man-pages/man2/prctl.2
1bb262
+++ b/man-pages/man2/prctl.2
1bb262
@@ -844,6 +844,42 @@ had been called.
1bb262
 For further information on Intel MPX, see the kernel source file
1bb262
 .IR Documentation/x86/intel_mpx.txt .
1bb262
 .\"
1bb262
+.TP
1bb262
+.BR PR_CAP_AMBIENT " (since Linux 4.3)"
1bb262
+.\" commit 58319057b7847667f0c9585b9de0e8932b0fdb08
1bb262
+Reads or changes the ambient capability set, according to the value of
1bb262
+.IR arg2 ,
1bb262
+which must be one of the following:
1bb262
+.RS
1bb262
+.TP
1bb262
+.B PR_CAP_AMBIENT_RAISE
1bb262
+The capability specified in
1bb262
+.I arg3
1bb262
+is added to the ambient set.
1bb262
+The specified capability must already be present in
1bb262
+both the permitted and the inheritable sets of the process.
1bb262
+This operation is not permitted if the
1bb262
+.B SECBIT_NO_CAP_AMBIENT_RAISE
1bb262
+securebit is set.
1bb262
+.TP
1bb262
+.B PR_CAP_AMBIENT_LOWER
1bb262
+The capability specified in
1bb262
+.I arg3
1bb262
+is removed from the ambient set.
1bb262
+.TP
1bb262
+.B PR_CAP_AMBIENT_IS_SET
1bb262
+The
1bb262
+.BR prctl (2)
1bb262
+call returns 1 if the capability in
1bb262
+.I arg3
1bb262
+is in the ambient set and 0 if it is not.
1bb262
+.TP
1bb262
+.BR PR_CAP_AMBIENT_CLEAR_ALL
1bb262
+All capabilities will be removed from the ambient set.
1bb262
+This operation requires setting
1bb262
+.I arg3
1bb262
+to zero.
1bb262
+.RE
1bb262
 .SH RETURN VALUE
1bb262
 On success,
1bb262
 .BR PR_GET_DUMPABLE ,
1bb262
@@ -853,6 +889,7 @@ On success,
1bb262
 .BR PR_GET_TIMING ,
1bb262
 .BR PR_GET_SECUREBITS ,
1bb262
 .BR PR_MCE_KILL_GET ,
1bb262
+.BR PR_CAP_AMBIENT + PR_CAP_AMBIENT_IS_SET ,
1bb262
 and (if it returns)
1bb262
 .BR PR_GET_SECCOMP
1bb262
 return the nonnegative values described above.
1bb262
@@ -949,6 +986,31 @@ is not 0,
1bb262
 .BR PR_SET_PTRACER_ANY ,
1bb262
 or the PID of an existing process.
1bb262
 .TP
1bb262
+.B EINVAL
1bb262
+.I option
1bb262
+is
1bb262
+.B PR_CAP_AMBIENT
1bb262
+and an unused argument
1bb262
+.RI ( arg4 ,
1bb262
+.IR arg5 ,
1bb262
+or, 
1bb262
+in the case of
1bb262
+.BR PR_CAP_AMBIENT_CLEAR_ALL ,
1bb262
+.IR arg3 )
1bb262
+is nonzero; or
1bb262
+.IR arg2
1bb262
+has an invalid value;
1bb262
+or
1bb262
+.IR arg2
1bb262
+is
1bb262
+.BR PR_CAP_AMBIENT_LOWER ,
1bb262
+.BR PR_CAP_AMBIENT_RAISE ,
1bb262
+or
1bb262
+.BR PR_CAP_AMBIENT_IS_SET
1bb262
+and
1bb262
+.IR arg3
1bb262
+does not specify a valid capability.
1bb262
+.TP
1bb262
 .B EPERM
1bb262
 .I option
1bb262
 is
1bb262
@@ -1030,6 +1092,21 @@ capability.
1bb262
 .\" .BR PR_SET_SECCOMP ,
1bb262
 .\" and secure computing mode is already 1.
1bb262
 .TP
1bb262
+.B EPERM
1bb262
+.IR option
1bb262
+is
1bb262
+.BR PR_CAP_AMBIENT
1bb262
+and
1bb262
+.IR arg2
1bb262
+is
1bb262
+.BR PR_CAP_AMBIENT_RAISE ,
1bb262
+but either the capability specified in
1bb262
+.IR arg3
1bb262
+is not present in the process's permitted and inheritable capability sets,
1bb262
+or the
1bb262
+.B PR_CAP_AMBIENT_LOWER
1bb262
+securebit has been set.
1bb262
+.TP
1bb262
 .B ENXIO
1bb262
 .I option
1bb262
 was
1bb262
diff --git a/man-pages/man7/capabilities.7 b/man-pages/man7/capabilities.7
1bb262
index 2c3377e..c340245 100644
1bb262
--- a/man-pages/man7/capabilities.7
1bb262
+++ b/man-pages/man7/capabilities.7
1bb262
@@ -659,13 +659,40 @@ a program whose associated file capabilities grant that capability).
1bb262
 .IR Inheritable :
1bb262
 This is a set of capabilities preserved across an
1bb262
 .BR execve (2).
1bb262
-It provides a mechanism for a process to assign capabilities
1bb262
-to the permitted set of the new program during an
1bb262
-.BR execve (2).
1bb262
+Inheritable capabilities remain inheritable when executing any program,
1bb262
+and inheritable capabilities are added to the permitted set when executing
1bb262
+a program that has the corresponding bits set in the file inheritable set.
1bb262
+.IP
1bb262
+Because inheritable capabilities are not generally preserved across
1bb262
+.BR execve (2)
1bb262
+when running as a non-root user, applications that wish to run helper
1bb262
+programs with elevated capabilities should consider using
1bb262
+ambient capabilities, described below.
1bb262
 .TP
1bb262
 .IR Effective :
1bb262
 This is the set of capabilities used by the kernel to
1bb262
 perform permission checks for the thread.
1bb262
+.TP
1bb262
+.IR Ambient " (since Linux 4.3):"
1bb262
+.\" commit 58319057b7847667f0c9585b9de0e8932b0fdb08
1bb262
+This is a set of capabilities that are preserved across an
1bb262
+.BR execve (2)
1bb262
+of a program that is not privileged.
1bb262
+The ambient capability set obeys the invariant that no capability
1bb262
+can ever be ambient if it is not both permitted and inheritable.
1bb262
+
1bb262
+The ambient capability set can be directly modified using
1bb262
+.BR prctl (2).
1bb262
+Ambient capabilities are automatically lowered if either of
1bb262
+the corresponding permitted or inheritable capabilities is lowered.
1bb262
+
1bb262
+Executing a program that changes UID or GID due to the
1bb262
+set-user-ID or set-group-ID bits or executing a program that has
1bb262
+any file capabilities set will clear the ambient set.
1bb262
+Ambient capabilities are added to the permitted set and
1bb262
+assigned to the effective set when
1bb262
+.BR execve (2)
1bb262
+is called.
1bb262
 .PP
1bb262
 A child created via
1bb262
 .BR fork (2)
1bb262
@@ -747,10 +774,12 @@ the process using the following algorithm:
1bb262
 .in +4n
1bb262
 .nf
1bb262
 
1bb262
+P'(ambient) = (file is privileged) ? 0 : P(ambient)
1bb262
+
1bb262
 P'(permitted) = (P(inheritable) & F(inheritable)) |
1bb262
-                (F(permitted) & cap_bset)
1bb262
+                (F(permitted) & cap_bset) | P'(ambient)
1bb262
 
1bb262
-P'(effective) = F(effective) ? P'(permitted) : 0
1bb262
+P'(effective) = F(effective) ? P'(permitted) : P'(ambient)
1bb262
 
1bb262
 P'(inheritable) = P(inheritable)    [i.e., unchanged]
1bb262
 
1bb262
@@ -769,6 +798,9 @@ denotes a file capability set
1bb262
 .IP cap_bset
1bb262
 is the value of the capability bounding set (described below).
1bb262
 .RE
1bb262
+.PP
1bb262
+A privileged file is one that has capabilities or
1bb262
+has the set-user-ID or set-group-ID bit set.
1bb262
 .\"
1bb262
 .SS Capabilities and execution of programs by root
1bb262
 In order to provide an all-powerful
1bb262
@@ -1029,6 +1061,12 @@ an effective or real UID of 0 calls
1bb262
 .BR execve (2).
1bb262
 (See the subsection
1bb262
 .IR "Capabilities and execution of programs by root" .)
1bb262
+.TP
1bb262
+.B SECBIT_NO_CAP_AMBIENT_RAISE
1bb262
+Setting this flag disallows raising ambient capabilities via the
1bb262
+.BR prctl (2)
1bb262
+.BR PR_CAP_AMBIENT_RAISE
1bb262
+operation.
1bb262
 .PP
1bb262
 Each of the above "base" flags has a companion "locked" flag.
1bb262
 Setting any of the "locked" flags is irreversible,
1bb262
@@ -1037,8 +1075,9 @@ corresponding "base" flag.
1bb262
 The locked flags are:
1bb262
 .BR SECBIT_KEEP_CAPS_LOCKED ,
1bb262
 .BR SECBIT_NO_SETUID_FIXUP_LOCKED ,
1bb262
+.BR SECBIT_NOROOT_LOCKED ,
1bb262
 and
1bb262
-.BR SECBIT_NOROOT_LOCKED .
1bb262
+.BR SECBIT_NO_CAP_AMBIENT_RAISE .
1bb262
 .PP
1bb262
 The
1bb262
 .I securebits
1bb262
-- 
1bb262
2.7.4
1bb262