summaryrefslogtreecommitdiffstats
path: root/meta/recipes-extended/sudo/files/CVE-2021-23239.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-extended/sudo/files/CVE-2021-23239.patch')
-rw-r--r--meta/recipes-extended/sudo/files/CVE-2021-23239.patch62
1 files changed, 62 insertions, 0 deletions
diff --git a/meta/recipes-extended/sudo/files/CVE-2021-23239.patch b/meta/recipes-extended/sudo/files/CVE-2021-23239.patch
new file mode 100644
index 0000000000..e16baecd5a
--- /dev/null
+++ b/meta/recipes-extended/sudo/files/CVE-2021-23239.patch
@@ -0,0 +1,62 @@
1
2# HG changeset patch
3# User Todd C. Miller <Todd.Miller@sudo.ws>
4# Date 1609953360 25200
5# Node ID ea19d0073c02951bbbf35342dd63304da83edce8
6# Parent f1ca39a0d87089d005b78a2556e2b1a2dc17f672
7Fix potential directory existing info leak in sudoedit.
8When creating a new file, sudoedit checks to make sure the parent
9directory exists so it can provide the user with a sensible error
10message. However, this could be used to test for the existence of
11directories not normally accessible to the user by pointing to them
12with a symbolic link when the parent directory is controlled by the
13user. Problem reported by Matthias Gerstner of SUSE.
14
15Upstream-Status: Backport [https://www.sudo.ws/repos/sudo/rev/ea19d0073c02]
16CVE: CVE-2021-23239
17Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
18
19diff -r f1ca39a0d870 -r ea19d0073c02 src/sudo_edit.c
20--- a/src/sudo_edit.c Wed Jan 06 10:16:00 2021 -0700
21+++ b/src/sudo_edit.c Wed Jan 06 10:16:00 2021 -0700
22@@ -541,14 +541,33 @@
23 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, command_details);
24 if (ofd != -1 || errno == ENOENT) {
25 if (ofd == -1) {
26- /* New file, verify parent dir exists unless in cwd. */
27+ /*
28+ * New file, verify parent dir exists unless in cwd.
29+ * This fails early so the user knows ahead of time if the
30+ * edit won't succeed. Additional checks are performed
31+ * when copying the temporary file back to the origin.
32+ */
33 char *slash = strrchr(files[i], '/');
34 if (slash != NULL && slash != files[i]) {
35- int serrno = errno;
36+ const int sflags = command_details->flags;
37+ const int serrno = errno;
38+ int dfd;
39+
40+ /*
41+ * The parent directory is allowed to be a symbolic
42+ * link as long as *its* parent is not writable.
43+ */
44 *slash = '\0';
45- if (stat(files[i], &sb) == 0 && S_ISDIR(sb.st_mode)) {
46- memset(&sb, 0, sizeof(sb));
47- rc = 0;
48+ SET(command_details->flags, CD_SUDOEDIT_FOLLOW);
49+ dfd = sudo_edit_open(files[i], DIR_OPEN_FLAGS,
50+ S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, command_details);
51+ command_details->flags = sflags;
52+ if (dfd != -1) {
53+ if (fstat(dfd, &sb) == 0 && S_ISDIR(sb.st_mode)) {
54+ memset(&sb, 0, sizeof(sb));
55+ rc = 0;
56+ }
57+ close(dfd);
58 }
59 *slash = '/';
60 errno = serrno;
61
62