Skip to content

kernel: #! scripts, random stack and mapping addresses; net: TCP SACK and loss recovery - #117

Merged
v3nn7 merged 7 commits into
mainfrom
v3nn7/practical-euler-ot7vt8
Nov 12, 2026
Merged

v3nn7 merged 7 commits into
mainfrom
v3nn7/practical-euler-ot7vt8

Conversation

@v3nn7

@v3nn7 v3nn7 commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

What does this change?

Four changes in separate commits. The script commit was pushed to #116 a moment after that pull request was merged, so it is not in main yet; the description of #116 mentions it by mistake.

#! scripts

spawn and execve refused every file that was not an ELF executable. A file that starts with #! now runs the interpreter named on its first line (#!interpreter [argument], at most 255 bytes).

  • The interpreter gets argv = interpreter, its argument, the script's canonical path, then the caller's arguments after argv[0]. The process keeps the script's name.
  • The interpreter is found like any program (a bare name is searched in /bin and /usr/bin) and may be a script itself, four levels deep; a longer chain fails with Loop, a malformed line with BadExecutable.

AXIS script arguments

$0 is the script's path, $1..$9 its arguments, $# their number. Unquoted $@ expands to one word per argument (for a in $@ { ... }); inside double quotes it is all of them joined by spaces. # after $ no longer starts a comment; AXIS uses the shell crate's comment stripper instead of its own copy.

Random stack and mapping addresses

Every process had its stack right below 0x7FFF_FFFF_0000 and its first anonymous mapping at 0x1000_0000_0000. Each program image (spawn and execve) now gets:

  • a stack top up to 16 GiB lower, in whole pages (22 random bits);
  • a mapping base up to 1 TiB higher, in 64 KiB steps (24 random bits).

Both come from the kernel's random source. Mappings end below the lowest place a stack can be. Program segments stay at their link addresses, because the loader takes ET_EXEC only.

TCP: selective acknowledgements and loss recovery

