kobako 0.31.0 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/.githooks/linux-tests.sh +29 -0
  3. data/.release-please-manifest.json +1 -1
  4. data/CHANGELOG.md +125 -0
  5. data/Cargo.lock +457 -494
  6. data/README.md +2 -3
  7. data/ROADMAP.md +0 -1
  8. data/crates/kobako-runtime/CHANGELOG.md +90 -0
  9. data/crates/kobako-runtime/Cargo.toml +14 -15
  10. data/crates/kobako-runtime/README.md +1 -1
  11. data/crates/kobako-runtime/src/cred.rs +32 -20
  12. data/crates/kobako-runtime/src/filesystem/bind/fid.rs +300 -22
  13. data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +56 -22
  14. data/crates/kobako-runtime/src/filesystem/bind/unicode.rs +109 -0
  15. data/crates/kobako-runtime/src/filesystem/bind/walk.rs +33 -14
  16. data/crates/kobako-runtime/src/filesystem/bind.rs +393 -220
  17. data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +2 -0
  18. data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +9 -10
  19. data/crates/kobako-runtime/src/filesystem/overlay.rs +277 -46
  20. data/crates/kobako-runtime/src/filesystem/rdir.rs +8 -27
  21. data/crates/kobako-runtime/src/filesystem/testing.rs +31 -0
  22. data/crates/kobako-runtime/src/filesystem/tmpfs.rs +47 -13
  23. data/crates/kobako-runtime/src/filesystem.rs +2 -0
  24. data/crates/kobako-runtime/src/fork.rs +239 -16
  25. data/crates/kobako-runtime/src/limits.rs +17 -41
  26. data/crates/kobako-runtime/src/locking/seqlock.rs +29 -3
  27. data/crates/kobako-runtime/src/locking.rs +508 -113
  28. data/crates/kobako-runtime/src/memcg.rs +83 -160
  29. data/crates/kobako-runtime/src/mount.rs +0 -30
  30. data/crates/kobako-runtime/src/net/connections.rs +53 -13
  31. data/crates/kobako-runtime/src/net/egress.rs +44 -24
  32. data/crates/kobako-runtime/src/net/http.rs +888 -456
  33. data/crates/kobako-runtime/src/net/lookup.rs +150 -50
  34. data/crates/kobako-runtime/src/net/namespace.rs +97 -95
  35. data/crates/kobako-runtime/src/net/reactor.rs +298 -203
  36. data/crates/kobako-runtime/src/net/resolv/darwin.rs +8 -3
  37. data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +50 -0
  38. data/crates/kobako-runtime/src/net/resolv/stub.rs +29 -23
  39. data/crates/kobako-runtime/src/net/resolv/windows.rs +14 -44
  40. data/crates/kobako-runtime/src/net/resolv.rs +39 -15
  41. data/crates/kobako-runtime/src/net/skbuff.rs +109 -0
  42. data/crates/kobako-runtime/src/net/socket.rs +51 -52
  43. data/crates/kobako-runtime/src/net/task.rs +223 -0
  44. data/crates/kobako-runtime/src/net/tcp.rs +410 -158
  45. data/crates/kobako-runtime/src/net/tls.rs +65 -3
  46. data/crates/kobako-runtime/src/net/transport.rs +72 -47
  47. data/crates/kobako-runtime/src/net/udp.rs +231 -129
  48. data/crates/kobako-runtime/src/net.rs +3 -0
  49. data/crates/kobako-runtime/src/sched.rs +244 -58
  50. data/crates/kobako-runtime/src/security.rs +27 -16
  51. data/crates/kobako-runtime/src/vfs/dentry.rs +80 -41
  52. data/crates/kobako-runtime/src/vfs/file.rs +52 -53
  53. data/crates/kobako-runtime/src/vfs/kern_path.rs +24 -11
  54. data/crates/kobako-runtime/src/vfs/namei.rs +399 -184
  55. data/crates/kobako-runtime/src/vfs/namespace.rs +123 -40
  56. data/crates/kobako-runtime/src/vfs/stat.rs +105 -16
  57. data/crates/kobako-runtime/src/vfs.rs +1 -0
  58. data/crates/kobako-runtime/src/wait.rs +75 -50
  59. data/crates/kobako-transport/CHANGELOG.md +7 -0
  60. data/crates/kobako-transport/Cargo.toml +1 -1
  61. data/crates/kobako-transport/README.md +1 -1
  62. data/crates/kobako-wasmtime/CHANGELOG.md +47 -0
  63. data/crates/kobako-wasmtime/Cargo.toml +27 -6
  64. data/crates/kobako-wasmtime/README.md +3 -3
  65. data/crates/kobako-wasmtime/src/abi.rs +2 -1
  66. data/crates/kobako-wasmtime/src/ambient.rs +11 -2
  67. data/crates/kobako-wasmtime/src/cache/unix.rs +95 -0
  68. data/crates/kobako-wasmtime/src/cache/windows.rs +359 -0
  69. data/crates/kobako-wasmtime/src/cache.rs +88 -103
  70. data/crates/kobako-wasmtime/src/driver.rs +40 -27
  71. data/crates/kobako-wasmtime/src/invocation.rs +21 -7
  72. data/crates/kobako-wasmtime/src/lib.rs +2 -0
  73. data/crates/kobako-wasmtime/src/limiter.rs +78 -25
  74. data/crates/kobako-wasmtime/src/preview1/descriptors.rs +13 -17
  75. data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +4 -5
  76. data/crates/kobako-wasmtime/src/preview1/differential.rs +1 -1
  77. data/crates/kobako-wasmtime/src/preview1/fd.rs +23 -19
  78. data/crates/kobako-wasmtime/src/preview1/mount_view.rs +130 -197
  79. data/crates/kobako-wasmtime/src/preview1/path.rs +3 -3
  80. data/crates/kobako-wasmtime/src/preview1/poll.rs +28 -22
  81. data/crates/kobako-wasmtime/src/preview1/random.rs +125 -0
  82. data/crates/kobako-wasmtime/src/preview1/testing.rs +31 -0
  83. data/crates/kobako-wasmtime/src/preview1.rs +85 -9
  84. data/crates/kobako-wasmtime/src/preview2/filesystem.rs +2 -2
  85. data/crates/kobako-wasmtime/src/preview2/host.rs +609 -249
  86. data/crates/kobako-wasmtime/src/preview2/http.rs +299 -215
  87. data/crates/kobako-wasmtime/src/preview2/io.rs +17 -4
  88. data/crates/kobako-wasmtime/src/preview2/table.rs +24 -72
  89. data/crates/kobako-wasmtime/src/trap.rs +68 -23
  90. data/crates/kobako-wasmtime/src/waits.rs +59 -0
  91. data/crates/kobako-wasmtime/src/wasi.rs +91 -10
  92. data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +13 -0
  93. data/data/kobako.wasm +0 -0
  94. data/ext/kobako/Cargo.toml +6 -2
  95. data/ext/kobako/src/escape.rs +332 -26
  96. data/ext/kobako/src/filesystem/grants.rs +5 -7
  97. data/ext/kobako/src/filesystem/ruby.rs +10 -3
  98. data/ext/kobako/src/filesystem.rs +47 -8
  99. data/ext/kobako/src/fork.rs +72 -0
  100. data/ext/kobako/src/gvl.rs +499 -76
  101. data/ext/kobako/src/handoff.rs +490 -0
  102. data/ext/kobako/src/lib.rs +10 -0
  103. data/ext/kobako/src/network.rs +5 -3
  104. data/ext/kobako/src/pinned_value.rs +28 -15
  105. data/ext/kobako/src/runtime/bridge.rs +32 -25
  106. data/ext/kobako/src/runtime.rs +74 -43
  107. data/lib/kobako/catalog/handles.rb +9 -5
  108. data/lib/kobako/codec/decoder.rb +1 -1
  109. data/lib/kobako/codec/state.rb +2 -18
  110. data/lib/kobako/codec/value_budget.rb +4 -4
  111. data/lib/kobako/codec.rb +5 -6
  112. data/lib/kobako/errors.rb +4 -7
  113. data/lib/kobako/filesystem.rb +1 -1
  114. data/lib/kobako/fork.rb +42 -0
  115. data/lib/kobako/handle.rb +1 -2
  116. data/lib/kobako/sandbox.rb +17 -36
  117. data/lib/kobako/sandbox_options.rb +7 -9
  118. data/lib/kobako/usage.rb +4 -2
  119. data/lib/kobako/version.rb +1 -1
  120. data/lib/kobako.rb +2 -2
  121. data/sig/kobako/catalog/handles.rbs +2 -0
  122. data/sig/kobako/codec/state.rbs +0 -4
  123. data/sig/kobako/codec/value_budget.rbs +1 -1
  124. data/sig/kobako/codec.rbs +2 -2
  125. data/sig/kobako/errors.rbs +0 -3
  126. data/sig/kobako/fork.rbs +17 -0
  127. data/sig/kobako/runtime.rbs +2 -2
  128. data/sig/kobako/sandbox.rbs +3 -12
  129. data/sig/kobako/sandbox_options.rbs +0 -2
  130. metadata +15 -4
  131. data/lib/kobako/pool.rb +0 -162
  132. data/sig/core/thread.rbs +0 -6
  133. data/sig/kobako/pool.rbs +0 -46
