Debian Codegraph @

CHANGELOG.md

raw
1 # Changelog #
2 All notable changes to this project will be documented in this file.
3
4 The format is based on [Keep a Changelog](http://keepachangelog.com/)
5 and this project adheres to [Semantic Versioning](http://semver.org/).
6
7 ## [Unreleased 0.5.z] ##
8
9 ## [0.5.2] - 2025-11-19 ##
10
11 > "Will you walk into my parlour?" said a spider to a fly.
12
13 ### Fixed ###
14 - Our logic for deciding whether to use `openat2(2)` or fallback to an `O_PATH`
15 resolver would cache the result to avoid doing needless test runs of
16 `openat2(2)`. However, this causes issues when `pathrs-lite` is being used by
17 a program that applies new seccomp-bpf filters onto itself -- if the filter
18 denies `openat2(2)` then we would return that error rather than falling back
19 to the `O_PATH` resolver. To resolve this issue, we no longer cache the
20 result if `openat2(2)` was successful, only if there was an error.
21 - A file descriptor leak in our `openat2` wrapper (when doing the necessary
22 `dup` for `RESOLVE_IN_ROOT`) has been removed.
23
24 ## [0.5.1] - 2025-10-31 ##
25
26 > Spooky scary skeletons send shivers down your spine!
27
28 ### Changed ###
29 - `openat2` can return `-EAGAIN` if it detects a possible attack in certain
30 scenarios (namely if there was a rename or mount while walking a path with a
31 `..` component). While this is necessary to avoid a denial-of-service in the
32 kernel, it does require retry loops in userspace.
33
34 In previous versions, `pathrs-lite` would retry `openat2` 32 times before
35 returning an error, but we've received user reports that this limit can be
36 hit on systems with very heavy load. In some synthetic benchmarks (testing
37 the worst-case of an attacker doing renames in a tight loop on every core of
38 a 16-core machine) we managed to get a ~3% failure rate in runc. We have
39 improved this situation in two ways:
40
41 * We have now increased this limit to 128, which should be good enough for
42 most use-cases without becoming a denial-of-service vector (the number of
43 syscalls called by the `O_PATH` resolver in a typical case is within the
44 same ballpark). The same benchmarks show a failure rate of ~0.12% which
45 (while not zero) is probably sufficient for most users.
46
47 * In addition, we now return a `unix.EAGAIN` error that is bubbled up and can
48 be detected by callers. This means that callers with stricter requirements
49 to avoid spurious errors can choose to do their own infinite `EAGAIN` retry
50 loop (though we would strongly recommend users use time-based deadlines in
51 such retry loops to avoid potentially unbounded denials-of-service).
52
53 ## [0.5.0] - 2025-09-26 ##
54
55 > Let the past die. Kill it if you have to.
56
57 > **NOTE**: With this release, some parts of
58 > `github.com/cyphar/filepath-securejoin` are now licensed under the Mozilla
59 > Public License (version 2). Please see [COPYING.md][] as well as the the
60 > license header in each file for more details.
61
62 [COPYING.md]: ./COPYING.md
63
64 ### Breaking ###
65 - The new API introduced in the [0.3.0][] release has been moved to a new
66 subpackage called `pathrs-lite`. This was primarily done to better indicate
67 the split between the new and old APIs, as well as indicate to users the
68 purpose of this subpackage (it is a less complete version of [libpathrs][]).
69
70 We have added some wrappers to the top-level package to ease the transition,
71 but those are deprecated and will be removed in the next minor release of
72 filepath-securejoin. Users should update their import paths.
73
74 This new subpackage has also been relicensed under the Mozilla Public License
75 (version 2), please see [COPYING.md][] for more details.
76
77 ### Added ###
78 - Most of the key bits the safe `procfs` API have now been exported and are
79 available in `github.com/cyphar/filepath-securejoin/pathrs-lite/procfs`. At
80 the moment this primarily consists of a new `procfs.Handle` API:
81
82 * `OpenProcRoot` returns a new handle to `/proc`, endeavouring to make it
83 safe if possible (`subset=pid` to protect against mistaken write attacks
84 and leaks, as well as using `fsopen(2)` to avoid racing mount attacks).
85
86 `OpenUnsafeProcRoot` returns a handle without attempting to create one
87 with `subset=pid`, which makes it more dangerous to leak. Most users
88 should use `OpenProcRoot` (even if you need to use `ProcRoot` as the base
89 of an operation, as filepath-securejoin will internally open a handle when
90 necessary).
91
92 * The `(*procfs.Handle).Open*` family of methods lets you get a safe
93 `O_PATH` handle to subpaths within `/proc` for certain subpaths.
94
95 For `OpenThreadSelf`, the returned `ProcThreadSelfCloser` needs to be
96 called after you completely finish using the handle (this is necessary
97 because Go is multi-threaded and `ProcThreadSelf` references
98 `/proc/thread-self` which may disappear if we do not
99 `runtime.LockOSThread` -- `ProcThreadSelfCloser` is currently equivalent
100 to `runtime.UnlockOSThread`).
101
102 Note that you cannot open any `procfs` symlinks (most notably magic-links)
103 using this API. At the moment, filepath-securejoin does not support this
104 feature (but [libpathrs][] does).
105
106 * `ProcSelfFdReadlink` lets you get the in-kernel path representation of a
107 file descriptor (think `readlink("/proc/self/fd/...")`), except that we
108 verify that there aren't any tricky overmounts that could fool the
109 process.
110
111 Please be aware that the returned string is simply a snapshot at that
112 particular moment, and an attacker could move the file being pointed to.
113 In addition, complex namespace configurations could result in non-sensical
114 or confusing paths to be returned. The value received from this function
115 should only be used as secondary verification of some security property,
116 not as proof that a particular handle has a particular path.
117
118 The procfs handle used internally by the API is the same as the rest of
119 `filepath-securejoin` (for privileged programs this is usually a private
120 in-process `procfs` instance created with `fsopen(2)`).
121
122 As before, this is intended as a stop-gap before users migrate to
123 [libpathrs][], which provides a far more extensive safe `procfs` API and is
124 generally more robust.
125
126 - Previously, the hardened procfs implementation (used internally within
127 `Reopen` and `Open(at)InRoot`) only protected against overmount attacks on
128 systems with `openat2(2)` (Linux 5.6) or systems with `fsopen(2)` or
129 `open_tree(2)` (Linux 5.2) and programs with privileges to use them (with
130 some caveats about locked mounts that probably affect very few users). For
131 other users, an attacker with the ability to create malicious mounts (on most
132 systems, a sysadmin) could trick you into operating on files you didn't
133 expect. This attack only really makes sense in the context of container
134 runtime implementations.
135
136 This was considered a reasonable trade-off, as the long-term intention was to
137 get all users to just switch to [libpathrs][] if they wanted to use the safe
138 `procfs` API (which had more extensive protections, and is what these new
139 protections in `filepath-securejoin` are based on). However, as the API
140 is now being exported it seems unwise to advertise the API as "safe" if we do
141 not protect against known attacks.
142
143 The procfs API is now more protected against attackers on systems lacking the
144 aforementioned protections. However, the most comprehensive of these
145 protections effectively rely on [`statx(STATX_MNT_ID)`][statx.2] (Linux 5.8).
146 On older kernel versions, there is no effective protection (there is some
147 minimal protection against non-`procfs` filesystem components but a
148 sufficiently clever attacker can work around those). In addition,
149 `STATX_MNT_ID` is vulnerable to mount ID reuse attacks by sufficiently
150 motivated and privileged attackers -- this problem is mitigated with
151 `STATX_MNT_ID_UNIQUE` (Linux 6.8) but that raises the minimum kernel version
152 for more protection.
153
154 The fact that these protections are quite limited despite needing a fair bit
155 of extra code to handle was one of the primary reasons we did not initially
156 implement this in `filepath-securejoin` ([libpathrs][] supports all of this,
157 of course).
158
159 ### Fixed ###
160 - RHEL 8 kernels have backports of `fsopen(2)` but in some testing we've found
161 that it has very bad (and very difficult to debug) performance issues, and so
162 we will explicitly refuse to use `fsopen(2)` if the running kernel version is
163 pre-5.2 and will instead fallback to `open("/proc")`.
164
165 [CVE-2024-21626]: https://github.com/opencontainers/runc/security/advisories/GHSA-xr7r-f8xq-vfvv
166 [libpathrs]: https://github.com/cyphar/libpathrs
167 [statx.2]: https://www.man7.org/linux/man-pages/man2/statx.2.html
168
169 ## [0.4.1] - 2025-01-28 ##
170
171 ### Fixed ###
172 - The restrictions added for `root` paths passed to `SecureJoin` in 0.4.0 was
173 found to be too strict and caused some regressions when folks tried to
174 update, so this restriction has been relaxed to only return an error if the
175 path contains a `..` component. We still recommend users use `filepath.Clean`
176 (and even `filepath.EvalSymlinks`) on the `root` path they are using, but at
177 least you will no longer be punished for "trivial" unclean paths.
178
179 ## [0.4.0] - 2025-01-13 ##
180
181 ### Breaking ####
182 - `SecureJoin(VFS)` will now return an error if the provided `root` is not a
183 `filepath.Clean`'d path.
184
185 While it is ultimately the responsibility of the caller to ensure the root is
186 a safe path to use, passing a path like `/symlink/..` as a root would result
187 in the `SecureJoin`'d path being placed in `/` even though `/symlink/..`
188 might be a different directory, and so we should more strongly discourage
189 such usage.
190
191 All major users of `securejoin.SecureJoin` already ensure that the paths they
192 provide are safe (and this is ultimately a question of user error), but
193 removing this foot-gun is probably a good idea. Of course, this is
194 necessarily a breaking API change (though we expect no real users to be
195 affected by it).
196
197 Thanks to [Erik Sjölund](https://github.com/eriksjolund), who initially
198 reported this issue as a possible security issue.
199
200 - `MkdirAll` and `MkdirHandle` now take an `os.FileMode`-style mode argument
201 instead of a raw `unix.S_*`-style mode argument, which may cause compile-time
202 type errors depending on how you use `filepath-securejoin`. For most users,
203 there will be no change in behaviour aside from the type change (as the
204 bottom `0o777` bits are the same in both formats, and most users are probably
205 only using those bits).
206
207 However, if you were using `unix.S_ISVTX` to set the sticky bit with
208 `MkdirAll(Handle)` you will need to switch to `os.ModeSticky` otherwise you
209 will get a runtime error with this update. In addition, the error message you
210 will get from passing `unix.S_ISUID` and `unix.S_ISGID` will be different as
211 they are treated as invalid bits now (note that previously passing said bits
212 was also an error).
213
214 ## [0.3.6] - 2024-12-17 ##
215
216 ### Compatibility ###
217 - The minimum Go version requirement for `filepath-securejoin` is now Go 1.18
218 (we use generics internally).
219
220 For reference, `[email protected]` somewhat-arbitrarily bumped the
221 Go version requirement to 1.21.
222
223 While we did make some use of Go 1.21 stdlib features (and in principle Go
224 versions <= 1.21 are no longer even supported by upstream anymore), some
225 downstreams have complained that the version bump has meant that they have to
226 do workarounds when backporting fixes that use the new `filepath-securejoin`
227 API onto old branches. This is not an ideal situation, but since using this
228 library is probably better for most downstreams than a hand-rolled
229 workaround, we now have compatibility shims that allow us to build on older
230 Go versions.
231 - Lower minimum version requirement for `golang.org/x/sys` to `v0.18.0` (we
232 need the wrappers for `fsconfig(2)`), which should also make backporting
233 patches to older branches easier.
234
235 ## [0.3.5] - 2024-12-06 ##
236
237 ### Fixed ###
238 - `MkdirAll` will now no longer return an `EEXIST` error if two racing
239 processes are creating the same directory. We will still verify that the path
240 is a directory, but this will avoid spurious errors when multiple threads or
241 programs are trying to `MkdirAll` the same path. opencontainers/runc#4543
242
243 ## [0.3.4] - 2024-10-09 ##
244
245 ### Fixed ###
246 - Previously, some testing mocks we had resulted in us doing `import "testing"`
247 in non-`_test.go` code, which made some downstreams like Kubernetes unhappy.
248 This has been fixed. (#32)
249
250 ## [0.3.3] - 2024-09-30 ##
251
252 ### Fixed ###
253 - The mode and owner verification logic in `MkdirAll` has been removed. This
254 was originally intended to protect against some theoretical attacks but upon
255 further consideration these protections don't actually buy us anything and
256 they were causing spurious errors with more complicated filesystem setups.
257 - The "is the created directory empty" logic in `MkdirAll` has also been
258 removed. This was not causing us issues yet, but some pseudofilesystems (such
259 as `cgroup`) create non-empty directories and so this logic would've been
260 wrong for such cases.
261
262 ## [0.3.2] - 2024-09-13 ##
263
264 ### Changed ###
265 - Passing the `S_ISUID` or `S_ISGID` modes to `MkdirAllInRoot` will now return
266 an explicit error saying that those bits are ignored by `mkdirat(2)`. In the
267 past a different error was returned, but since the silent ignoring behaviour
268 is codified in the man pages a more explicit error seems apt. While silently
269 ignoring these bits would be the most compatible option, it could lead to
270 users thinking their code sets these bits when it doesn't. Programs that need
271 to deal with compatibility can mask the bits themselves. (#23, #25)
272
273 ### Fixed ###
274 - If a directory has `S_ISGID` set, then all child directories will have
275 `S_ISGID` set when created and a different gid will be used for any inode
276 created under the directory. Previously, the "expected owner and mode"
277 validation in `securejoin.MkdirAll` did not correctly handle this. We now
278 correctly handle this case. (#24, #25)
279
280 ## [0.3.1] - 2024-07-23 ##
281
282 ### Changed ###
283 - By allowing `Open(at)InRoot` to opt-out of the extra work done by `MkdirAll`
284 to do the necessary "partial lookups", `Open(at)InRoot` now does less work
285 for both implementations (resulting in a many-fold decrease in the number of
286 operations for `openat2`, and a modest improvement for non-`openat2`) and is
287 far more guaranteed to match the correct `openat2(RESOLVE_IN_ROOT)`
288 behaviour.
289 - We now use `readlinkat(fd, "")` where possible. For `Open(at)InRoot` this
290 effectively just means that we no longer risk getting spurious errors during
291 rename races. However, for our hardened procfs handler, this in theory should
292 prevent mount attacks from tricking us when doing magic-link readlinks (even
293 when using the unsafe host `/proc` handle). Unfortunately `Reopen` is still
294 potentially vulnerable to those kinds of somewhat-esoteric attacks.
295
296 Technically this [will only work on post-2.6.39 kernels][linux-readlinkat-emptypath]
297 but it seems incredibly unlikely anyone is using `filepath-securejoin` on a
298 pre-2011 kernel.
299
300 ### Fixed ###
301 - Several improvements were made to the errors returned by `Open(at)InRoot` and
302 `MkdirAll` when dealing with invalid paths under the emulated (ie.
303 non-`openat2`) implementation. Previously, some paths would return the wrong
304 error (`ENOENT` when the last component was a non-directory), and other paths
305 would be returned as though they were acceptable (trailing-slash components
306 after a non-directory would be ignored by `Open(at)InRoot`).
307
308 These changes were done to match `openat2`'s behaviour and purely is a
309 consistency fix (most users are going to be using `openat2` anyway).
310
311 [linux-readlinkat-emptypath]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=65cfc6722361570bfe255698d9cd4dccaf47570d
312
313 ## [0.3.0] - 2024-07-11 ##
314
315 ### Added ###
316 - A new set of `*os.File`-based APIs have been added. These are adapted from
317 [libpathrs][] and we strongly suggest using them if possible (as they provide
318 far more protection against attacks than `SecureJoin`):
319
320 - `Open(at)InRoot` resolves a path inside a rootfs and returns an `*os.File`
321 handle to the path. Note that the handle returned is an `O_PATH` handle,
322 which cannot be used for reading or writing (as well as some other
323 operations -- [see open(2) for more details][open.2])
324
325 - `Reopen` takes an `O_PATH` file handle and safely re-opens it to upgrade
326 it to a regular handle. This can also be used with non-`O_PATH` handles,
327 but `O_PATH` is the most obvious application.
328
329 - `MkdirAll` is an implementation of `os.MkdirAll` that is safe to use to
330 create a directory tree within a rootfs.
331
332 As these are new APIs, they may change in the future. However, they should be
333 safe to start migrating to as we have extensive tests ensuring they behave
334 correctly and are safe against various races and other attacks.
335
336 [libpathrs]: https://github.com/cyphar/libpathrs
337 [open.2]: https://www.man7.org/linux/man-pages/man2/open.2.html
338
339 ## [0.2.5] - 2024-05-03 ##
340
341 ### Changed ###
342 - Some minor changes were made to how lexical components (like `..` and `.`)
343 are handled during path generation in `SecureJoin`. There is no behaviour
344 change as a result of this fix (the resulting paths are the same).
345
346 ### Fixed ###
347 - The error returned when we hit a symlink loop now references the correct
348 path. (#10)
349
350 ## [0.2.4] - 2023-09-06 ##
351
352 ### Security ###
353 - This release fixes a potential security issue in filepath-securejoin when
354 used on Windows ([GHSA-6xv5-86q9-7xr8][], which could be used to generate
355 paths outside of the provided rootfs in certain cases), as well as improving
356 the overall behaviour of filepath-securejoin when dealing with Windows paths
357 that contain volume names. Thanks to Paulo Gomes for discovering and fixing
358 these issues.
359
360 ### Fixed ###
361 - Switch to GitHub Actions for CI so we can test on Windows as well as Linux
362 and MacOS.
363
364 [GHSA-6xv5-86q9-7xr8]: https://github.com/advisories/GHSA-6xv5-86q9-7xr8
365
366 ## [0.2.3] - 2021-06-04 ##
367
368 ### Changed ###
369 - Switch to Go 1.13-style `%w` error wrapping, letting us drop the dependency
370 on `github.com/pkg/errors`.
371
372 ## [0.2.2] - 2018-09-05 ##
373
374 ### Changed ###
375 - Use `syscall.ELOOP` as the base error for symlink loops, rather than our own
376 (internal) error. This allows callers to more easily use `errors.Is` to check
377 for this case.
378
379 ## [0.2.1] - 2018-09-05 ##
380
381 ### Fixed ###
382 - Use our own `IsNotExist` implementation, which lets us handle `ENOTDIR`
383 properly within `SecureJoin`.
384
385 ## [0.2.0] - 2017-07-19 ##
386
387 We now have 100% test coverage!
388
389 ### Added ###
390 - Add a `SecureJoinVFS` API that can be used for mocking (as we do in our new
391 tests) or for implementing custom handling of lookup operations (such as for
392 rootless containers, where work is necessary to access directories with weird
393 modes because we don't have `CAP_DAC_READ_SEARCH` or `CAP_DAC_OVERRIDE`).
394
395 ## 0.1.0 - 2017-07-19
396
397 This is our first release of `github.com/cyphar/filepath-securejoin`,
398 containing a full implementation with a coverage of 93.5% (the only missing
399 cases are the error cases, which are hard to mocktest at the moment).
400
401 [Unreleased 0.5.z]: https://github.com/cyphar/filepath-securejoin/compare/v0.5.1...release-0.5
402 [0.5.1]: https://github.com/cyphar/filepath-securejoin/compare/v0.5.0...v0.5.1
403 [0.5.0]: https://github.com/cyphar/filepath-securejoin/compare/v0.4.1...v0.5.0
404 [0.4.1]: https://github.com/cyphar/filepath-securejoin/compare/v0.4.0...v0.4.1
405 [0.4.0]: https://github.com/cyphar/filepath-securejoin/compare/v0.3.6...v0.4.0
406 [0.3.6]: https://github.com/cyphar/filepath-securejoin/compare/v0.3.5...v0.3.6
407 [0.3.5]: https://github.com/cyphar/filepath-securejoin/compare/v0.3.4...v0.3.5
408 [0.3.4]: https://github.com/cyphar/filepath-securejoin/compare/v0.3.3...v0.3.4
409 [0.3.3]: https://github.com/cyphar/filepath-securejoin/compare/v0.3.2...v0.3.3
410 [0.3.2]: https://github.com/cyphar/filepath-securejoin/compare/v0.3.1...v0.3.2
411 [0.3.1]: https://github.com/cyphar/filepath-securejoin/compare/v0.3.0...v0.3.1
412 [0.3.0]: https://github.com/cyphar/filepath-securejoin/compare/v0.2.5...v0.3.0
413 [0.2.5]: https://github.com/cyphar/filepath-securejoin/compare/v0.2.4...v0.2.5
414 [0.2.4]: https://github.com/cyphar/filepath-securejoin/compare/v0.2.3...v0.2.4
415 [0.2.3]: https://github.com/cyphar/filepath-securejoin/compare/v0.2.2...v0.2.3
416 [0.2.2]: https://github.com/cyphar/filepath-securejoin/compare/v0.2.1...v0.2.2
417 [0.2.1]: https://github.com/cyphar/filepath-securejoin/compare/v0.2.0...v0.2.1
418 [0.2.0]: https://github.com/cyphar/filepath-securejoin/compare/v0.1.0...v0.2.0