Commit c2af9f1
internal/runtime/cgroup: fix path on non-root mount point
We should trim the mount root (4th field in /proc/self/mountinfo) from
cgroup path read from /proc/self/cgroup before appending it to the mount
point. Non-root mount points are very common in containers with cgroup
v1.
parseCPURelativePath is renamed to parseCPUCgroup, as it is unclear what
it is relative to. cgroups(7) says "This pathname is relative to the
mount point of the hierarchy." It should mean the root of the hierarchy,
and we cannot concat it to arbirary cgroup mount point. So just use the
word cgroup, since it parses /proc/self/cgroup.
It now returns errMalformedFile if the cgroup pathname does not start
with "/", and errPathTooLong if the pathname can't fit into the buffer.
We already rely on this when composing the path, just make this explicit
to avoid incorrect paths.
We now parse cgroup first then parse the mount point accordingly. We
consider the previously read cgroup pathname and version to ensure we
got the desired mount point. The out buffer is reused to pass in the
cgroup, to avoid extra memory allocation.
This should also resolve the race mentioned in the comments, so removing
those comments. If our cgroup changed between the two read syscalls, we
will stick with the cgroup read from /proc/self/cgroup. This is the same
behavior as cgroup change after FindCPU() returns, so nothing special to
comment about now.
parseCPUMount now returns error when the combined path is too long, to
avoid panic or truncation if we got a really long path from mountinfo.
cgrouptest is changed to use dev returned from stat() to detect
filesystem boundary, since we don't return mount point and sub-path
separately now. This also avoid using os.Root since we don't handle
untrusted input here. os.Root is too complex, and the performance is
bad.
Fixes #76390
Change-Id: Ia9cbd7be3e58a2d51caf27a973fbd201dac06afc
Reviewed-on: https://go-review.googlesource.com/c/go/+/723241
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>1 parent 6be5de4 commit c2af9f1
File tree
5 files changed
+421
-153
lines changed- src/internal
- cgrouptest
- runtime/cgroup
5 files changed
+421
-153
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
55 | | - | |
| 53 | + | |
| 54 | + | |
56 | 55 | | |
57 | 56 | | |
58 | 57 | | |
| |||
93 | 92 | | |
94 | 93 | | |
95 | 94 | | |
96 | | - | |
97 | | - | |
98 | | - | |
| 95 | + | |
| 96 | + | |
99 | 97 | | |
100 | 98 | | |
101 | 99 | | |
102 | 100 | | |
103 | 101 | | |
104 | | - | |
| 102 | + | |
105 | 103 | | |
106 | 104 | | |
107 | 105 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | 106 | | |
115 | 107 | | |
116 | 108 | | |
117 | | - | |
118 | | - | |
119 | | - | |
| 109 | + | |
120 | 110 | | |
121 | 111 | | |
122 | 112 | | |
123 | | - | |
| 113 | + | |
124 | 114 | | |
125 | 115 | | |
126 | 116 | | |
| |||
142 | 132 | | |
143 | 133 | | |
144 | 134 | | |
145 | | - | |
| 135 | + | |
146 | 136 | | |
147 | 137 | | |
148 | 138 | | |
| |||
166 | 156 | | |
167 | 157 | | |
168 | 158 | | |
169 | | - | |
| 159 | + | |
| 160 | + | |
170 | 161 | | |
171 | | - | |
| 162 | + | |
172 | 163 | | |
173 | 164 | | |
174 | 165 | | |
175 | 166 | | |
176 | | - | |
177 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
178 | 171 | | |
179 | 172 | | |
180 | 173 | | |
181 | 174 | | |
182 | | - | |
183 | | - | |
184 | | - | |
| 175 | + | |
| 176 | + | |
185 | 177 | | |
186 | 178 | | |
187 | 179 | | |
188 | | - | |
189 | | - | |
| 180 | + | |
| 181 | + | |
190 | 182 | | |
191 | 183 | | |
192 | 184 | | |
193 | 185 | | |
194 | 186 | | |
195 | 187 | | |
196 | 188 | | |
197 | | - | |
| 189 | + | |
198 | 190 | | |
199 | 191 | | |
200 | 192 | | |
| |||
0 commit comments