Blame SOURCES/1642394-mpo-7.7.0-execve.2.patch

5a015b
From f16317f50e663ac0343bc96c01496f6b94c6211c Mon Sep 17 00:00:00 2001
5a015b
From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nforro@redhat.com>
5a015b
Date: Mon, 26 Nov 2018 17:10:36 +0100
5a015b
Subject: [PATCH] execve.2: document EAGAIN error
5a015b
MIME-Version: 1.0
5a015b
Content-Type: text/plain; charset=UTF-8
5a015b
Content-Transfer-Encoding: 8bit
5a015b
5a015b
---
5a015b
 man-pages/man2/execve.2 | 78 +++++++++++++++++++++++++++++++++++++++++
5a015b
 1 file changed, 78 insertions(+)
5a015b
5a015b
diff --git a/man-pages/man2/execve.2 b/man-pages/man2/execve.2
5a015b
index 3343372..192b90a 100644
5a015b
--- a/man-pages/man2/execve.2
5a015b
+++ b/man-pages/man2/execve.2
5a015b
@@ -384,6 +384,16 @@ Execute permission is denied for the file or a script or ELF interpreter.
5a015b
 The file system is mounted
5a015b
 .IR noexec .
5a015b
 .TP
5a015b
+.BR EAGAIN " (since Linux 3.1)"
5a015b
+.\" commit 72fa59970f8698023045ab0713d66f3f4f96945c
5a015b
+Having changed its real UID using one of the
5a015b
+.BR set*uid ()
5a015b
+calls, the caller was\(emand is now still\(emabove its
5a015b
+.BR RLIMIT_NPROC
5a015b
+resource limit (see
5a015b
+.BR setrlimit (2)).
5a015b
+For a more detailed explanation of this error, see NOTES.
5a015b
+.TP
5a015b
 .B EFAULT
5a015b
 .I filename
5a015b
 points outside your accessible address space.
5a015b
@@ -530,6 +540,74 @@ command-line arguments and environment variables has changed.
5a015b
 .\" .BR execve ()
5a015b
 .\" that could be exploited for denial of service by a suitably crafted
5a015b
 .\" ELF binary. There are no known problems with 2.0.34 or 2.2.15.
5a015b
+.SS execve() and EAGAIN
5a015b
+A more detailed explanation of the
5a015b
+.BR EAGAIN
5a015b
+error that can occur (since Linux 3.1) when calling
5a015b
+.BR execve ()
5a015b
+is as follows.
5a015b
+
5a015b
+The
5a015b
+.BR EAGAIN
5a015b
+error can occur when a
5a015b
+.I preceding
5a015b
+call to
5a015b
+.BR setuid (2),
5a015b
+.BR setreuid (2),
5a015b
+or
5a015b
+.BR setresuid (2)
5a015b
+caused the real user ID of the process to change,
5a015b
+and that change caused the process to exceed its
5a015b
+.BR RLIMIT_NPROC
5a015b
+resource limit (i.e., the number of processes belonging
5a015b
+to the new real UID exceeds the resource limit).
5a015b
+In Linux 3.0 and earlier, this caused the
5a015b
+.BR set*uid ()
5a015b
+call to fail.
5a015b
+
5a015b
+Since Linux 3.1, the scenario just described no longer causes the
5a015b
+.BR set*uid ()
5a015b
+call to fail,
5a015b
+because it too often led to security holes where buggy applications
5a015b
+didn't check the return status and assumed
5a015b
+that\(emif the caller had root privileges\(emthe call would always succeed.
5a015b
+Instead, the
5a015b
+.BR set*uid ()
5a015b
+calls now successfully change the real UID,
5a015b
+but the kernel sets an internal flag, named
5a015b
+.BR PF_NPROC_EXCEEDED ,
5a015b
+to note that the
5a015b
+.BR RLIMIT_NPROC
5a015b
+resource limit has been exceeded.
5a015b
+If the resource limit is still exceeded at the time of a subsequent
5a015b
+.BR execve ()
5a015b
+call, that call fails with the error
5a015b
+.BR EAGAIN .
5a015b
+This kernel logic ensures that the
5a015b
+.BR RLIMIT_NPROC
5a015b
+resource limit is still enforced for the
5a015b
+common privileged daemon workflow\(emnamely,
5a015b
+.BR fork (2)
5a015b
++
5a015b
+.BR set*uid ()
5a015b
++
5a015b
+.BR execve ().
5a015b
+
5a015b
+If the resource limit was not still exceeded at the time of the
5a015b
+.BR execve ()
5a015b
+call
5a015b
+(because other processes belonging to this real UID terminated between the
5a015b
+.BR set*uid()
5a015b
+call and the
5a015b
+.BR execve ()
5a015b
+call), then the
5a015b
+.BR execve ()
5a015b
+call succeeds and the kernel clears the
5a015b
+.BR PF_NPROC_EXCEEDED
5a015b
+process flag.
5a015b
+The flag is also cleared if a subsequent call to
5a015b
+.BR fork (2)
5a015b
+by this process succeeds.
5a015b
 .SS Historical
5a015b
 With UNIX V6 the argument list of an
5a015b
 .BR exec ()
5a015b
-- 
5a015b
2.17.2
5a015b