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

kernel: report entropy sources as character devices

Co-authored-by: nmzik <Nmzik@mail.ru>
This commit is contained in:
Henrique Reis Neves
2026-10-07 20:35:58 -03:00
committed by GitHub
parent 34f6fd1f5f
commit de62664908
2 changed files with 17 additions and 10 deletions
+2 -10
View File
@@ -1138,19 +1138,11 @@ int KYTY_SYSV_ABI KernelFstat(int d, FileStat* sb) {
auto wt = at; auto wt = at;
if (file->special != SpecialFile::None) { if (file->special != SpecialFile::None) {
stat.st_mode = 0020644u;
stat.st_size = 0; stat.st_size = 0;
stat.st_blksize = 512; stat.st_blksize = 512;
stat.st_blocks = 0; stat.st_blocks = 0;
SecToTimespec(&stat.st_atim, at.ToUnix()); } else if (!file->directory) {
SecToTimespec(&stat.st_mtim, wt.ToUnix());
stat.st_ctim = stat.st_atim;
stat.st_birthtim = stat.st_mtim;
*sb = stat;
return OK;
}
if (!file->directory) {
file->mutex.Lock(); file->mutex.Lock();
bool is_invalid = file->f.IsInvalid(); bool is_invalid = file->f.IsInvalid();
+15
View File
@@ -121,6 +121,20 @@ void CheckSaveRename(const std::filesystem::path &root,
"renamed save contents"); "renamed save contents");
} }
void TestRandomDevices() {
for (const auto* path : {"/dev/urandom", "/dev/random"}) {
const int fd = FileSystem::KernelOpen(path, 0, 0);
FileSystem::FileStat stat {};
Check(fd >= 3 && FileSystem::KernelFstat(fd, &stat) == OK &&
(stat.st_mode & 0170000) == 0020000,
"entropy sources are character devices");
std::array<uint8_t, 32> entropy {};
Check(FileSystem::KernelRead(fd, entropy.data(), entropy.size()) == entropy.size(),
"character device supplies requested entropy");
Check(FileSystem::KernelClose(fd) == OK, "close entropy source");
}
}
void TestSaveOpenVisibility() { void TestSaveOpenVisibility() {
constexpr char Path[] = "/savedata0/visible-save.dat"; constexpr char Path[] = "/savedata0/visible-save.dat";
constexpr char Payload[] = "saved progress"; constexpr char Payload[] = "saved progress";
@@ -1398,6 +1412,7 @@ int main(int, char**) {
TempDirectory temporary; TempDirectory temporary;
FileSystem::Initialize(); FileSystem::Initialize();
TestRandomDevices();
CheckMountRoot(temporary.Path()); CheckMountRoot(temporary.Path());
CheckUnmappedPaths(temporary.Path()); CheckUnmappedPaths(temporary.Path());
CheckArchiveMount(temporary.Path()); CheckArchiveMount(temporary.Path());