kernel: report /dev/random and /dev/urandom as character devices #1140

Manually merged
github merged 1 commit from gh-pr/1140/head into gh-pr/1140/base 2026-11-26 09:44:42 +00:00
Owner

@⁠NevesHenry on GitHub · 2026-10-07 13:45 UTC · original
NevesHenry:kernel/random-device-fstat → main · +17 −10 · 2 files · 1 commits · merged 2026-10-07 23:35 UTC

Summary

KernelFstat reports every descriptor that isn't a directory as a regular file (S_IFREG). That includes /dev/random and /dev/urandom, which KernelOpen handles as SpecialFile::Random. On FreeBSD these are character devices: devfs creates random with mode 0644 and adds urandom as an alias of it (randomdev.c, releng/11.0).

libsodium checks for this. randombytes_sysrandom_random_dev_open() opens /dev/urandom, then /dev/random. It keeps a descriptor only when fstat reports S_ISCHR and closes it otherwise (source). If neither device passes, randombytes_sysrandom_init() calls sodium_misuse() (source), which ends in abort() (source).

This change makes KernelFstat report these descriptors as S_IFCHR | 0644.

Evidence

#774 Warhammer Age of Sigmar: Realms of Ruin (PPSA06927, build 8b095ca) doesn't boot: Guest abort() at libC.cpp:254. The log ends with that exact sequence. Each device is opened read-only, checked with fstat and closed, then the abort follows:

	 path = /dev/urandom
	 flags = 00000000
	Open device: /dev/urandom, [ok]
	KernelFstat: /dev/urandom
	Close: /dev/urandom
	 path = /dev/random
	 flags = 00000000
	Open device: /dev/random, [ok]
	KernelFstat: /dev/random
	Close: /dev/random
Guest abort diagnostics:

I'm inferring libsodium from this call sequence; I haven't looked inside the game's binary. I don't have the game, so I can't say how far it gets with this change.

I also searched the other logs attached to issues here. 104 logs from 85 issues open /dev/urandom, and #774 is the only one where the game aborts afterwards.

Testing

CheckRandomDevices in tests/KernelFileSystemTests.cpp opens both devices. It checks that fstat reports a character device, reads 16 bytes from each and closes it.

I used the same local-only setup as in #1109 to run kernel_file_system_tests: an Ubuntu 24.04 container (clang 18) with no window or Vulkan device, and Memory::InvalidateMemory returning early when no GPU context is installed. Results:

  • with main's fileSystem.cpp, the test aborts at "random devices are readable character devices"
  • with this change, all cases in the file pass

In the same container, kyty_emulator and kyty_tests build, and the 35 ctest tests that don't need a Vulkan device pass. The other 15 all run shader_recompiler_compute_tests, which can't create a Vulkan instance there (ErrorIncompatibleDriver). They fail the same way with main's fileSystem.cpp.

The changed lines are clean under clang-format 22.1.3. Not built on Windows or macOS.

AI assistance

An AI coding assistant (Claude Code) helped me search the issue logs, compare the log with the libsodium and FreeBSD sources, write the change and the test, and run the builds above. I reviewed the code and the test results. All communication on this PR comes from me.

🤖 Generated with Claude Code