@@ -16,7 +16,6 @@ use std::ops::{Deref, DerefMut};
16
16
  use std::sync::{Arc, MutexGuard};
17
17
 
18
18
  use kobako_runtime::cred::Cred;
19
- use kobako_runtime::mount::Mount;
20
19
  use kobako_runtime::vfs::File;
21
20
  use kobako_runtime::Errno;
22
21
 
@@ -52,7 +51,7 @@ impl Resource {
52
51
  /// What one descriptor stands for, as Linux's fd table holds a `struct file`.
53
52
  pub(crate) struct Descriptor {
54
53
  pub(crate) resource: Resource,
55
- /// The guest path a preopen names; an outermost Mount's root has one.
54
+ /// The guest path a preopen names; the guest's root has one, `/`.
56
55
  pub(crate) preopen_path: Option<String>,
57
56
  }
58
57
 
@@ -81,16 +80,15 @@ pub(crate) struct Descriptors {
81
80
 
82
81
  impl Descriptors {
83
82
  /// The table every invocation starts from: stdin, then the two
84
- /// Channels, then one preopen per Mount among `mounts`, from descriptor
85
- /// 3. Each counts against the open files in `table`, as a process's
86
- /// `RLIMIT_NOFILE` counts every one it holds. Each opens, as `opener`, the
87
- /// Cred the Driver prepared, the topmost mount stacked on its root for
88
- /// `guest`, as Linux's `topmost_overmount` answers.
83
+ /// Channels, then the guest's root as the one preopen `/`, at descriptor
84
+ /// 3, where `guest` holds one. Each counts against the open files in
85
+ /// `table`, as a process's `RLIMIT_NOFILE` counts every one it holds. The
86
+ /// root opens as `opener`, the Cred the Driver prepared, the topmost mount
87
+ /// stacked on it for `guest`, as Linux's `topmost_overmount` answers.
89
88
  pub(crate) fn new(
90
89
  stdin: File,
91
90
  stdout: File,
92
91
  stderr: File,
93
- mounts: &[&Mount],
94
92
  table: &mut Table,
95
93
  (opener, guest): (&Arc<Cred>, &Arc<Cred>),
96
94
  ) -> Result<Self, Errno> {
@@ -102,13 +100,13 @@ impl Descriptors {
102
100
  let output = lend_inherited(table, OutputStream::new(Stream::from(file)))?;
103
101
  used.insert(fd, Descriptor::for_stream(Resource::Output(output)));
104
102
  }
105
- for (fd, mount) in (3..).zip(mounts) {
106
- let root = File::root(&guest.topmost_overmount(mount.mnt()), opener)?;
103
+ if let Some(root) = guest.root() {
104
+ let root = File::root(&guest.topmost_overmount(&root), opener)?;
107
105
  used.insert(
108
- fd,
106
+ 3,
109
107
  Descriptor {
110
108
  resource: Resource::File(install_inherited(table, root)?),
111
- preopen_path: Some(mount.at().to_string()),
109
+ preopen_path: Some("/".to_string()),
112
110
  },
113
111
  );
114
112
  }
@@ -185,7 +183,7 @@ impl Descriptors {
185
183
  /// Invocation holds as many files as it may.
186
184
  #[cfg(test)]
187
185
  pub(crate) fn push_file(&mut self, file: File, table: &mut Table) -> Option<u32> {
188
- let room = table.reserve_file::<FileHandle>().ok()?;
186
+ let room = table.reserve_file().ok()?;
189
187
  let fd = self.lowest_unused()?;
190
188
  let handle = table.install(room, file);
191
189
  self.place(fd, Descriptor::for_file(handle));
@@ -196,7 +194,7 @@ impl Descriptors {
196
194
  /// The handle `resource`, opened before the guest runs, takes in `table`;
197
195
  /// refused past the open file limit.
198
196
  fn install_inherited<H: Handle>(table: &mut Table, resource: H::Host) -> Result<H, Errno> {
199
- let room = table.reserve_inherited_file()?;
197
+ let room = table.reserve_file()?;
200
198
  Ok(table.install(room, resource))
201
199
  }
202
200
 
@@ -257,7 +255,6 @@ impl DerefMut for FileRefMut<'_> {
257
255
  mod tests {
258
256
  use super::*;
259
257
  use kobako_runtime::filesystem::{create_pipe_files, PipeInodeInfo};
260
- use kobako_runtime::memcg::MemoryBudget;
261
258
  use kobako_runtime::security::prepare_creds;
262
259
  use kobako_runtime::vfs::OpenFiles;
263
260
 
@@ -268,12 +265,11 @@ mod tests {
268
265
  // @behavior RT-189
269
266
  #[test]
270
267
  fn a_new_descriptor_takes_the_lowest_closed_number() {
271
- let mut table = Table::new(OpenFiles::new(None), MemoryBudget::new(None));
268
+ let mut table = Table::new(OpenFiles::new(None));
272
269
  let mut descriptors = Descriptors::new(
273
270
  pipe_end(),
274
271
  pipe_end(),
275
272
  pipe_end(),
276
- &[],
277
273
  &mut table,
278
274
  (&prepare_creds(&[], None), &prepare_creds(&[], None)),
279
275
  )
@@ -39,8 +39,9 @@ use crate::invocation::Invocation;
39
39
  use crate::trap::NO_TIMEOUT_EPOCH_DELTA;
40
40
  use crate::wasi::Wasi;
41
41
 
42
- /// The guest path both sides preopen the host directory at.
43
- const AT: &str = "/data";
42
+ /// The guest path both sides preopen the host directory at: the root, so
43
+ /// kobako's one preopen is the Bind itself, as wasmtime-wasi's is.
44
+ const AT: &str = "/";
44
45
 
45
46
  /// Each export calls one path import on descriptor 3 with the path the
46
47
  /// host placed at 1024, and the second path at 8192 where a call takes
@@ -228,10 +229,8 @@ impl HostDir {
228
229
  fs::create_dir_all(path.join("d/e")).expect("the host directory must be created");
229
230
  fs::write(path.join("a"), "hello").expect("the host file must be written");
230
231
  fs::write(path.join("d/f"), "inner").expect("the host file must be written");
231
- #[cfg(unix)]
232
232
  for (target, link) in [("a", "l"), ("d/e", "n"), ("nowhere", "g")] {
233
- std::os::unix::fs::symlink(target, path.join(link))
234
- .expect("the host link must be made");
233
+ crate::preview1::testing::symlink(target, path.join(link));
235
234
  }
236
235
  Self(path)
237
236
  }
@@ -283,7 +283,7 @@ fn through_kobako(call: &str, fd: i32, limit: Option<usize>) -> Observation {
283
283
  let mut config = Config::for_profile(Profile::Hermetic);
284
284
  config.limits.stdout_limit = limit;
285
285
  config.limits.stderr_limit = limit;
286
- let wasi = Wasi::reading_stdin(&config, STDIN.to_vec());
286
+ let wasi = Wasi::with_stdin(&config, STDIN.to_vec());
287
287
  let mut store = Store::new(engine, Invocation::new(wasi));
288
288
  store.set_epoch_deadline(NO_TIMEOUT_EPOCH_DELTA);
289
289
  let linker = imports::linker().expect("host imports must link");
@@ -126,7 +126,7 @@ fn to_filetype(file_type: FileType) -> Filetype {
126
126
  /// A `filestat` for what a Filesystem reports a path names, as `cred` sees
127
127
  /// it, at time zero where it keeps no time.
128
128
  pub(crate) fn to_filestat(cred: &Cred, stat: Kstat) -> Answer<types::Filestat> {
129
- let stat = vfs::cp_new_stat(cred, stat);
129
+ let stat = vfs::cp_new_stat(cred, stat)?;
130
130
  Ok(types::Filestat {
131
131
  dev: stat.dev,
132
132
  ino: stat.ino,
@@ -386,7 +386,7 @@ fn write_dirent(
386
386
  ) -> Answer<Option<u32>> {
387
387
  let (start, capacity) = buf;
388
388
  let at = *used;
389
- let header = to_dirent_header(emit, vfs::ino_of(cred, emit.identity))?;
389
+ let header = to_dirent_header(emit, vfs::ino_of(cred, emit.identity)?)?;
390
390
  let mut whole = true;
391
391
  for part in [&header[..], emit.name.as_bytes()] {
392
392
  let room = (capacity - *used) as usize;
@@ -600,7 +600,7 @@ mod tests {
600
600
  use crate::preview2::bindings::IoHost as _;
601
601
 
602
602
  let config = crate::config::Config::for_profile(kobako_runtime::profile::Profile::Hermetic);
603
- let mut guest = Invocation::new(Wasi::reading_stdin(&config, b"hi".to_vec()));
603
+ let mut guest = Invocation::new(Wasi::with_stdin(&config, b"hi".to_vec()));
604
604
  let read = guest.streams_input_stream_read(InputStream(1), 16).ok();
605
605
  let dropped_while_open = guest.streams_output_stream_drop(OutputStream(2)).is_ok();
606
606
  let closed = errno(super::close(guest.wasi_mut(), 1));
@@ -702,11 +702,11 @@ mod tests {
702
702
  false => Access::Read,
703
703
  };
704
704
  let mount = Mount::new(
705
- "/data",
705
+ "/",
706
706
  Filesystem::new(holds).expect("the instance must stand"),
707
707
  access,
708
708
  )
709
- .expect("/data is a guest path");
709
+ .expect("/ is a guest path");
710
710
  let start = Path::root(mount.mnt());
711
711
  vfs::do_file_open(&prepare_creds(&[], None), &start, "file", &flags_of(how))
712
712
  .unwrap_or_else(|_| panic!("the file must open"))
@@ -810,11 +810,11 @@ mod tests {
810
810
  #[test]
811
811
  fn a_directory_refuses_a_call_about_its_position() {
812
812
  let mount = Mount::new(
813
- "/data",
813
+ "/",
814
814
  Filesystem::new(HOLDS_REFUSES_CLOSE).expect("the instance must stand"),
815
815
  Access::Read,
816
816
  )
817
- .expect("/data is a guest path");
817
+ .expect("/ is a guest path");
818
818
  let mut wasi = wasi_of(vec![mount], None);
819
819
  assert_eq!(
820
820
  (
@@ -832,11 +832,11 @@ mod tests {
832
832
  fn a_descriptor_reports_how_far_it_was_opened_to_sync() {
833
833
  let tmpfs: kobako_runtime::filesystem::Tmpfs = [("f", "x")].into_iter().collect();
834
834
  let mount = Mount::new(
835
- "/data",
835
+ "/",
836
836
  Filesystem::new(tmpfs).expect("the instance must stand"),
837
837
  Access::ReadWrite,
838
838
  )
839
- .expect("/data is a guest path");
839
+ .expect("/ is a guest path");
840
840
  let mut wasi = wasi_of(vec![mount], None);
841
841
  let mut bytes = b"f".to_vec();
842
842
  let mut memory = wiggle::GuestMemory::Unshared(&mut bytes);
@@ -888,11 +888,11 @@ mod tests {
888
888
  let policy = Arc::new(CountsAsks::default());
889
889
  let tmpfs: kobako_runtime::filesystem::Tmpfs = [("f", "x")].into_iter().collect();
890
890
  let mount = Mount::new(
891
- "/data",
891
+ "/",
892
892
  Filesystem::new(tmpfs).expect("the instance must stand"),
893
893
  Access::ReadWrite,
894
894
  )
895
- .expect("/data is a guest path")
895
+ .expect("/ is a guest path")
896
896
  .with_policy(policy.clone());
897
897
  let root = Path::root(mount.mnt());
898
898
  let mut wasi = wasi_of(vec![mount], None);
@@ -921,11 +921,11 @@ mod tests {
921
921
  #[test]
922
922
  fn setting_a_descriptors_times_answers_as_a_paths_do() {
923
923
  let mount = Mount::new(
924
- "/data",
924
+ "/",
925
925
  Filesystem::new(HOLDS_REFUSES_CLOSE).expect("the instance must stand"),
926
926
  Access::Read,
927
927
  )
928
- .expect("/data is a guest path");
928
+ .expect("/ is a guest path");
929
929
  let wasi = wasi_of(vec![mount], None);
930
930
  assert_eq!(
931
931
  (
@@ -1238,6 +1238,10 @@ mod tests {
1238
1238
  }
1239
1239
 
1240
1240
  impl FileOperations for ListsNames {
1241
+ fn has_iterate_shared(&self) -> bool {
1242
+ true
1243
+ }
1244
+
1241
1245
  fn iterate_shared(
1242
1246
  &mut self,
1243
1247
  dentry: &Dentry,
@@ -1278,11 +1282,11 @@ mod tests {
1278
1282
  #[test]
1279
1283
  fn each_listed_entry_names_where_the_listing_goes_on() {
1280
1284
  let mount = Mount::new(
1281
- "/data",
1285
+ "/",
1282
1286
  Filesystem::new(ListsNames("bb")).expect("the instance must stand"),
1283
1287
  Access::Read,
1284
1288
  )
1285
- .expect("/data is a guest path");
1289
+ .expect("/ is a guest path");
1286
1290
  let mut wasi = wasi_of(vec![mount], None);
1287
1291
  let header = types::Dirent::guest_size();
1288
1292
  let dots = 2 * header + 3;
@@ -1320,11 +1324,11 @@ mod tests {
1320
1324
  fn a_listing_stops_at_a_name_no_directory_can_hold() {
1321
1325
  let listed = |bad: &'static str| {
1322
1326
  let mount = Mount::new(
1323
- "/data",
1327
+ "/",
1324
1328
  Filesystem::new(ListsNames(bad)).expect("the instance must stand"),
1325
1329
  Access::Read,
1326
1330
  )
1327
- .expect("/data is a guest path");
1331
+ .expect("/ is a guest path");
1328
1332
  let mut wasi = wasi_of(vec![mount], None);
1329
1333
  let mut bytes = vec![0u8; 256];
1330
1334
  let (first, next) = {
@@ -1383,11 +1387,11 @@ mod tests {
1383
1387
  #[test]
1384
1388
  fn a_link_to_an_absolute_path_is_not_made() {
1385
1389
  let mount = Mount::new(
1386
- "/data",
1390
+ "/",
1387
1391
  Filesystem::new(MakesLinks).expect("the instance must stand"),
1388
1392
  Access::ReadWrite,
1389
1393
  )
1390
- .expect("/data is a guest path");
1394
+ .expect("/ is a guest path");
1391
1395
  let wasi = wasi_of(vec![mount], None);
1392
1396
  let mut bytes = *b"/trelative";
1393
1397
  let mut memory = wiggle::GuestMemory::Unshared(&mut bytes);