Blame SOURCES/oddjob-cve-2020-10737-reversal-option.patch

c509f8
From 71b0389fbb31833d827f5f0fec18880c2f602753 Mon Sep 17 00:00:00 2001
c509f8
From: Alexander Bokovoy <abokovoy@redhat.com>
c509f8
Date: Thu, 19 May 2022 13:52:22 +0300
c509f8
Subject: [PATCH] mkhomedir: add support for pre-CVE-2020-10737 behavior
c509f8
c509f8
Pre-CVE-2020-10737 behavior was used to allow creating home directories
c509f8
on NFS mounts when non-Kerberos authentication method is in use. This is
c509f8
exactly the case where a race condition addressed by the CVE-2020-10737
c509f8
fix could have happened. However, there are legit use cases where this
c509f8
setup is needed.
c509f8
c509f8
Add '-f' option to mkhomedir helper to activate previous behavior. In
c509f8
order to enable it, a change to oddjobd-mkhomedir.conf configuration
c509f8
file is needed by explicitly adding '-f' option to the executable file
c509f8
definition.
c509f8
c509f8
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2050079
c509f8
c509f8
Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
c509f8
---
c509f8
 src/mkhomedir.c                 | 16 +++++++++++++---
c509f8
 src/oddjobd-mkhomedir.conf.5.in |  9 +++++++++
c509f8
 2 files changed, 22 insertions(+), 3 deletions(-)
c509f8
c509f8
diff --git a/src/mkhomedir.c b/src/mkhomedir.c
c509f8
index be85959..ac813a9 100644
c509f8
--- a/src/mkhomedir.c
c509f8
+++ b/src/mkhomedir.c
c509f8
@@ -53,9 +53,11 @@ static const char *skel;
c509f8
 static const char *skel_dir;
c509f8
 static struct passwd *pwd;
c509f8
 static mode_t override_umask;
c509f8
+static int owner_mkdir_first = 0;
c509f8
 
c509f8
 #define FLAG_POPULATE	(1 << 0)
c509f8
 #define FLAG_QUIET	(1 << 1)
c509f8
+#define FLAG_OWNER_MKDIR_FIRST (1 << 2)
c509f8
 
c509f8
 /* Given the path of an item somewhere in the skeleton directory, create as
c509f8
  * identical as possible a copy in the destination tree. */
c509f8
@@ -158,7 +160,7 @@ copy_single_item(const char *source, const struct stat *sb,
c509f8
 		 * target user just yet to avoid potential race conditions
c509f8
 		 * involving symlink attacks when we copy over the skeleton
c509f8
 		 * tree. */
c509f8
-		if (status->level == 0) {
c509f8
+		if (status->level == 0 && !owner_mkdir_first) {
c509f8
 			uid = 0;
c509f8
 			gid = 0;
c509f8
 		}
c509f8
@@ -222,6 +224,9 @@ mkhomedir(const char *user, int flags)
c509f8
 		       pwd->pw_dir);
c509f8
 		return HANDLER_INVALID_INVOCATION;
c509f8
 	}
c509f8
+	if (flags & FLAG_OWNER_MKDIR_FIRST) {
c509f8
+		owner_mkdir_first = 1;
c509f8
+	}
c509f8
 	if ((lstat(pwd->pw_dir, &st) == -1) && (errno == ENOENT)) {
c509f8
 		/* Figure out which location we're using as a
c509f8
 		 * template. */
c509f8
@@ -237,7 +242,7 @@ mkhomedir(const char *user, int flags)
c509f8
 				int res = nftw(get_skel_dir(), copy_single_item, 5,
c509f8
 					       FTW_PHYS);
c509f8
 				/* only now give ownership to the target user */
c509f8
-				if (res == 0) {
c509f8
+				if (res == 0 && !owner_mkdir_first) {
c509f8
 					res = chown(pwd->pw_dir, pwd->pw_uid, pwd->pw_gid);
c509f8
 				}
c509f8
 
c509f8
@@ -317,8 +322,11 @@ main(int argc, char **argv)
c509f8
 	umask(override_umask);
c509f8
 	skel_dir = "/etc/skel";
c509f8
 
c509f8
-	while ((i = getopt(argc, argv, "nqs:u:")) != -1) {
c509f8
+	while ((i = getopt(argc, argv, "nqfs:u:")) != -1) {
c509f8
 		switch (i) {
c509f8
+		case 'f':
c509f8
+			flags |= FLAG_OWNER_MKDIR_FIRST;
c509f8
+			break;
c509f8
 		case 'n':
c509f8
 			flags &= ~FLAG_POPULATE;
c509f8
 			break;
c509f8
@@ -339,6 +347,8 @@ main(int argc, char **argv)
c509f8
 			break;
c509f8
 		default:
c509f8
 			fprintf(stderr, "Valid options:\n"
c509f8
+				"-f\tCreate home directory initially owned by user, "
c509f8
+				"not root. See man page for security issues.\n"
c509f8
 				"-n\tDo not populate home directories, "
c509f8
 				"just create them.\n"
c509f8
 				"-q\tDo not print messages when creating "
c509f8
diff --git a/src/oddjobd-mkhomedir.conf.5.in b/src/oddjobd-mkhomedir.conf.5.in
c509f8
index d7a2429..6e35ad5 100644
c509f8
--- a/src/oddjobd-mkhomedir.conf.5.in
c509f8
+++ b/src/oddjobd-mkhomedir.conf.5.in
c509f8
@@ -10,6 +10,15 @@ directory.
c509f8
 
c509f8
 The mkhomedir helper itself accepts these options:
c509f8
 .TP
c509f8
+-f
c509f8
+Restore behavior before CVE-2020-10737 was fixed: create the home directory
c509f8
+with user's ownership directly rather than create it as a root and only after
c509f8
+populating it change to the user's ownership. The former behavior is insecure
c509f8
+but may be used to allow creation of NFS-mounted home directories when
c509f8
+non-Kerberos authentication is in use. It is prone for a race condition that
c509f8
+could be exploited in the NFS-mounted home directories use case. To avoid
c509f8
+CVE-2020-10737, do not use \fB-f\fR option in production environments.
c509f8
+.TP
c509f8
 -q
c509f8
 Refrain from outputting the usual "Creating home directory..." message when it
c509f8
 creates a home directory.
c509f8
-- 
c509f8
2.37.1
c509f8