The stack buffered out-of-order segments but acknowledged them only cumulatively, and after three duplicate ACKs it sent everything from the first loss again.

  • SACK (RFC 2018): the SYN offers SACK-permitted; a SYN-ACK carries it when the peer offered it. Every ACK sent while out-of-order data is held names it, the most recent arrival first (three blocks at most). Blocks received are merged into a scoreboard; fast recovery retransmits only the holes below the highest block. A retransmission timeout forgets the scoreboard.
  • In a SACK recovery the data in flight is counted from the scoreboard (RFC 6675's pipe) and the congestion window is not inflated by duplicate ACKs.
  • Limited transmit (RFC 3042) and, with SACK, early retransmit (RFC 5827): a loss in a small window no longer waits for the retransmission timer.
  • The out-of-order queue holds 256 segments instead of 64 (a full receive window).
  • A data segment that carries the SACK option is shortened by it, so it still fits the MSS.
  • Segments without the new options are encoded byte for byte as before.

Documentation

docs/kernel.md, docs/memory.md and docs/syscall-abi.md describe the loader changes. docs/storage.md and docs/roadmap.md said FAT32 writes its metadata through on every change; it has delayed FAT sectors and FSInfo since #41.

How was it tested?

QEMU 8.2.2 (TCG) with OVMF on Linux, test image built from the same steps as build.ps1 -NoZen -Cmdline 'test.exit boot.fast init.args=tests', -cpu qemu64,...,+smep,+smap:

CPUs Kernel self-tests User checks Exec checks
1 35 passed, 0 failed 94 passed, 1 failed 15 of 15
4 35 passed, 0 failed 94 passed, 1 failed 15 of 15
  • Self-test "program loader": the #! line parser, the argument order, a missing interpreter, a script that interprets itself, a non-ELF interpreter.
  • User check exec: #! scripts run their interpreter: AXIS scripts started by path and by interpreter name write a file that is read back; a script with arguments writes $1+$2+$# and one line per $@ word.
  • User check exec: stack and mapping addresses differ between processes: four runs of probe, for example stacks 7ffc9b83f000, 7ffe87652000, 7ffedd6db000, 7ffc6eec6000 and mappings 10ed7f8e1000, 10003b1e1000, 109772ea1000, 107726621000.
  • Desktop session (init.args=desktop, 2 CPUs) for 60 s: PRISM composes frames, no fault in the serial log.
  • cargo test --locked -p osyx-shell: 14 passed (one new).
  • scripts/test.ps1: the expected number of exec checks goes from 13 to 15.

TCP:

  • cargo test --locked -p osyx-net: 69 passed. The eight new tests in network/net/tests/sack.rs join two connections by a wire that loses chosen segments: the options through the codec, malformed options, the blocks a receiver reports, exactly the two lost segments of forty sent again without a timeout, a peer without SACK, bogus blocks, the size of a data segment with blocks, and a loss in a three-segment flight repaired without a timeout.
  • Against the Linux TCP stack: the guest on a TAP device behind a relay that drops 2 % of the data segments in each direction, init.args=tests,netbench,<tcp>,<udp>,4,tcp with scripts/net-bench-host.py, 4 MiB each way. tcpdump shows sackOK on both SYNs and SACK blocks from both sides.
Build Upload Upload stalls of 150 ms or more Segments Linux received twice Download
main (3 runs) 1.8 to 3.2 MiB/s 5 to 10 about 290 did not finish in 200 s, 3 of 3
this branch (4 runs) 3.9 to 13 MiB/s 0 to 3 1 to 25 22 to 31 MiB/s
  • The same path without loss: 63 MiB/s up, 54 MiB/s down (2 runs).
  • The functional network checks under the same 2 % loss (1 MiB echo, four concurrent connections, refused connect, loopback, non-blocking read, socket release) pass.
  • In QEMU's user network against scripts/net-host.py the same checks pass.

Limitations or screenshots

  • The one failing user check fails on main too: ipc: ordinary users cannot register services, take the display or read input.
  • In the network runs the DNS checks failed because this build machine has no outside DNS, and the port-forward check was not set up; none of them is a TCP data path.
  • The loss measurements are few runs with a wide spread, under TCG, over a link with no delay. main without loss was not measured on this path.
  • Not run: scripts/test.ps1, scripts/net-test.ps1, scripts/net-bench.ps1 and scripts/net-stress.ps1 themselves (PowerShell, Windows host), the Win32 and Zen suites (winrun under the new address layout is untested), real hardware.
  • Code addresses are not randomised; that needs position-independent (ET_DYN) programs.
  • Scripts: AT_EXECFN is the interpreter's path.
  • TCP: no D-SACK, no timestamps, no tail loss probe.

Labels

Labels: security, kernel, network

🤖 Generated with Claude Code

https://claude.ai/code/session_01Wky8K1hAgSGYFWjvQ1gDqK

spawn and execve refused every file that was not an ELF executable. A
file that starts with "#!" now runs the interpreter named on its first
line ("#!interpreter [argument]", at most 255 bytes): the interpreter
gets its argument, the script's canonical path and the caller's remaining
arguments. The interpreter is found like any program, may be a script
itself up to four levels (Loop beyond that), and a malformed line is
BadExecutable. /bin/axis already takes a script path, so AXIS scripts can
be started directly.

Self-tests cover the line parser, the argument order, a missing
interpreter, a script that interprets itself and a non-ELF interpreter;
a new ring-3 check runs AXIS scripts by path and by name (the expected
number of exec checks in test.ps1 goes from 13 to 14).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Wky8K1hAgSGYFWjvQ1gDqK
Every process had its stack right below 0x7FFF_FFFF_0000 and its first
anonymous mapping at 0x1000_0000_0000, so heap and stack addresses were
the same in every run. Each program image (spawn and execve) now gets a
stack top up to 16 GiB lower (whole pages, 22 random bits) and a mapping
base up to 1 TiB higher (64 KiB steps, 24 random bits), drawn from the
kernel's random source. Mappings end below the lowest place a stack can
be. Program segments stay at their link addresses: the loader takes
ET_EXEC only, so code addresses are not randomised yet.

probe reports its stack and first mapping address; a new ring-3 check
starts it four times and expects the addresses to differ and to lie in
the documented ranges (15 exec checks in test.ps1).

Also correct the storage documentation: FAT32 has kept dirty FAT sectors
and FSInfo in memory until the volume is quiet since #41.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Wky8K1hAgSGYFWjvQ1gDqK
@github-actions github-actions Bot added the enhancement New feature or request label Nov 11, 2026
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Pre-merge checks: Inconclusive 2

Failed Failed checks: 2 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Description check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@github-actions github-actions Bot added security Area: security kernel Area: kernel labels Nov 11, 2026
@v3nn7 v3nn7 removed the enhancement New feature or request label Nov 11, 2026 — with Claude
@codspeed

codspeed Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 10.54%

1 warning

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

❌ 1 regressed benchmark
✅ 35 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ internet_checksum[20] 942.8 ns 1,053.9 ns -10.54%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing v3nn7/practical-euler-ot7vt8 (5e4d188) with main (9e08ce6)

Open in CodSpeed

The stack buffered out-of-order segments but could only acknowledge them
cumulatively, and after three duplicate ACKs it sent everything from the
first loss again.

- The SYN offers SACK-permitted; a SYN-ACK carries it when the peer
  offered it. The codec parses and writes both options (blocks behind two
  NOPs, at most four parsed and three sent); segments without them are
  encoded byte for byte as before.
- Receiver: every ACK sent while out-of-order data is held names it, the
  range with the most recent arrival first.
- Sender: blocks inside (snd_una, snd_max] are merged into a scoreboard.
  An ACK that reports new data counts as a duplicate ACK; fast recovery
  retransmits only the holes below the highest block and does not repeat a
  hole on a partial ACK. A retransmission timeout forgets the scoreboard
  and sends everything again, as RFC 2018 asks.

Tests (network/net/tests/sack.rs) join two connections by a wire that
loses chosen segments: the options through the codec, malformed options,
the blocks a receiver reports, exactly the two lost segments sent again
out of forty, a peer without SACK, and bogus blocks.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Wky8K1hAgSGYFWjvQ1gDqK
@v3nn7 v3nn7 changed the title kernel: #! scripts; random stack and mapping addresses kernel: #! scripts, random stack and mapping addresses; net: TCP SACK Nov 12, 2026
@v3nn7 v3nn7 added the network Area: networking label Nov 12, 2026 — with Claude
A script could not see the arguments it was started with. $0 is the
script's path, $1..$9 its arguments, $# their number; unquoted $@
expands to one word per argument (for a in $@ { ... }) and inside
double quotes to all of them joined by spaces. The same names work in
expressions.

"#" after "$" no longer starts a comment; AXIS now uses the shell
crate's comment stripper instead of its own copy.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Wky8K1hAgSGYFWjvQ1gDqK
Measured against the Linux TCP stack over a TAP device with a relay that
drops 2 % of the data segments in each direction (4 MiB each way):

- Before SACK (main), the download never finished within 200 s in three
  of three runs, and the upload ran at 1.8 to 3.2 MiB/s with 5 to 10
  retransmission timeouts and about 290 segments sent again needlessly.
- The first SACK commit made the download work (1 to 7 MiB/s) but Linux
  still sent a third of the data twice, and the upload stalled on the
  timer more often than before.

Three causes, fixed here:

- The out-of-order queue held 64 segments; what arrived behind a loss
  beyond that was dropped. It holds 256 now, a full receive window.
  Download: 20 to 31 MiB/s, Linux sends about 60 segments again for about
  115 lost.
- In a SACK recovery everything up to snd_nxt counted as in flight, the
  data the peer already held included, so later holes waited for the
  window. The scoreboard gives the real figure (RFC 6675's pipe), and the
  congestion window is no longer inflated by duplicate ACKs.
- A loss in a small window (after a timeout, or the end of a transfer)
  never drew three duplicate ACKs. The first two now let one new segment
  out each (limited transmit, RFC 3042), and with SACK a flight of fewer
  than four segments with nothing left to send is repaired after one
  fewer duplicate ACK than segments (early retransmit, RFC 5827).
  Upload: 3.9 to 13 MiB/s with 0 to 3 timeouts in four runs.

A data segment sent while out-of-order data is held carries the SACK
option; its payload is now shortened by the option so the segment still
fits the MSS.

Without loss the same path runs at 63 MiB/s up and 54 MiB/s down.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Wky8K1hAgSGYFWjvQ1gDqK
@v3nn7 v3nn7 changed the title kernel: #! scripts, random stack and mapping addresses; net: TCP SACK kernel: #! scripts, random stack and mapping addresses; net: TCP SACK and loss recovery Nov 12, 2026
Parsing a segment decoded the SACK option into a 36-byte block list in
every Segment, whether or not it carried one; CodSpeed reported
tcp_parse_segment_1460 12 % slower. The parser now only checks the
option's length and keeps a slice of it; the connection decodes the
blocks when it records them.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Wky8K1hAgSGYFWjvQ1gDqK
@v3nn7
v3nn7 marked this pull request as ready for review November 12, 2026 09:00
@v3nn7
v3nn7 merged commit 2953c07 into main Nov 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel Area: kernel network Area: networking security Area: security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants