Skip to content

0.17.0 --- an enumeration ends with its directory, a context has the stack it asks for, and input can arrive unaltered - #37

Merged
Sunrisepeak merged 5 commits into
mainfrom
openkal-0.16.0
Oct 24, 2026
Merged

Sunrisepeak merged 5 commits into
mainfrom
openkal-0.16.0

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

Fixes #34. Supersedes #35, whose commit is carried with its author.

  • An enumeration ends when its directory is closed (End a directory's unfinished enumerations when the directory is closed #35), and kal_fs_list_next refuses a closed directory or an iterator that is not an open listing of the directory given, without reading through it (clause 6.7). A close that races a read of the same enumeration marks the listing and the reader releases it (clause 6.6).
  • A started context's stack is 8 MiB unless more is asked for, with a 256 KiB inaccessible guard beneath it; the guard exceeds the 69,008-byte frame measured in the C library above at -O0. kal_task_start_sized (openkal 0.16) gives at least the size asked for and never less than the default.
  • KAL_TERM_PASS_INPUT is ISTRIP | INLCR | IGNCR | ICRNL: read as set only where all four are clear; set, all four are cleared; clear, ICRNL is restored.

Observed in this package's tests: the leak through /proc/self/fd, the refusals, two hundred close/read races; a pseudo terminal delivering the return key and Ctrl+J as 0x0d and 0x0a with the position set; a least stack size as room for 1, 16 and 64 MiB. The specification's suite at openkal-0.16.0: 201 held, 0 did not hold.

yspbwx2010 and others added 5 commits October 25, 2026 05:29
kal_fs_list_begin opens a descriptor of its own for each enumeration, and
only kal_fs_list_next released it, on reaching the end. kal_fs_close_dir
closed the directory's descriptor and nothing else, so an enumeration
abandoned part-way kept its descriptor and buffer until the program
exited, although fs.h says that closing the directory that produced an
iterator releases it.

Keep the listings not yet read to the end on a list, with the directory
each was begun on. kal_fs_close_dir ends that directory's listings before
the descriptor is closed, and kal_fs_list_next takes a listing off the
list when it reaches the end or fails. The close now frees the listing,
so an iterator used after its directory is closed uses freed memory
instead of going on with the directory.

The test begins and abandons 64 enumerations and compares the number of
open descriptors before and after. It fails without the change.
…ot free what another context is reading

The listing an iterator names is found among the open ones rather than read
through, so a closed directory (a released handle, clause 6.7) or a stale
iterator is refused with kal_err_invalid. A listing another context is inside
kal_fs_list_next with is marked by the close and released by that context on its
way out, so the close does not free a buffer a getdents64 is writing into
(clause 6.6). Two contexts reading one enumeration take turns.
…e is asked for, and kal_task_start_sized asks

The stack was one anonymous mapping from kal_alloc with nothing beneath it, and
the C library above cannot place a guard of its own. It is now mapped with a
256 KiB inaccessible guard below it, larger than the 69,008-byte frame measured
in that library at -O0. The default is the host's, 8 MiB, which costs address
space and not memory. kal_task_start_sized (openkal 0.16) gives at least the
size asked for and never less than the default; above a C runtime the request
is passed to it.
Read as set only where ISTRIP, INLCR, IGNCR and ICRNL are all clear; set, all
four are cleared; clear, ICRNL is restored, which is what this kernel ordinarily
applies. A position already at the requested value is not written.
The enumeration of a closed directory is refused and a close racing a read
ends it safely; a pseudo terminal this test makes delivers the return key and
Ctrl+J as two bytes once KAL_TERM_PASS_INPUT is set, and the kernel's ordinary
rewriting when it is clear; a context started with a least stack size is told
at least that size and has the room.
@Sunrisepeak
Sunrisepeak merged commit 88b82e0 into main Oct 24, 2026
4 checks passed
@Sunrisepeak
Sunrisepeak deleted the openkal-0.16.0 branch October 24, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants