Browse code

patch: Fix for CVE-2019-13636, CVE-2019-13638

Change-Id: Idbdf20d3228746016ce43fbfb238b3f53fa44c21
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/7726
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Anish Swaminathan <anishs@vmware.com>

Shreenidhi Shedi authored on 2019/08/08 16:16:10
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,108 @@
0
+From dce4683cbbe107a95f1f0d45fabc304acfb5d71a Mon Sep 17 00:00:00 2001
1
+From: Andreas Gruenbacher <agruen@gnu.org>
2
+Date: Mon, 15 Jul 2019 16:21:48 +0200
3
+Subject: Don't follow symlinks unless --follow-symlinks is given
4
+
5
+* src/inp.c (plan_a, plan_b), src/util.c (copy_to_fd, copy_file,
6
+append_to_file): Unless the --follow-symlinks option is given, open files with
7
+the O_NOFOLLOW flag to avoid following symlinks.  So far, we were only doing
8
+that consistently for input files.
9
+* src/util.c (create_backup): When creating empty backup files, (re)create them
10
+with O_CREAT | O_EXCL to avoid following symlinks in that case as well.
11
+---
12
+ src/inp.c  | 12 ++++++++++--
13
+ src/util.c | 14 +++++++++++---
14
+ 2 files changed, 21 insertions(+), 5 deletions(-)
15
+
16
+diff --git a/src/inp.c b/src/inp.c
17
+index 32d0919..22d7473 100644
18
+--- a/src/inp.c
19
+@@ -238,8 +238,13 @@ plan_a (char const *filename)
20
+     {
21
+       if (S_ISREG (instat.st_mode))
22
+         {
23
+-	  int ifd = safe_open (filename, O_RDONLY|binary_transput, 0);
24
++	  int flags = O_RDONLY | binary_transput;
25
+ 	  size_t buffered = 0, n;
26
++	  int ifd;
27
++
28
++	  if (! follow_symlinks)
29
++	    flags |= O_NOFOLLOW;
30
++	  ifd = safe_open (filename, flags, 0);
31
+ 	  if (ifd < 0)
32
+ 	    pfatal ("can't open file %s", quotearg (filename));
33
+ 
34
+@@ -340,6 +345,7 @@ plan_a (char const *filename)
35
+ static void
36
+ plan_b (char const *filename)
37
+ {
38
++  int flags = O_RDONLY | binary_transput;
39
+   int ifd;
40
+   FILE *ifp;
41
+   int c;
42
+@@ -353,7 +359,9 @@ plan_b (char const *filename)
43
+ 
44
+   if (instat.st_size == 0)
45
+     filename = NULL_DEVICE;
46
+-  if ((ifd = safe_open (filename, O_RDONLY | binary_transput, 0)) < 0
47
++  if (! follow_symlinks)
48
++    flags |= O_NOFOLLOW;
49
++  if ((ifd = safe_open (filename, flags, 0)) < 0
50
+       || ! (ifp = fdopen (ifd, binary_transput ? "rb" : "r")))
51
+     pfatal ("Can't open file %s", quotearg (filename));
52
+   if (TMPINNAME_needs_removal)
53
+diff --git a/src/util.c b/src/util.c
54
+index 1cc08ba..fb38307 100644
55
+--- a/src/util.c
56
+@@ -388,7 +388,7 @@ create_backup (char const *to, const struct stat *to_st, bool leave_original)
57
+ 
58
+ 	  try_makedirs_errno = ENOENT;
59
+ 	  safe_unlink (bakname);
60
+-	  while ((fd = safe_open (bakname, O_CREAT | O_WRONLY | O_TRUNC, 0666)) < 0)
61
++	  while ((fd = safe_open (bakname, O_CREAT | O_EXCL | O_WRONLY | O_TRUNC, 0666)) < 0)
62
+ 	    {
63
+ 	      if (errno != try_makedirs_errno)
64
+ 		pfatal ("Can't create file %s", quotearg (bakname));
65
+@@ -579,10 +579,13 @@ create_file (char const *file, int open_flags, mode_t mode,
66
+ static void
67
+ copy_to_fd (const char *from, int tofd)
68
+ {
69
++  int from_flags = O_RDONLY | O_BINARY;
70
+   int fromfd;
71
+   ssize_t i;
72
+ 
73
+-  if ((fromfd = safe_open (from, O_RDONLY | O_BINARY, 0)) < 0)
74
++  if (! follow_symlinks)
75
++    from_flags |= O_NOFOLLOW;
76
++  if ((fromfd = safe_open (from, from_flags, 0)) < 0)
77
+     pfatal ("Can't reopen file %s", quotearg (from));
78
+   while ((i = read (fromfd, buf, bufsize)) != 0)
79
+     {
80
+@@ -625,6 +628,8 @@ copy_file (char const *from, char const *to, struct stat *tost,
81
+   else
82
+     {
83
+       assert (S_ISREG (mode));
84
++      if (! follow_symlinks)
85
++	to_flags |= O_NOFOLLOW;
86
+       tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode,
87
+ 			  to_dir_known_to_exist);
88
+       copy_to_fd (from, tofd);
89
+@@ -640,9 +645,12 @@ copy_file (char const *from, char const *to, struct stat *tost,
90
+ void
91
+ append_to_file (char const *from, char const *to)
92
+ {
93
++  int to_flags = O_WRONLY | O_APPEND | O_BINARY;
94
+   int tofd;
95
+ 
96
+-  if ((tofd = safe_open (to, O_WRONLY | O_BINARY | O_APPEND, 0)) < 0)
97
++  if (! follow_symlinks)
98
++    to_flags |= O_NOFOLLOW;
99
++  if ((tofd = safe_open (to, to_flags, 0)) < 0)
100
+     pfatal ("Can't reopen file %s", quotearg (to));
101
+   copy_to_fd (from, tofd);
102
+   if (close (tofd) != 0)
103
+-- 
104
+cgit v1.0-41-gc330
105
+
0 106
new file mode 100644
... ...
@@ -0,0 +1,38 @@
0
+From 3fcd042d26d70856e826a42b5f93dc4854d80bf0 Mon Sep 17 00:00:00 2001
1
+From: Andreas Gruenbacher <agruen@gnu.org>
2
+Date: Fri, 6 Apr 2018 19:36:15 +0200
3
+Subject: Invoke ed directly instead of using the shell
4
+
5
+* src/pch.c (do_ed_script): Invoke ed directly instead of using a shell
6
+command to avoid quoting vulnerabilities.
7
+---
8
+ src/pch.c | 6 ++----
9
+ 1 file changed, 2 insertions(+), 4 deletions(-)
10
+
11
+diff --git a/src/pch.c b/src/pch.c
12
+index 4fd5a05..16e001a 100644
13
+--- a/src/pch.c
14
+@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
15
+ 	    *outname_needs_removal = true;
16
+ 	    copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
17
+ 	  }
18
+-	sprintf (buf, "%s %s%s", editor_program,
19
+-		 verbosity == VERBOSE ? "" : "- ",
20
+-		 outname);
21
+ 	fflush (stdout);
22
+ 
23
+ 	pid = fork();
24
+@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
25
+ 	else if (pid == 0)
26
+ 	  {
27
+ 	    dup2 (tmpfd, 0);
28
+-	    execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
29
++	    assert (outname[0] != '!' && outname[0] != '-');
30
++	    execlp (editor_program, editor_program, "-", outname, (char  *) NULL);
31
+ 	    _exit (2);
32
+ 	  }
33
+ 	else
34
+-- 
35
+cgit v1.0-41-gc330
36
+
... ...
@@ -1,7 +1,7 @@
1 1
 Summary:        Program for modifying or creating files
2 2
 Name:           patch
3 3
 Version:        2.7.6
4
-Release:        3%{?dist}
4
+Release:        4%{?dist}
5 5
 License:        GPLv3+
6 6
 URL:            http://www.gnu.org/software/%{name}
7 7
 Source0:        ftp://ftp.gnu.org/gnu/patch/%{name}-%{version}.tar.gz
... ...
@@ -9,6 +9,8 @@ Source0:        ftp://ftp.gnu.org/gnu/patch/%{name}-%{version}.tar.gz
9 9
 Patch0:		CVE-2018-6951.patch
10 10
 Patch1:		CVE-2018-1000156.patch
11 11
 Patch2:		CVE-2018-6952.patch
12
+patch3:         CVE-2019-13636.patch
13
+Patch4:         CVE-2019-13638.patch
12 14
 Group:          Development/Tools
13 15
 Vendor:         VMware, Inc.
14 16
 Distribution:   Photon
... ...
@@ -23,6 +25,8 @@ file typically created by the diff program.
23 23
 %patch0	-p1
24 24
 %patch1 -p1
25 25
 %patch2 -p1
26
+%patch3 -p1
27
+%patch4 -p1
26 28
 
27 29
 %build
28 30
 %configure --disable-silent-rules
... ...
@@ -41,6 +45,8 @@ make  %{?_smp_mflags} check
41 41
 %{_mandir}/*/*
42 42
 
43 43
 %changelog
44
+*   Thu Aug 08 2019 Shreenidhi Shedi <sshedi@vmware.com> 2.7.6-4
45
+-   Apply patch for CVE-2019-13636, CVE-2019-13638
44 46
 *   Mon Nov 19 2018 Siju Maliakkal <smaliakkal@vmware.com> 2.7.6-3
45 47
 -   Add patches for CVE-2018-6951,CVE-2018-1000156,CVE-2018-6952
46 48
 *   Tue Oct 2 2018 Michelle Wang <michellew@vmware.com> 2.7.6-2