**@⁠NevesHenry** on GitHub · 2026-10-07 13:45 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1140) `NevesHenry:kernel/random-device-fstat` → `main` · +17 −10 · 2 files · 1 commits · merged 2026-10-07 23:35 UTC ## Summary `KernelFstat` reports every descriptor that isn't a directory as a regular file (`S_IFREG`). That includes `/dev/random` and `/dev/urandom`, which `KernelOpen` handles as `SpecialFile::Random`. On FreeBSD these are character devices: devfs creates `random` with mode 0644 and adds `urandom` as an alias of it ([randomdev.c](https://github.com/freebsd/freebsd-src/blob/8d2708de5d6112a492744d367cfdfb8fd219227a/sys/dev/random/randomdev.c#L374-L376), releng/11.0). libsodium checks for this. `randombytes_sysrandom_random_dev_open()` opens `/dev/urandom`, then `/dev/random`. It keeps a descriptor only when `fstat` reports `S_ISCHR` and closes it otherwise ([source](https://github.com/jedisct1/libsodium/blob/9dcaa81943641565585482c20f2a211200aa1d89/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c#L191-L237)). If neither device passes, `randombytes_sysrandom_init()` calls `sodium_misuse()` ([source](https://github.com/jedisct1/libsodium/blob/9dcaa81943641565585482c20f2a211200aa1d89/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c#L293-L296)), which ends in `abort()` ([source](https://github.com/jedisct1/libsodium/blob/9dcaa81943641565585482c20f2a211200aa1d89/src/libsodium/sodium/core.c#L188-L202)). This change makes `KernelFstat` report these descriptors as `S_IFCHR | 0644`. ## Evidence #774 Warhammer Age of Sigmar: Realms of Ruin (PPSA06927, build 8b095ca) doesn't boot: `Guest abort()` at `libC.cpp:254`. The log ends with that exact sequence. Each device is opened read-only, checked with fstat and closed, then the abort follows: ``` path = /dev/urandom flags = 00000000 Open device: /dev/urandom, [ok] KernelFstat: /dev/urandom Close: /dev/urandom path = /dev/random flags = 00000000 Open device: /dev/random, [ok] KernelFstat: /dev/random Close: /dev/random Guest abort diagnostics: ``` I'm inferring libsodium from this call sequence; I haven't looked inside the game's binary. I don't have the game, so I can't say how far it gets with this change. I also searched the other logs attached to issues here. 104 logs from 85 issues open `/dev/urandom`, and #774 is the only one where the game aborts afterwards. ## Testing `CheckRandomDevices` in `tests/KernelFileSystemTests.cpp` opens both devices. It checks that `fstat` reports a character device, reads 16 bytes from each and closes it. I used the same local-only setup as in #1109 to run `kernel_file_system_tests`: an Ubuntu 24.04 container (clang 18) with no window or Vulkan device, and `Memory::InvalidateMemory` returning early when no GPU context is installed. Results: - with main's `fileSystem.cpp`, the test aborts at "random devices are readable character devices" - with this change, all cases in the file pass In the same container, `kyty_emulator` and `kyty_tests` build, and the 35 ctest tests that don't need a Vulkan device pass. The other 15 all run `shader_recompiler_compute_tests`, which can't create a Vulkan instance there (`ErrorIncompatibleDriver`). They fail the same way with main's `fileSystem.cpp`. The changed lines are clean under clang-format 22.1.3. Not built on Windows or macOS. ## AI assistance An AI coding assistant (Claude Code) helped me search the issue logs, compare the log with the libsodium and FreeBSD sources, write the change and the test, and run the builds above. I reviewed the code and the test results. All communication on this PR comes from me. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:44:40 +00:00
github manually merged commit 1b97321944 into gh-pr/1140/base 2026-11-26 09:44:42 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-07 13:51 UTC · original

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 76264cd9-4fff-461c-9ba9-3d04e17e1c4d
📥 Commits

Reviewing files that changed from the base of the PR and between d2413fc2eb and 4b3984e5e3d69f98f6da484901357df58ee8a119.

📒 Files selected for processing (2)
  • src/kernel/fileSystem.cpp
  • tests/KernelFileSystemTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

KernelFstat now reports special files with character-device mode while retaining zero size and block counts. The filesystem tests check that /dev/urandom and /dev/random open, report character-device mode, return 16 bytes, and close successfully.

Suggested reviewers: nmzik

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 4b398

The change reports the two random-device paths as character devices and tests their status and readability; no actionable merge blocker is evident.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the change: reporting /dev/random and /dev/urandom as character devices.
Description check ✅ Passed The description explains the change, its motivation, and the tests performed. It is directly related to the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-07 13:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1140#issuecomment-6039401499) <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1140?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `76264cd9-4fff-461c-9ba9-3d04e17e1c4d` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between d2413fc2ebd91d1b7234197c2dd5bd48e1cb6a51 and 4b3984e5e3d69f98f6da484901357df58ee8a119. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/kernel/fileSystem.cpp` * `tests/KernelFileSystemTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough `KernelFstat` now reports special files with character-device mode while retaining zero size and block counts. The filesystem tests check that `/dev/urandom` and `/dev/random` open, report character-device mode, return 16 bytes, and close successfully. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"4b3984e5e3d69f98f6da484901357df58ee8a119" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `4b398` <!-- final_review_risk_coverage:{"sourceCommitId":"4b3984e5e3d69f98f6da484901357df58ee8a119","coveredCommitId":"4b3984e5e3d69f98f6da484901357df58ee8a119","kind":"reviewed"} --> The change reports the two random-device paths as character devices and tests their status and readability; no actionable merge blocker is evident. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :--------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly identifies the change: reporting `/dev/random` and `/dev/urandom` as character devices. | | Description check | ✅ Passed | The description explains the change, its motivation, and the tests performed. It is directly related to the changeset. | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1140)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
This discussion has been locked. Commenting is limited to contributors.
No description provided.