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

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