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

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