Browse code

Fix for CVE-2018-7187

Change-Id: Ibb4a3aea56233825722a75a2a44295301b29e58a
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/4965
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Srivatsa S. Bhat <srivatsab@vmware.com>

DheerajSShetty authored on 2018/04/03 13:40:51
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,124 @@
0
+From c941e27e70c3e06e1011d2dd71d72a7a06a9bcbc Mon Sep 17 00:00:00 2001
1
+From: Ian Lance Taylor <iant@golang.org>
2
+Date: Thu, 15 Feb 2018 15:57:13 -0800
3
+Subject: [PATCH] cmd/go: restrict meta imports to valid schemes
4
+
5
+Before this change, when using -insecure, we permitted any meta import
6
+repo root as long as it contained "://". When not using -insecure, we
7
+restrict meta import repo roots to be valid URLs. People may depend on
8
+that somehow, so permit meta import repo roots to be invalid URLs, but
9
+require them to have valid schemes per RFC 3986.
10
+
11
+Fixes #23867
12
+
13
+Change-Id: Iac666dfc75ac321bf8639dda5b0dba7c8840922d
14
+Reviewed-on: https://go-review.googlesource.com/94603
15
+Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
16
+---
17
+ src/cmd/go/internal/get/vcs.go      | 34 +++++++++++++++++++++++++++--
18
+ src/cmd/go/internal/get/vcs_test.go | 43 +++++++++++++++++++++++++++++++++++++
19
+ 2 files changed, 75 insertions(+), 2 deletions(-)
20
+
21
+diff --git a/src/cmd/go/internal/get/vcs.go b/src/cmd/go/internal/get/vcs.go
22
+index ee6b16a1369..dced0ed8db5 100644
23
+--- a/src/cmd/go/internal/get/vcs.go
24
+@@ -809,8 +809,8 @@ func repoRootForImportDynamic(importPath string, security web.SecurityMode) (*re
25
+ 		}
26
+ 	}
27
+ 
28
+-	if !strings.Contains(mmi.RepoRoot, "://") {
29
+-		return nil, fmt.Errorf("%s: invalid repo root %q; no scheme", urlStr, mmi.RepoRoot)
30
++	if err := validateRepoRootScheme(mmi.RepoRoot); err != nil {
31
++		return nil, fmt.Errorf("%s: invalid repo root %q: %v", urlStr, mmi.RepoRoot, err)
32
+ 	}
33
+ 	rr := &repoRoot{
34
+ 		vcs:      vcsByCmd(mmi.VCS),
35
+@@ -824,6 +824,36 @@ func repoRootForImportDynamic(importPath string, security web.SecurityMode) (*re
36
+ 	return rr, nil
37
+ }
38
+ 
39
++// validateRepoRootScheme returns an error if repoRoot does not seem
40
++// to have a valid URL scheme. At this point we permit things that
41
++// aren't valid URLs, although later, if not using -insecure, we will
42
++// restrict repoRoots to be valid URLs. This is only because we've
43
++// historically permitted them, and people may depend on that.
44
++func validateRepoRootScheme(repoRoot string) error {
45
++	end := strings.Index(repoRoot, "://")
46
++	if end <= 0 {
47
++		return errors.New("no scheme")
48
++	}
49
++
50
++	// RFC 3986 section 3.1.
51
++	for i := 0; i < end; i++ {
52
++		c := repoRoot[i]
53
++		switch {
54
++		case 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z':
55
++			// OK.
56
++		case '0' <= c && c <= '9' || c == '+' || c == '-' || c == '.':
57
++			// OK except at start.
58
++			if i == 0 {
59
++				return errors.New("invalid scheme")
60
++			}
61
++		default:
62
++			return errors.New("invalid scheme")
63
++		}
64
++	}
65
++
66
++	return nil
67
++}
68
++
69
+ var fetchGroup singleflight.Group
70
+ var (
71
+ 	fetchCacheMu sync.Mutex
72
+diff --git a/src/cmd/go/internal/get/vcs_test.go b/src/cmd/go/internal/get/vcs_test.go
73
+index 2cb611fabd8..ece78b563ce 100644
74
+--- a/src/cmd/go/internal/get/vcs_test.go
75
+@@ -416,3 +416,46 @@ func TestMatchGoImport(t *testing.T) {
76
+ 		}
77
+ 	}
78
+ }
79
++
80
++func TestValidateRepoRootScheme(t *testing.T) {
81
++	tests := []struct {
82
++		root string
83
++		err  string
84
++	}{
85
++		{
86
++			root: "",
87
++			err:  "no scheme",
88
++		},
89
++		{
90
++			root: "http://",
91
++			err:  "",
92
++		},
93
++		{
94
++			root: "a://",
95
++			err:  "",
96
++		},
97
++		{
98
++			root: "a#://",
99
++			err:  "invalid scheme",
100
++		},
101
++		{
102
++			root: "-config://",
103
++			err:  "invalid scheme",
104
++		},
105
++	}
106
++
107
++	for _, test := range tests {
108
++		err := validateRepoRootScheme(test.root)
109
++		if err == nil {
110
++			if test.err != "" {
111
++				t.Errorf("validateRepoRootScheme(%q) = nil, want %q", test.root, test.err)
112
++			}
113
++		} else if test.err == "" {
114
++			if err != nil {
115
++				t.Errorf("validateRepoRootScheme(%q) = %q, want nil", test.root, test.err)
116
++			}
117
++		} else if err.Error() != test.err {
118
++			t.Errorf("validateRepoRootScheme(%q) = %q, want %q", test.root, err, test.err)
119
++		}
120
++	}
121
++}
... ...
@@ -10,7 +10,7 @@
10 10
 Summary:        Go 
11 11
 Name:           go
12 12
 Version:        1.9.4
13
-Release:        1%{?dist}
13
+Release:        2%{?dist}
14 14
 License:        BSD
15 15
 URL:            https://golang.org
16 16
 Group:          System Environment/Security
... ...
@@ -19,6 +19,7 @@ Distribution:   Photon
19 19
 Source0:        https://dl.google.com/go/%{name}%{version}.src.tar.gz
20 20
 %define sha1    go=12b0ecee83525cd594f4fbf30380d4832e06f189
21 21
 Patch0:         go_imports_fix.patch
22
+Patch1:         CVE-2018-7187.patch 
22 23
 BuildRequires:  mercurial
23 24
 Requires:       mercurial
24 25
 Requires:       glibc
... ...
@@ -29,6 +30,7 @@ Go is an open source programming language that makes it easy to build simple, re
29 29
 %prep
30 30
 %setup -qn %{name}
31 31
 %patch0 -p1
32
+%patch1 -p1
32 33
 
33 34
 %build
34 35
 export GOHOSTOS=linux
... ...
@@ -115,6 +117,8 @@ rm -rf %{buildroot}/*
115 115
 %{_bindir}/*
116 116
 
117 117
 %changelog
118
+*   Mon Apr 02 2018 Dheeraj Shetty <dheerajs@vmware.com> 1.9.4-2
119
+-   Fix for CVE-2018-7187
118 120
 *   Thu Mar 15 2018 Xiaolin Li <xiaolinl@vmware.com> 1.9.4-1
119 121
 -   Update to golang release v1.9.4
120 122
 *   Mon Oct 23 2017 Vinay Kulkarni <kulkarniv@vmware.com> 1.9.1-1