Repository navigation
Expand file tree
/
Copy path0010-archive-Prevent-symlink-directory-collision-chmod-at.patch
More file actions
414 lines (408 loc) · 28.6 KB
/
Copy path0010-archive-Prevent-symlink-directory-collision-chmod-at.patch
File metadata and controls
414 lines (408 loc) · 28.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Alex Crichton <alex@alexcrichton.com>
Date: Thu, 19 Mar 2026 16:58:05 -0500
Subject: [PATCH] archive: Prevent symlink-directory collision chmod attack
(#442)
When unpacking a tarball containing a symlink followed by a directory
entry with the same path, unpack_dir previously used fs::metadata()
which follows symlinks. This allowed an attacker to modify permissions
on arbitrary directories outside the extraction path.
The fix uses fs::symlink_metadata() to detect symlinks and refuse to
treat them as valid existing directories.
Document more exhaustively+consistently security caveats.
Reported-by: Sergei Zimmerman <https://github.com/xokdvium>
Assisted-by: OpenCode (Claude claude-opus-4-5)
Signed-off-by: Colin Walters <walters@verbum.org>
Co-authored-by: Colin Walters <walters@verbum.org>
---
vendor/tar-0.4.38/.cargo-checksum.json | 2 +-
vendor/tar-0.4.38/src/archive.rs | 18 +++++++--
vendor/tar-0.4.38/src/entry.rs | 7 ++--
vendor/tar-0.4.38/tests/entry.rs | 56 ++++++++++++++++++++++++++
vendor/tar-0.4.43/.cargo-checksum.json | 2 +-
vendor/tar-0.4.43/src/archive.rs | 18 +++++++--
vendor/tar-0.4.43/src/entry.rs | 7 ++--
vendor/tar-0.4.43/tests/entry.rs | 56 ++++++++++++++++++++++++++
vendor/tar-0.4.44/.cargo-checksum.json | 2 +-
vendor/tar-0.4.44/src/archive.rs | 18 +++++++--
vendor/tar-0.4.44/src/entry.rs | 7 ++--
vendor/tar-0.4.44/tests/entry.rs | 56 ++++++++++++++++++++++++++
12 files changed, 228 insertions(+), 21 deletions(-)
diff --git a/vendor/tar-0.4.38/.cargo-checksum.json b/vendor/tar-0.4.38/.cargo-checksum.json
index 49dec43..29f3652 100644
--- a/vendor/tar-0.4.38/.cargo-checksum.json
+++ b/vendor/tar-0.4.38/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{".cargo_vcs_info.json":"e45d0dcacca796a5216a6c06af829c4951e4a6a50a45a49c17f3e57cd6d37d4d",".github/dependabot.yml":"d04c9b0253b2bbae886b59a11399ea260397b460cd9f5712d692d1c85f8ec090",".github/workflows/main.yml":"2cb0bdc03adee75e18d8c9115c16baaae15136d6b7c47ad7f5ffc00d2dca7267","Cargo.lock":"9872bf9e41b9cadee45b688c9537030a993ca49a266fc7859029d8c74810d1d5","Cargo.toml":"8353c71aa4d394efa7aaeac3004d0a16fd0c7124b7bd57ea91ba87a7b2015f15","Cargo.toml.orig":"cf5ae4c1847ad24f5314d0ae865ad72d58cb050362611effd8a1d84e0e541b37","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"71079f1a0962c2cf288058f38d24735bddabd1427ac2dee72ec18cc5ae4bceed","examples/extract_file.rs":"dc487f6631d824175afc3ee33de99e80718a8ca3f9e57fddd7cac0a46c07d3ae","examples/list.rs":"36e412205eaffea8ab7f39be4173594b74e36acb369e091362b1975ee4a7a14b","examples/raw_list.rs":"0a735576ac354457d6d5a4d395d044fae99bf67a7c69960ca784a6f6a1743651","examples/write.rs":"419ac3e4155035e32b52cd8e6ae987a2d99cf82f60abbfb315c2a2c4f8e8fd19","src/archive.rs":"85a0091e02690c62379137988cd9b2689009536a0b941f1ab0581db26e9ebce6","src/builder.rs":"2914f394d44c133557532bf5765fe63e0def30ec0b447f8f2bc620e932a2036a","src/entry.rs":"705016636f7fdcad4fe20d7d2672be2b94cc53bb05e47628f5212b89e17a40fe","src/entry_type.rs":"0786688729a96b4a3135b28d40b95c3d4feaad66b9574c490cbea14814ab975f","src/error.rs":"a20813fbc52f1f2e3a79654f62de6001759f6504a06acee5b0819d4865398587","src/header.rs":"fb2b1fa943c19635826b3f2becfb82527be7d08fdac115af840da3ff06152908","src/lib.rs":"5468e413205c907c367c35d28a528389103d68fd6a5b5979bbedba7c9e6b6c99","src/pax.rs":"54002e31151f9c50e02a3da26b3cacd1d3c9a3902daee008ab76d112cf5a2430","tests/all.rs":"567a05d54e369d22efe40f3507a26e21f7878b95bd05c811250b2c350761791b","tests/entry.rs":"c1411ee09da9edb659b508867f0960e804966dfd33801f4a7afaefda331479dd","tests/header/mod.rs":"02b05639f63c39a47559650c7209817bb60282deb4f679d5b001ed936343d9de"},"package":"4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6"}
\ No newline at end of file
+{"files":{".cargo_vcs_info.json":"e45d0dcacca796a5216a6c06af829c4951e4a6a50a45a49c17f3e57cd6d37d4d",".github/dependabot.yml":"d04c9b0253b2bbae886b59a11399ea260397b460cd9f5712d692d1c85f8ec090",".github/workflows/main.yml":"2cb0bdc03adee75e18d8c9115c16baaae15136d6b7c47ad7f5ffc00d2dca7267","Cargo.lock":"9872bf9e41b9cadee45b688c9537030a993ca49a266fc7859029d8c74810d1d5","Cargo.toml":"8353c71aa4d394efa7aaeac3004d0a16fd0c7124b7bd57ea91ba87a7b2015f15","Cargo.toml.orig":"cf5ae4c1847ad24f5314d0ae865ad72d58cb050362611effd8a1d84e0e541b37","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"71079f1a0962c2cf288058f38d24735bddabd1427ac2dee72ec18cc5ae4bceed","examples/extract_file.rs":"dc487f6631d824175afc3ee33de99e80718a8ca3f9e57fddd7cac0a46c07d3ae","examples/list.rs":"36e412205eaffea8ab7f39be4173594b74e36acb369e091362b1975ee4a7a14b","examples/raw_list.rs":"0a735576ac354457d6d5a4d395d044fae99bf67a7c69960ca784a6f6a1743651","examples/write.rs":"419ac3e4155035e32b52cd8e6ae987a2d99cf82f60abbfb315c2a2c4f8e8fd19","src/archive.rs":"4eac362ffc7bf629fcecf88ca43cec96a1753c9e0a759722d916a9931c093e25","src/builder.rs":"2914f394d44c133557532bf5765fe63e0def30ec0b447f8f2bc620e932a2036a","src/entry.rs":"2f3ff18dc0c693f425488f946e8a7d250c4020134ca870fe5522d9a95b6a6ae0","src/entry_type.rs":"0786688729a96b4a3135b28d40b95c3d4feaad66b9574c490cbea14814ab975f","src/error.rs":"a20813fbc52f1f2e3a79654f62de6001759f6504a06acee5b0819d4865398587","src/header.rs":"fb2b1fa943c19635826b3f2becfb82527be7d08fdac115af840da3ff06152908","src/lib.rs":"5468e413205c907c367c35d28a528389103d68fd6a5b5979bbedba7c9e6b6c99","src/pax.rs":"54002e31151f9c50e02a3da26b3cacd1d3c9a3902daee008ab76d112cf5a2430","tests/all.rs":"567a05d54e369d22efe40f3507a26e21f7878b95bd05c811250b2c350761791b","tests/entry.rs":"97b7927f14027c2f9bce2dc5f565ede00b9c37da41d0ee95144be8c0cb8c6983","tests/header/mod.rs":"02b05639f63c39a47559650c7209817bb60282deb4f679d5b001ed936343d9de"},"package":"4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6"}
diff --git a/vendor/tar-0.4.38/src/archive.rs b/vendor/tar-0.4.38/src/archive.rs
index 1bed512..056eb71 100644
--- a/vendor/tar-0.4.38/src/archive.rs
+++ b/vendor/tar-0.4.38/src/archive.rs
@@ -88,9 +88,21 @@ impl<R: Read> Archive<R> {
/// extracting each file in turn to the location specified by the entry's
/// path name.
///
- /// This operation is relatively sensitive in that it will not write files
- /// outside of the path specified by `dst`. Files in the archive which have
- /// a '..' in their path are skipped during the unpacking process.
+ /// # Security
+ ///
+ /// A best-effort is made to prevent writing files outside `dst` (paths
+ /// containing `..` are skipped, symlinks are validated). However, there
+ /// have been historical bugs in this area, and more may exist. For this
+ /// reason, when processing untrusted archives, stronger sandboxing is
+ /// encouraged: e.g. the [`cap-std`] crate and/or OS-level
+ /// containerization/virtualization.
+ ///
+ /// If `dst` does not exist, it is created. Unpacking into an existing
+ /// directory merges content. This function assumes `dst` is not
+ /// concurrently modified by untrusted processes. Protecting against
+ /// TOCTOU races is out of scope for this crate.
+ ///
+ /// [`cap-std`]: https://docs.rs/cap-std/
///
/// # Examples
///
diff --git a/vendor/tar-0.4.38/src/entry.rs b/vendor/tar-0.4.38/src/entry.rs
index 8f0b62a..287d689 100644
--- a/vendor/tar-0.4.38/src/entry.rs
+++ b/vendor/tar-0.4.38/src/entry.rs
@@ -210,8 +210,9 @@ impl<'a, R: Read> Entry<'a, R> {
/// also be propagated to the path `dst`. Any existing file at the location
/// `dst` will be overwritten.
///
- /// This function carefully avoids writing outside of `dst`. If the file has
- /// a '..' in its path, this function will skip it and return false.
+ /// # Security
+ ///
+ /// See [`Archive::unpack`].
///
/// # Examples
///
@@ -430,7 +431,7 @@ impl<'a> EntryFields<'a> {
// If the directory already exists just let it slide
fs::create_dir(dst).or_else(|err| {
if err.kind() == ErrorKind::AlreadyExists {
- let prev = fs::metadata(dst);
+ let prev = fs::symlink_metadata(dst);
if prev.map(|m| m.is_dir()).unwrap_or(false) {
return Ok(());
}
diff --git a/vendor/tar-0.4.38/tests/entry.rs b/vendor/tar-0.4.38/tests/entry.rs
index fa8eeae..5e874fa 100644
--- a/vendor/tar-0.4.38/tests/entry.rs
+++ b/vendor/tar-0.4.38/tests/entry.rs
@@ -377,3 +377,59 @@ fn modify_symlink_just_created() {
t!(t!(File::open(&test)).read_to_end(&mut contents));
assert_eq!(contents.len(), 0);
}
+
+/// Test that unpacking a tarball with a symlink followed by a directory entry
+/// with the same name does not allow modifying permissions of arbitrary directories
+/// outside the extraction path.
+#[test]
+#[cfg(unix)]
+fn symlink_dir_collision_does_not_modify_external_dir_permissions() {
+ use ::std::fs;
+ use ::std::os::unix::fs::PermissionsExt;
+
+ let td = Builder::new().prefix("tar").tempdir().unwrap();
+
+ let target_dir = td.path().join("target-dir");
+ fs::create_dir(&target_dir).unwrap();
+ fs::set_permissions(&target_dir, fs::Permissions::from_mode(0o700)).unwrap();
+ let before_mode = fs::metadata(&target_dir).unwrap().permissions().mode() & 0o7777;
+ assert_eq!(before_mode, 0o700);
+
+ let extract_dir = td.path().join("extract-dir");
+ fs::create_dir(&extract_dir).unwrap();
+
+ let mut ar = tar::Builder::new(Vec::new());
+
+ let mut header = tar::Header::new_gnu();
+ header.set_size(0);
+ header.set_entry_type(tar::EntryType::Symlink);
+ header.set_path("foo").unwrap();
+ header.set_link_name(&target_dir).unwrap();
+ header.set_mode(0o777);
+ header.set_cksum();
+ ar.append(&header, &[][..]).unwrap();
+
+ let mut header = tar::Header::new_gnu();
+ header.set_size(0);
+ header.set_entry_type(tar::EntryType::Directory);
+ header.set_path("foo").unwrap();
+ header.set_mode(0o777);
+ header.set_cksum();
+ ar.append(&header, &[][..]).unwrap();
+
+ let bytes = ar.into_inner().unwrap();
+ let mut ar = tar::Archive::new(&bytes[..]);
+
+ let result = ar.unpack(&extract_dir);
+ assert!(result.is_err());
+
+ let symlink_path = extract_dir.join("foo");
+ assert!(symlink_path
+ .symlink_metadata()
+ .unwrap()
+ .file_type()
+ .is_symlink());
+
+ let after_mode = fs::metadata(&target_dir).unwrap().permissions().mode() & 0o7777;
+ assert_eq!(after_mode, 0o700);
+}
diff --git a/vendor/tar-0.4.43/.cargo-checksum.json b/vendor/tar-0.4.43/.cargo-checksum.json
index 58b2036..d060264 100644
--- a/vendor/tar-0.4.43/.cargo-checksum.json
+++ b/vendor/tar-0.4.43/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{".cargo_vcs_info.json":"025fd4291d3a3d5e2526d4caa043c7c93cbf14d7ff86625217ec5eb50cff16aa",".github/dependabot.yml":"d04c9b0253b2bbae886b59a11399ea260397b460cd9f5712d692d1c85f8ec090",".github/workflows/main.yml":"6c844d85c298b164d0aa3f704ec9c4dd5df7748458d99ff65c4b99c4b1b18cf1","Cargo.lock":"4cd48beffdb2f2c3d877b25416981d7e03d174f4978aa209f57c8577c25eaa20","Cargo.toml":"1c485088be21ebf8749ce7894365429c16f1be2b99ebcb14f038255dc19323d9","Cargo.toml.orig":"cacd8e8c4aa358255d6f49effaaef01fcf285b4b36657673d5035624b8b2873b","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"71079f1a0962c2cf288058f38d24735bddabd1427ac2dee72ec18cc5ae4bceed","examples/extract_file.rs":"dc487f6631d824175afc3ee33de99e80718a8ca3f9e57fddd7cac0a46c07d3ae","examples/list.rs":"36e412205eaffea8ab7f39be4173594b74e36acb369e091362b1975ee4a7a14b","examples/raw_list.rs":"0a735576ac354457d6d5a4d395d044fae99bf67a7c69960ca784a6f6a1743651","examples/write.rs":"419ac3e4155035e32b52cd8e6ae987a2d99cf82f60abbfb315c2a2c4f8e8fd19","src/archive.rs":"913500dfb2484e1ae7e38a8de23b7d0c3522eeae956c1cbcb765cc9f14504190","src/builder.rs":"d552134c0a4e937ab133bd312aa05b37ad780e450ba4a8597143368cbc6d253c","src/entry.rs":"ef0583b82c214348875074a911a24e43007d9672c6dec12aaacee852cd3f71c8","src/entry_type.rs":"e22cf19e52310cf19f9a43e4191bb71a98c703274211265266565d9533730f6d","src/error.rs":"a20813fbc52f1f2e3a79654f62de6001759f6504a06acee5b0819d4865398587","src/header.rs":"eefe3426044e672e5134a5368c951de226d971fcf76a2f37b1cf847fda9ec37e","src/lib.rs":"b0c121cc2fdea38dad19e70bec6fd167d7a8dd87bb4d8c33016af78e1b1be9e1","src/pax.rs":"54c991798b22d6b5b7b9de2bd53aea5cfc48c494b61c26fa9867587d926b4b51","tests/all.rs":"7cc3b6fdf7ad77826305a414986af889d2971ea26a67e08df42a2f8fdfe76f91","tests/entry.rs":"07f1a9fbe30bc0d7d0af8c93a27cb33dce7e949bc198dc182bf2326ce08464d6","tests/header/mod.rs":"78fead69835262dbdcb35b6259cd664a70964e050b855417b5b29ae28f31c9fc"},"package":"c65998313f8e17d0d553d28f91a0df93e4dbbbf770279c7bc21ca0f09ea1a1f6"}
\ No newline at end of file
+{"files":{".cargo_vcs_info.json":"025fd4291d3a3d5e2526d4caa043c7c93cbf14d7ff86625217ec5eb50cff16aa",".github/dependabot.yml":"d04c9b0253b2bbae886b59a11399ea260397b460cd9f5712d692d1c85f8ec090",".github/workflows/main.yml":"6c844d85c298b164d0aa3f704ec9c4dd5df7748458d99ff65c4b99c4b1b18cf1","Cargo.lock":"4cd48beffdb2f2c3d877b25416981d7e03d174f4978aa209f57c8577c25eaa20","Cargo.toml":"1c485088be21ebf8749ce7894365429c16f1be2b99ebcb14f038255dc19323d9","Cargo.toml.orig":"cacd8e8c4aa358255d6f49effaaef01fcf285b4b36657673d5035624b8b2873b","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"71079f1a0962c2cf288058f38d24735bddabd1427ac2dee72ec18cc5ae4bceed","examples/extract_file.rs":"dc487f6631d824175afc3ee33de99e80718a8ca3f9e57fddd7cac0a46c07d3ae","examples/list.rs":"36e412205eaffea8ab7f39be4173594b74e36acb369e091362b1975ee4a7a14b","examples/raw_list.rs":"0a735576ac354457d6d5a4d395d044fae99bf67a7c69960ca784a6f6a1743651","examples/write.rs":"419ac3e4155035e32b52cd8e6ae987a2d99cf82f60abbfb315c2a2c4f8e8fd19","src/archive.rs":"b9ad64d9ab2ed89aa885ac57f912feabdffeaccc120ce351a72091fc6dc79f5d","src/builder.rs":"d552134c0a4e937ab133bd312aa05b37ad780e450ba4a8597143368cbc6d253c","src/entry.rs":"370dc8cc216254b7b8dcdd063af41aee69382cc7363dd6bd4536b15030e2c198","src/entry_type.rs":"e22cf19e52310cf19f9a43e4191bb71a98c703274211265266565d9533730f6d","src/error.rs":"a20813fbc52f1f2e3a79654f62de6001759f6504a06acee5b0819d4865398587","src/header.rs":"eefe3426044e672e5134a5368c951de226d971fcf76a2f37b1cf847fda9ec37e","src/lib.rs":"b0c121cc2fdea38dad19e70bec6fd167d7a8dd87bb4d8c33016af78e1b1be9e1","src/pax.rs":"54c991798b22d6b5b7b9de2bd53aea5cfc48c494b61c26fa9867587d926b4b51","tests/all.rs":"7cc3b6fdf7ad77826305a414986af889d2971ea26a67e08df42a2f8fdfe76f91","tests/entry.rs":"51f229be18b27b5db94e21254897ffab747f707cac9cb270c4f902b57031a092","tests/header/mod.rs":"78fead69835262dbdcb35b6259cd664a70964e050b855417b5b29ae28f31c9fc"},"package":"c65998313f8e17d0d553d28f91a0df93e4dbbbf770279c7bc21ca0f09ea1a1f6"}
diff --git a/vendor/tar-0.4.43/src/archive.rs b/vendor/tar-0.4.43/src/archive.rs
index 924e54a..17938a8 100644
--- a/vendor/tar-0.4.43/src/archive.rs
+++ b/vendor/tar-0.4.43/src/archive.rs
@@ -92,9 +92,21 @@ impl<R: Read> Archive<R> {
/// extracting each file in turn to the location specified by the entry's
/// path name.
///
- /// This operation is relatively sensitive in that it will not write files
- /// outside of the path specified by `dst`. Files in the archive which have
- /// a '..' in their path are skipped during the unpacking process.
+ /// # Security
+ ///
+ /// A best-effort is made to prevent writing files outside `dst` (paths
+ /// containing `..` are skipped, symlinks are validated). However, there
+ /// have been historical bugs in this area, and more may exist. For this
+ /// reason, when processing untrusted archives, stronger sandboxing is
+ /// encouraged: e.g. the [`cap-std`] crate and/or OS-level
+ /// containerization/virtualization.
+ ///
+ /// If `dst` does not exist, it is created. Unpacking into an existing
+ /// directory merges content. This function assumes `dst` is not
+ /// concurrently modified by untrusted processes. Protecting against
+ /// TOCTOU races is out of scope for this crate.
+ ///
+ /// [`cap-std`]: https://docs.rs/cap-std/
///
/// # Examples
///
diff --git a/vendor/tar-0.4.43/src/entry.rs b/vendor/tar-0.4.43/src/entry.rs
index b6b48b4..c9f3b9f 100644
--- a/vendor/tar-0.4.43/src/entry.rs
+++ b/vendor/tar-0.4.43/src/entry.rs
@@ -212,8 +212,9 @@ impl<'a, R: Read> Entry<'a, R> {
/// also be propagated to the path `dst`. Any existing file at the location
/// `dst` will be overwritten.
///
- /// This function carefully avoids writing outside of `dst`. If the file has
- /// a '..' in its path, this function will skip it and return false.
+ /// # Security
+ ///
+ /// See [`Archive::unpack`].
///
/// # Examples
///
@@ -446,7 +447,7 @@ impl<'a> EntryFields<'a> {
// If the directory already exists just let it slide
fs::create_dir(dst).or_else(|err| {
if err.kind() == ErrorKind::AlreadyExists {
- let prev = fs::metadata(dst);
+ let prev = fs::symlink_metadata(dst);
if prev.map(|m| m.is_dir()).unwrap_or(false) {
return Ok(());
}
diff --git a/vendor/tar-0.4.43/tests/entry.rs b/vendor/tar-0.4.43/tests/entry.rs
index 4d612e2..92c11f6 100644
--- a/vendor/tar-0.4.43/tests/entry.rs
+++ b/vendor/tar-0.4.43/tests/entry.rs
@@ -409,3 +409,59 @@ fn modify_symlink_just_created() {
t!(t!(File::open(&test)).read_to_end(&mut contents));
assert_eq!(contents.len(), 0);
}
+
+/// Test that unpacking a tarball with a symlink followed by a directory entry
+/// with the same name does not allow modifying permissions of arbitrary directories
+/// outside the extraction path.
+#[test]
+#[cfg(unix)]
+fn symlink_dir_collision_does_not_modify_external_dir_permissions() {
+ use ::std::fs;
+ use ::std::os::unix::fs::PermissionsExt;
+
+ let td = Builder::new().prefix("tar").tempdir().unwrap();
+
+ let target_dir = td.path().join("target-dir");
+ fs::create_dir(&target_dir).unwrap();
+ fs::set_permissions(&target_dir, fs::Permissions::from_mode(0o700)).unwrap();
+ let before_mode = fs::metadata(&target_dir).unwrap().permissions().mode() & 0o7777;
+ assert_eq!(before_mode, 0o700);
+
+ let extract_dir = td.path().join("extract-dir");
+ fs::create_dir(&extract_dir).unwrap();
+
+ let mut ar = tar::Builder::new(Vec::new());
+
+ let mut header = tar::Header::new_gnu();
+ header.set_size(0);
+ header.set_entry_type(tar::EntryType::Symlink);
+ header.set_path("foo").unwrap();
+ header.set_link_name(&target_dir).unwrap();
+ header.set_mode(0o777);
+ header.set_cksum();
+ ar.append(&header, &[][..]).unwrap();
+
+ let mut header = tar::Header::new_gnu();
+ header.set_size(0);
+ header.set_entry_type(tar::EntryType::Directory);
+ header.set_path("foo").unwrap();
+ header.set_mode(0o777);
+ header.set_cksum();
+ ar.append(&header, &[][..]).unwrap();
+
+ let bytes = ar.into_inner().unwrap();
+ let mut ar = tar::Archive::new(&bytes[..]);
+
+ let result = ar.unpack(&extract_dir);
+ assert!(result.is_err());
+
+ let symlink_path = extract_dir.join("foo");
+ assert!(symlink_path
+ .symlink_metadata()
+ .unwrap()
+ .file_type()
+ .is_symlink());
+
+ let after_mode = fs::metadata(&target_dir).unwrap().permissions().mode() & 0o7777;
+ assert_eq!(after_mode, 0o700);
+}
diff --git a/vendor/tar-0.4.44/.cargo-checksum.json b/vendor/tar-0.4.44/.cargo-checksum.json
index 078f51c..3542b9c 100644
--- a/vendor/tar-0.4.44/.cargo-checksum.json
+++ b/vendor/tar-0.4.44/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{".cargo_vcs_info.json":"bd0530055d1e8045030571042267ea5674c6cc4bd6af4bbd9d1a80f96578bf30",".github/dependabot.yml":"d04c9b0253b2bbae886b59a11399ea260397b460cd9f5712d692d1c85f8ec090",".github/workflows/main.yml":"3127e0a0379272a0f9b31e7d910b9de08ddf6b0c08b95f80825e5a07cdb0df91","Cargo.lock":"d861d685d22978a03927adb7e90992836adbed746dde53b1f256268a95911da3","Cargo.toml":"b3822faba576e8faef11ab664ff71adcf46dc547c21684e7ddf502b321ca9004","Cargo.toml.orig":"2692096c2923e0b549ea93ad2754becbbe0213469ad4a96bb5b1ffdf6546915f","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"71079f1a0962c2cf288058f38d24735bddabd1427ac2dee72ec18cc5ae4bceed","examples/extract_file.rs":"dc487f6631d824175afc3ee33de99e80718a8ca3f9e57fddd7cac0a46c07d3ae","examples/list.rs":"36e412205eaffea8ab7f39be4173594b74e36acb369e091362b1975ee4a7a14b","examples/raw_list.rs":"0a735576ac354457d6d5a4d395d044fae99bf67a7c69960ca784a6f6a1743651","examples/write.rs":"419ac3e4155035e32b52cd8e6ae987a2d99cf82f60abbfb315c2a2c4f8e8fd19","src/archive.rs":"c23693531825157c481f5addcf05cd48b8bfbb19c7777b7b8b2375cfdb67aa66","src/builder.rs":"50d6d4cbdad2722ff9524cef44453fa500b145b7757ef19e2ccdfab1d08aa6c9","src/entry.rs":"259ba8993987db5ab1fd9d0163e0de54c2168837f74a53f75569a2d303823769","src/entry_type.rs":"e22cf19e52310cf19f9a43e4191bb71a98c703274211265266565d9533730f6d","src/error.rs":"a20813fbc52f1f2e3a79654f62de6001759f6504a06acee5b0819d4865398587","src/header.rs":"12994aef80d5bdae8015de90e25f071ba46d897fb3ba3fc4e0103f02a9d3c235","src/lib.rs":"b0c121cc2fdea38dad19e70bec6fd167d7a8dd87bb4d8c33016af78e1b1be9e1","src/pax.rs":"54c991798b22d6b5b7b9de2bd53aea5cfc48c494b61c26fa9867587d926b4b51","tests/all.rs":"938658f554c93a0c9c90df8814da3155ce98d94494b01b04acf037b7af6d8070","tests/entry.rs":"07f1a9fbe30bc0d7d0af8c93a27cb33dce7e949bc198dc182bf2326ce08464d6","tests/header/mod.rs":"78fead69835262dbdcb35b6259cd664a70964e050b855417b5b29ae28f31c9fc"},"package":"1d863878d212c87a19c1a610eb53bb01fe12951c0501cf5a0d65f724914a667a"}
\ No newline at end of file
+{"files":{".cargo_vcs_info.json":"bd0530055d1e8045030571042267ea5674c6cc4bd6af4bbd9d1a80f96578bf30",".github/dependabot.yml":"d04c9b0253b2bbae886b59a11399ea260397b460cd9f5712d692d1c85f8ec090",".github/workflows/main.yml":"3127e0a0379272a0f9b31e7d910b9de08ddf6b0c08b95f80825e5a07cdb0df91","Cargo.lock":"d861d685d22978a03927adb7e90992836adbed746dde53b1f256268a95911da3","Cargo.toml":"b3822faba576e8faef11ab664ff71adcf46dc547c21684e7ddf502b321ca9004","Cargo.toml.orig":"2692096c2923e0b549ea93ad2754becbbe0213469ad4a96bb5b1ffdf6546915f","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"71079f1a0962c2cf288058f38d24735bddabd1427ac2dee72ec18cc5ae4bceed","examples/extract_file.rs":"dc487f6631d824175afc3ee33de99e80718a8ca3f9e57fddd7cac0a46c07d3ae","examples/list.rs":"36e412205eaffea8ab7f39be4173594b74e36acb369e091362b1975ee4a7a14b","examples/raw_list.rs":"0a735576ac354457d6d5a4d395d044fae99bf67a7c69960ca784a6f6a1743651","examples/write.rs":"419ac3e4155035e32b52cd8e6ae987a2d99cf82f60abbfb315c2a2c4f8e8fd19","src/archive.rs":"8755087ac4437356d74ee7e10a589986763d80e14e2c105edc3e2936c9358534","src/builder.rs":"50d6d4cbdad2722ff9524cef44453fa500b145b7757ef19e2ccdfab1d08aa6c9","src/entry.rs":"4dd1b8cc43917989b0b9c7f3e9e39798b1c5676ba3ecc0135b52b85de659c66b","src/entry_type.rs":"e22cf19e52310cf19f9a43e4191bb71a98c703274211265266565d9533730f6d","src/error.rs":"a20813fbc52f1f2e3a79654f62de6001759f6504a06acee5b0819d4865398587","src/header.rs":"12994aef80d5bdae8015de90e25f071ba46d897fb3ba3fc4e0103f02a9d3c235","src/lib.rs":"b0c121cc2fdea38dad19e70bec6fd167d7a8dd87bb4d8c33016af78e1b1be9e1","src/pax.rs":"54c991798b22d6b5b7b9de2bd53aea5cfc48c494b61c26fa9867587d926b4b51","tests/all.rs":"938658f554c93a0c9c90df8814da3155ce98d94494b01b04acf037b7af6d8070","tests/entry.rs":"51f229be18b27b5db94e21254897ffab747f707cac9cb270c4f902b57031a092","tests/header/mod.rs":"78fead69835262dbdcb35b6259cd664a70964e050b855417b5b29ae28f31c9fc"},"package":"1d863878d212c87a19c1a610eb53bb01fe12951c0501cf5a0d65f724914a667a"}
diff --git a/vendor/tar-0.4.44/src/archive.rs b/vendor/tar-0.4.44/src/archive.rs
index 4d569c6..459c28b 100644
--- a/vendor/tar-0.4.44/src/archive.rs
+++ b/vendor/tar-0.4.44/src/archive.rs
@@ -93,9 +93,21 @@ impl<R: Read> Archive<R> {
/// extracting each file in turn to the location specified by the entry's
/// path name.
///
- /// This operation is relatively sensitive in that it will not write files
- /// outside of the path specified by `dst`. Files in the archive which have
- /// a '..' in their path are skipped during the unpacking process.
+ /// # Security
+ ///
+ /// A best-effort is made to prevent writing files outside `dst` (paths
+ /// containing `..` are skipped, symlinks are validated). However, there
+ /// have been historical bugs in this area, and more may exist. For this
+ /// reason, when processing untrusted archives, stronger sandboxing is
+ /// encouraged: e.g. the [`cap-std`] crate and/or OS-level
+ /// containerization/virtualization.
+ ///
+ /// If `dst` does not exist, it is created. Unpacking into an existing
+ /// directory merges content. This function assumes `dst` is not
+ /// concurrently modified by untrusted processes. Protecting against
+ /// TOCTOU races is out of scope for this crate.
+ ///
+ /// [`cap-std`]: https://docs.rs/cap-std/
///
/// # Examples
///
diff --git a/vendor/tar-0.4.44/src/entry.rs b/vendor/tar-0.4.44/src/entry.rs
index 843719f..6898b0a 100644
--- a/vendor/tar-0.4.44/src/entry.rs
+++ b/vendor/tar-0.4.44/src/entry.rs
@@ -212,8 +212,9 @@ impl<'a, R: Read> Entry<'a, R> {
/// also be propagated to the path `dst`. Any existing file at the location
/// `dst` will be overwritten.
///
- /// This function carefully avoids writing outside of `dst`. If the file has
- /// a '..' in its path, this function will skip it and return false.
+ /// # Security
+ ///
+ /// See [`Archive::unpack`].
///
/// # Examples
///
@@ -446,7 +447,7 @@ impl<'a> EntryFields<'a> {
// If the directory already exists just let it slide
fs::create_dir(dst).or_else(|err| {
if err.kind() == ErrorKind::AlreadyExists {
- let prev = fs::metadata(dst);
+ let prev = fs::symlink_metadata(dst);
if prev.map(|m| m.is_dir()).unwrap_or(false) {
return Ok(());
}
diff --git a/vendor/tar-0.4.44/tests/entry.rs b/vendor/tar-0.4.44/tests/entry.rs
index 4d612e2..92c11f6 100644
--- a/vendor/tar-0.4.44/tests/entry.rs
+++ b/vendor/tar-0.4.44/tests/entry.rs
@@ -409,3 +409,59 @@ fn modify_symlink_just_created() {
t!(t!(File::open(&test)).read_to_end(&mut contents));
assert_eq!(contents.len(), 0);
}
+
+/// Test that unpacking a tarball with a symlink followed by a directory entry
+/// with the same name does not allow modifying permissions of arbitrary directories
+/// outside the extraction path.
+#[test]
+#[cfg(unix)]
+fn symlink_dir_collision_does_not_modify_external_dir_permissions() {
+ use ::std::fs;
+ use ::std::os::unix::fs::PermissionsExt;
+
+ let td = Builder::new().prefix("tar").tempdir().unwrap();
+
+ let target_dir = td.path().join("target-dir");
+ fs::create_dir(&target_dir).unwrap();
+ fs::set_permissions(&target_dir, fs::Permissions::from_mode(0o700)).unwrap();
+ let before_mode = fs::metadata(&target_dir).unwrap().permissions().mode() & 0o7777;
+ assert_eq!(before_mode, 0o700);
+
+ let extract_dir = td.path().join("extract-dir");
+ fs::create_dir(&extract_dir).unwrap();
+
+ let mut ar = tar::Builder::new(Vec::new());
+
+ let mut header = tar::Header::new_gnu();
+ header.set_size(0);
+ header.set_entry_type(tar::EntryType::Symlink);
+ header.set_path("foo").unwrap();
+ header.set_link_name(&target_dir).unwrap();
+ header.set_mode(0o777);
+ header.set_cksum();
+ ar.append(&header, &[][..]).unwrap();
+
+ let mut header = tar::Header::new_gnu();
+ header.set_size(0);
+ header.set_entry_type(tar::EntryType::Directory);
+ header.set_path("foo").unwrap();
+ header.set_mode(0o777);
+ header.set_cksum();
+ ar.append(&header, &[][..]).unwrap();
+
+ let bytes = ar.into_inner().unwrap();
+ let mut ar = tar::Archive::new(&bytes[..]);
+
+ let result = ar.unpack(&extract_dir);
+ assert!(result.is_err());
+
+ let symlink_path = extract_dir.join("foo");
+ assert!(symlink_path
+ .symlink_metadata()
+ .unwrap()
+ .file_type()
+ .is_symlink());
+
+ let after_mode = fs::metadata(&target_dir).unwrap().permissions().mode() & 0o7777;
+ assert_eq!(after_mode, 0o700);
+}