@ai-ecoverse/slicc-kernel 1.196.17 → 1.196.18

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.
@@ -5237,7 +5237,7 @@ function satisfies(version, range2) {
5237
5237
  }
5238
5238
 
5239
5239
  // src/version.ts
5240
- var KERNEL_VERSION = true ? "1.196.17" : "0.0.0-dev";
5240
+ var KERNEL_VERSION = true ? "1.196.18" : "0.0.0-dev";
5241
5241
  var OS_RELEASE = "6.0.0-slicc";
5242
5242
  function procVersion() {
5243
5243
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -10190,12 +10190,8 @@ var SpawnError = class extends Error {
10190
10190
  }
10191
10191
  };
10192
10192
  var ChangedError = class extends SpawnError {
10193
- notice;
10194
- file;
10195
- constructor(notice, file) {
10193
+ constructor() {
10196
10194
  super("EPERM");
10197
- this.notice = notice;
10198
- this.file = file;
10199
10195
  }
10200
10196
  };
10201
10197
  function interrupted(signal) {
@@ -19900,11 +19896,11 @@ function stdinMatches(rule2, stdin) {
19900
19896
  function recordable(cwd, argv) {
19901
19897
  return !hasControl2(cwd) && !argv.some(hasControl2);
19902
19898
  }
19903
- function changedText(file) {
19904
- return `sudo: ${file} changed since it was approved`;
19899
+ function changedText(word) {
19900
+ return `sudo: ${quoteWord(word)} changed since it was approved`;
19905
19901
  }
19906
- function requestedText(file) {
19907
- return `sudo: ${file} changed since it was requested`;
19902
+ function requestedText(word) {
19903
+ return `sudo: ${quoteWord(word)} changed since it was requested`;
19908
19904
  }
19909
19905
  function changedFile(approved, now) {
19910
19906
  const files = /* @__PURE__ */ new Set([...Object.keys(approved), ...Object.keys(now)]);
@@ -20371,12 +20367,12 @@ var Sudo = class {
20371
20367
  if (file.split("/").includes("..")) return physicalPathAsync(fs, file, true);
20372
20368
  return await fs.realpath?.(file, true).catch(() => file) ?? file;
20373
20369
  }
20374
- async moved({ routes }, loading2 = false) {
20370
+ async moved({ routes }) {
20375
20371
  for (const [asked, approved] of Object.entries(routes)) {
20376
20372
  const real2 = await this.real(asked).catch(() => void 0);
20377
- if (real2 !== approved) return loading2 ? real2 ?? asked : approved;
20373
+ if (real2 !== approved) return true;
20378
20374
  }
20379
- return void 0;
20375
+ return false;
20380
20376
  }
20381
20377
  async missingBacking(hashes, except) {
20382
20378
  for (const path of Object.keys(hashes)) {
@@ -20419,6 +20415,11 @@ var Sudo = class {
20419
20415
  await lstat("/");
20420
20416
  return physicalPathAsync({ lstat, readlink: (at) => fs.readlink(at) }, path, true);
20421
20417
  }
20418
+ async executablePath(fs, cred, asked) {
20419
+ const path = await this.searched(fs, cred, asked);
20420
+ const st = await fs.stat(path);
20421
+ return st.isFile && (st.mode & 73) !== 0 ? path : void 0;
20422
+ }
20422
20423
  async locate(word, cwd, reads, target) {
20423
20424
  const fs = this.o.planFs?.(reads) ?? this.o.fs;
20424
20425
  const candidates = word.includes("/") ? [askedPath(cwd, word)] : SECURE_PATH.split(":").map((dir) => `${dir}/${word}`);
@@ -20426,9 +20427,8 @@ var Sudo = class {
20426
20427
  let denial;
20427
20428
  for (const asked of candidates) {
20428
20429
  try {
20429
- const path = await this.searched(fs, cred, asked);
20430
- const st = await fs.stat(path);
20431
- if (st.isFile && (st.mode & 73) !== 0) return { path, asked };
20430
+ const path = await this.executablePath(fs, cred, asked);
20431
+ if (path !== void 0) return { path, asked };
20432
20432
  } catch (err) {
20433
20433
  const code = err.code;
20434
20434
  if (code === "EACCES") denial = failed2(code, `sudo: ${word}: Permission denied`);
@@ -20507,7 +20507,7 @@ ${SCRIPT_HELP}
20507
20507
  const [word = "", ...args] = r.argv;
20508
20508
  const argv = [r.path, ...args];
20509
20509
  if (!await this.mayAsk(self, target, r, argv)) {
20510
- const quoted = argv.map(quoteWord).join(" ");
20510
+ const quoted = r.argv.map(quoteWord).join(" ");
20511
20511
  return failed2(
20512
20512
  "EACCES",
20513
20513
  `sudo: ${self.name} may no longer ask to run ${quoted} as ${target.name}`
@@ -20527,19 +20527,19 @@ ${SCRIPT_HELP}
20527
20527
  if (located && "error" in located) return located;
20528
20528
  if (!located) {
20529
20529
  const gone = await this.missingBacking(r.bound, r.path);
20530
- return gone ? failed2("EPERM", requestedText(gone)) : failed2("ENOENT", `sudo: ${word}: command not found`);
20530
+ return gone ? failed2("EPERM", requestedText(word)) : failed2("ENOENT", `sudo: ${word}: command not found`);
20531
20531
  }
20532
20532
  const { path, asked } = located;
20533
- if (path !== r.path) return failed2("EPERM", `sudo: ${word} now runs ${path}, not ${r.path}`);
20533
+ if (path !== r.path) return failed2("EPERM", requestedText(word));
20534
20534
  const bound3 = await this.bound(path, r.cwd, asked, void 0, reads);
20535
- if (!bound3) return failed2("EPERM", requestedText(await this.missingBacking(r.bound) ?? path));
20535
+ if (!bound3) return failed2("EPERM", requestedText(word));
20536
20536
  const changed2 = changedDecision(r.bound, r, bound3, path);
20537
20537
  if (changed2 !== void 0) {
20538
20538
  const missing7 = ["chainSha256", "routeSha256"].filter(
20539
20539
  (key) => bound3[key] !== void 0 && r[key] === void 0
20540
20540
  );
20541
20541
  const hint = missing7.length && changedFile(r.bound, bound3.hashes) === void 0 ? `; the saved request lacks ${missing7.join(" and ")}; pass back the whole request from approve unchanged` : "";
20542
- return failed2("EPERM", requestedText(changed2) + hint);
20542
+ return failed2("EPERM", requestedText(word) + hint);
20543
20543
  }
20544
20544
  const now = await this.rootOnly(r.cwd, args);
20545
20545
  const flipped = Object.keys(r.rootOnly).find((at) => r.rootOnly[at] && now[at] !== true);
@@ -20574,6 +20574,11 @@ ${SCRIPT_HELP}
20574
20574
  const { caller, self, target, parsed: parsed3 } = s;
20575
20575
  const { cred } = caller;
20576
20576
  const [word = "", ...args] = parsed3.command;
20577
+ const notAllowed = () => failed2(
20578
+ "EPERM",
20579
+ `sudo: ${self.name} is not allowed to run ${parsed3.command.map(quoteWord).join(" ")} as ${target.name}`
20580
+ );
20581
+ if (!root && mine.length === 0) return notAllowed();
20577
20582
  const cwd = await this.canonical(call.cwd, cred);
20578
20583
  if (cwd === void 0 || !await this.reachable(cred, cwd)) {
20579
20584
  return failed2(
@@ -20594,13 +20599,7 @@ ${SCRIPT_HELP}
20594
20599
  const matching = applicable.filter((rule2) => pinned(rule2, bound3.hashes, bound3));
20595
20600
  const grant = () => this.grant(self, target, cred, parsed3.command, path, cwd, call.term, bound3, s.kept, asked);
20596
20601
  if (root || matching.some((rule2) => rule2.nopasswd)) return grant();
20597
- const quoted = argv.map(quoteWord).join(" ");
20598
- if (matching.length === 0) {
20599
- return failed2(
20600
- "EPERM",
20601
- `sudo: ${self.name} is not allowed to run ${quoted} as ${target.name}`
20602
- );
20603
- }
20602
+ if (matching.length === 0) return notAllowed();
20604
20603
  if (!parsed3.reset && this.timestamps.current(s.owner, s.policy, stampOf(bound3))) {
20605
20604
  this.timestamps.stamp(s.owner, s.policy, stampOf(bound3));
20606
20605
  this.logged(s, cwd, argv);
@@ -20624,14 +20623,11 @@ ${SCRIPT_HELP}
20624
20623
  if (await this.canonical(call.cwd, cred) !== cwd || !await this.reachable(cred, cwd)) {
20625
20624
  return failed2("EACCES", `sudo: ${call.cwd} changed while the request waited`);
20626
20625
  }
20627
- const moved3 = await this.moved(bound3);
20628
- if (moved3 !== void 0) return failed2("EPERM", changedText(moved3));
20626
+ if (await this.moved(bound3)) return failed2("EPERM", changedText(word));
20629
20627
  if (answer2.answer === "once" && !answer2.person) return grant();
20630
20628
  const now = await this.bound(path, cwd, asked, caller.pid);
20631
- if (!now)
20632
- return failed2("EPERM", changedText(await this.missingBacking(bound3.hashes) ?? path));
20633
- const changed2 = changedDecision(bound3.hashes, bound3, now, path);
20634
- if (changed2 !== void 0) return failed2("EPERM", changedText(changed2));
20629
+ if (!now || changedDecision(bound3.hashes, bound3, now, path) !== void 0)
20630
+ return failed2("EPERM", changedText(word));
20635
20631
  const shown2 = recordable(cwd, [...parsed3.command, ...Object.keys(bound3.hashes)]);
20636
20632
  const result = answer2.answer === "once" ? grant() : await this.always(
20637
20633
  self,
@@ -29357,8 +29353,8 @@ var WasmProcess = class _WasmProcess {
29357
29353
  close: () => source.release()
29358
29354
  });
29359
29355
  }
29360
- nonblocking(fd, requested2) {
29361
- return requested2 === true || !this.options.perCallNonblock && ((this.fds.statusFlags(fd) ?? 0) & O_NONBLOCK2) !== 0;
29356
+ nonblocking(fd, requested) {
29357
+ return requested === true || !this.options.perCallNonblock && ((this.fds.statusFlags(fd) ?? 0) & O_NONBLOCK2) !== 0;
29362
29358
  }
29363
29359
  async fdSyscall(req, cancelled) {
29364
29360
  if (isVfsSyscall(req)) return this.vfsSyscall(req);
@@ -30240,7 +30236,8 @@ var WasmProcess = class _WasmProcess {
30240
30236
  })
30241
30237
  };
30242
30238
  } catch (err) {
30243
- if (err instanceof ChangedError) return { error: err.notice, errno: err.code };
30239
+ if (err instanceof ChangedError)
30240
+ return { error: changedText(argv[0] ?? asked), errno: err.code };
30244
30241
  throw err;
30245
30242
  }
30246
30243
  }
@@ -37676,8 +37673,7 @@ function describe(req, tty) {
37676
37673
  return { argv: [req.argv0, ...req.args], tty, started: Date.now(), ...exe };
37677
37674
  }
37678
37675
  function refuseChanged(approved, now) {
37679
- const changed2 = changedFile(approved, now);
37680
- if (changed2 !== void 0) throw new ChangedError(changedText(changed2), changed2);
37676
+ if (changedFile(approved, now) !== void 0) throw new ChangedError();
37681
37677
  }
37682
37678
  var O_WRONLY2 = 1;
37683
37679
  var OUTPUT_MODE = 384;
@@ -37696,10 +37692,14 @@ function sudoCause(err) {
37696
37692
  if (typeof code !== "string") throw err;
37697
37693
  return code;
37698
37694
  }
37699
- function requested(err) {
37700
- if (err instanceof ChangedError) throw sudoFailure(err.code, requestedText(err.file));
37701
- throw err;
37702
- }
37695
+ var LOST_ROUTE = /* @__PURE__ */ new Set([
37696
+ "ENOENT",
37697
+ "ENOTDIR",
37698
+ "EACCES",
37699
+ "ELOOP",
37700
+ "ESTALE",
37701
+ "ENAMETOOLONG"
37702
+ ]);
37703
37703
  var MAX_SPAWN_TAGS = 8;
37704
37704
  function tagList(value2) {
37705
37705
  if (!Array.isArray(value2)) {
@@ -38999,16 +38999,20 @@ var Launcher = class {
38999
38999
  const refused5 = (err) => {
39000
39000
  throw codeOf9(err) === "EACCES" ? new SpawnError("EACCES") : err;
39001
39001
  };
39002
+ const lost = (err) => {
39003
+ if (LOST_ROUTE.has(codeOf9(err))) throw new ChangedError();
39004
+ throw err;
39005
+ };
39002
39006
  const { file, parentHops } = await this.execFile(
39003
39007
  req.file,
39004
39008
  req.cwd,
39005
39009
  this.execGuard(cred, ppid),
39006
39010
  ppid
39007
- ).catch(refused5);
39011
+ ).catch(grant?.files ? lost : refused5);
39008
39012
  const reads = prepared ?? (grant?.files && await this.scriptReads(grant.files, cred, ppid));
39009
39013
  if (grant?.asked && reads) {
39010
- const destination = await this.sudoer.searched(this.sudoFs(reads), cred, grant.asked).catch(refused5);
39011
- if (destination !== file) throw new ChangedError(changedText(file), file);
39014
+ const destination = await this.sudoer.executablePath(this.sudoFs(reads), cred, grant.asked).catch(lost);
39015
+ if (destination !== file) throw new ChangedError();
39012
39016
  }
39013
39017
  const plan = await this.plan(file, req.argv, req.cwd, scope, {
39014
39018
  argv0: req.argv0,
@@ -39027,10 +39031,7 @@ var Launcher = class {
39027
39031
  async checkFailedPlan(file, req, scope, grant) {
39028
39032
  const reads = this.sudoer.reads();
39029
39033
  const { planned } = await this.plan(file, req.argv, req.cwd, scope, { reads });
39030
- if (!planned) {
39031
- const gone = await this.sudoer.missingBacking(grant.files.hashes) ?? file;
39032
- throw new ChangedError(changedText(gone), gone);
39033
- }
39034
+ if (!planned) throw new ChangedError();
39034
39035
  await this.unchanged({ ...planned, reads }, file, req.cwd, grant);
39035
39036
  }
39036
39037
  async enterable(g, cwd) {
@@ -39184,26 +39185,26 @@ var Launcher = class {
39184
39185
  const now = await planned.reads.bind([file, grant.asked ?? file, ...files]);
39185
39186
  refuseChanged(approved.hashes, now.hashes);
39186
39187
  refuseChanged(approved.routes, now.routes);
39187
- if (now.chainSha256 !== approved.chainSha256) throw new ChangedError(changedText(file), file);
39188
+ if (now.chainSha256 !== approved.chainSha256) throw new ChangedError();
39188
39189
  return { pinned: approved };
39189
39190
  }
39190
39191
  approvedChain(planned, file, cwd, grant) {
39191
39192
  if (!grant) return void 0;
39192
39193
  return async (next3) => {
39193
39194
  const chain2 = (p) => [...p.via ?? [], ...p.binfmts ?? []];
39194
- if (!sameList(chain2(next3), chain2(planned))) throw new ChangedError(changedText(file), file);
39195
+ if (!sameList(chain2(next3), chain2(planned))) throw new ChangedError();
39195
39196
  await this.unchanged(next3, file, cwd, grant);
39196
39197
  };
39197
39198
  }
39198
39199
  async scriptReads(files, cred, pid) {
39199
- await this.checkRoutes(files, false);
39200
+ await this.checkRoutes(files);
39200
39201
  const snapshots = /* @__PURE__ */ new Map();
39201
39202
  const reads = this.sudoer.reads(snapshots);
39202
39203
  const guard2 = { fs: this.sudoFs(reads), dac: this.dac, cred, pid, links: cred.euid };
39203
39204
  for (const path of files.scripts ?? []) {
39204
39205
  const real2 = files.routes[path];
39205
39206
  const walked2 = await need(guard2, "open", path, R_OK, { directory: false });
39206
- if (walked2.missing || walked2.path !== real2) throw new ChangedError(changedText(path), path);
39207
+ if (walked2.missing || walked2.path !== real2) throw new ChangedError();
39207
39208
  if (!snapshots.has(real2))
39208
39209
  snapshots.set(real2, new Uint8Array(await this.noLinksFs.readFileBuffer(real2)));
39209
39210
  }
@@ -39216,14 +39217,13 @@ var Launcher = class {
39216
39217
  const real2 = files.routes[path];
39217
39218
  if (real2 === void 0) continue;
39218
39219
  const bytes = reads.snapshots.get(real2);
39219
- if (!bytes) throw new ChangedError(changedText(path), path);
39220
+ if (!bytes) throw new ChangedError();
39220
39221
  args[args.length - fromEnd] = scriptFd(fds, bytes);
39221
39222
  }
39222
39223
  return { ...planned, args };
39223
39224
  }
39224
- async checkRoutes(files, loading2) {
39225
- const file = await this.sudoer.moved(files, loading2);
39226
- if (file !== void 0) throw new ChangedError(changedText(file), file);
39225
+ async checkRoutes(files) {
39226
+ if (await this.sudoer.moved(files)) throw new ChangedError();
39227
39227
  }
39228
39228
  async pinOf(path, caller) {
39229
39229
  const { pinned: pinned2 } = caller;
@@ -39231,7 +39231,7 @@ var Launcher = class {
39231
39231
  const real2 = await this.sudoer.real(path);
39232
39232
  const approved = pinned2.routes[path];
39233
39233
  if (approved !== real2 && (approved !== void 0 || !await this.sudoer.trustedThrough(path)))
39234
- throw new ChangedError(changedText(real2), real2);
39234
+ throw new ChangedError();
39235
39235
  const hex5 = pinned2.hashes[real2];
39236
39236
  return hex5 === void 0 ? {} : { [real2]: hex5 };
39237
39237
  }
@@ -39673,7 +39673,7 @@ var Launcher = class {
39673
39673
  const own = env.HOSTNAME;
39674
39674
  if (asked.target.abi === "wasi") env.HOSTNAME = this.hostname;
39675
39675
  const planned = chosen2(asked, env);
39676
- if (req.pinned) await this.checkRoutes(req.pinned, true);
39676
+ if (req.pinned) await this.checkRoutes(req.pinned);
39677
39677
  const caller = {
39678
39678
  pid: req.ppid ?? 0,
39679
39679
  uid: req.cred.euid,
@@ -41484,12 +41484,16 @@ var Launcher = class {
41484
41484
  this.resetCatalogs();
41485
41485
  const req = { file: grant.file, argv: grant.argv, env: grant.env, cwd: grant.cwd };
41486
41486
  const ctx = { ppid: 0, cred: grant.cred, scope: "", grant };
41487
+ const word = grant.argv[0] ?? grant.asked;
41488
+ const requested = (err2) => {
41489
+ if (err2 instanceof ChangedError) throw sudoFailure(err2.code, requestedText(word));
41490
+ throw err2;
41491
+ };
41487
41492
  const planned = await this.planOne(req, ctx).catch((err2) => {
41488
41493
  if (err2 instanceof ChangedError) requested(err2);
41489
41494
  const code = sudoCause(err2);
41490
- const word = grant.argv[0] ?? grant.file;
41491
- if (code === "ENOENT") throw sudoFailure(code, `sudo: ${word}: command not found`);
41492
- throw sudoFailure(code, `sudo: ${grant.file}: ${ERRNO_TEXT[code] ?? code}`);
41495
+ if (code === "ENOENT") throw sudoFailure(code, `sudo: ${quoteWord(word)}: command not found`);
41496
+ throw sudoFailure(code, `sudo: ${quoteWord(word)}: ${ERRNO_TEXT[code] ?? code}`);
41493
41497
  });
41494
41498
  const pin = await this.unchanged(planned, grant.file, grant.cwd, grant).catch(requested);
41495
41499
  const fds = await this.sudoOutputs(options, caller, this.stackFor(tags, tagged.tagBase));
@@ -42204,9 +42208,9 @@ async function accountOf(l, user) {
42204
42208
  if (!found) throw fsError("ENOENT", `no user ${String(user)}`);
42205
42209
  return found;
42206
42210
  }
42207
- async function runAs(l, self, requested2) {
42208
- if (requested2 === void 0) return self;
42209
- const target = await accountOf(l, requested2);
42211
+ async function runAs(l, self, requested) {
42212
+ if (requested === void 0) return self;
42213
+ const target = await accountOf(l, requested);
42210
42214
  if (self.uid !== 0 && target.uid !== self.uid) {
42211
42215
  throw fsError("EPERM", `${self.name} may not run as ${target.name}`);
42212
42216
  }