| ... | @@ -1755,7 +1755,7 @@ const getrandom_use_libc = @TypeOf(posix.system.getrandom) != void and (native_o | ... | @@ -1755,7 +1755,7 @@ const getrandom_use_libc = @TypeOf(posix.system.getrandom) != void and (native_o |
| 1755 | .patch = 0, | 1755 | .patch = 0, |
| 1756 | })); | 1756 | })); |
| 1757 | | 1757 | |
| 1758 | const use_dev_urandom = getrandom_use_libc and native_os == .linux; | 1758 | const use_dev_urandom = !getrandom_use_libc and native_os == .linux; |
| 1759 | | 1759 | |
| 1760 | fn async( | 1760 | fn async( |
| 1761 | userdata: ?*anyopaque, | 1761 | userdata: ?*anyopaque, |
| ... | @@ -3711,10 +3711,12 @@ fn dirOpenFilePosix( | ... | @@ -3711,10 +3711,12 @@ fn dirOpenFilePosix( |
| 3711 | }, | 3711 | }, |
| 3712 | }; | 3712 | }; |
| 3713 | | 3713 | |
| | 3714 | const mode: posix.mode_t = 0; |
| | 3715 | |
| 3714 | const fd: posix.fd_t = fd: { | 3716 | const fd: posix.fd_t = fd: { |
| 3715 | const syscall: Syscall = try .start(); | 3717 | const syscall: Syscall = try .start(); |
| 3716 | while (true) { | 3718 | while (true) { |
| 3717 | const rc = openat_sym(dir.handle, sub_path_posix, os_flags, @as(posix.mode_t, 0)); | 3719 | const rc = openat_sym(dir.handle, sub_path_posix, os_flags, mode); |
| 3718 | switch (posix.errno(rc)) { | 3720 | switch (posix.errno(rc)) { |
| 3719 | .SUCCESS => { | 3721 | .SUCCESS => { |
| 3720 | syscall.finish(); | 3722 | syscall.finish(); |
| ... | @@ -4143,9 +4145,11 @@ fn dirOpenDirPosix( | ... | @@ -4143,9 +4145,11 @@ fn dirOpenDirPosix( |
| 4143 | if (@hasField(posix.O, "PATH") and !options.iterate) | 4145 | if (@hasField(posix.O, "PATH") and !options.iterate) |
| 4144 | flags.PATH = true; | 4146 | flags.PATH = true; |
| 4145 | | 4147 | |
| | 4148 | const mode: posix.mode_t = 0; |
| | 4149 | |
| 4146 | const syscall: Syscall = try .start(); | 4150 | const syscall: Syscall = try .start(); |
| 4147 | while (true) { | 4151 | while (true) { |
| 4148 | const rc = openat_sym(dir.handle, sub_path_posix, flags, @as(usize, 0)); | 4152 | const rc = openat_sym(dir.handle, sub_path_posix, flags, mode); |
| 4149 | switch (posix.errno(rc)) { | 4153 | switch (posix.errno(rc)) { |
| 4150 | .SUCCESS => { | 4154 | .SUCCESS => { |
| 4151 | syscall.finish(); | 4155 | syscall.finish(); |
| ... | @@ -15270,7 +15274,7 @@ fn randomSecure(userdata: ?*anyopaque, buffer: []u8) Io.RandomSecureError!void { | ... | @@ -15270,7 +15274,7 @@ fn randomSecure(userdata: ?*anyopaque, buffer: []u8) Io.RandomSecureError!void { |
| 15270 | } | 15274 | } |
| 15271 | } | 15275 | } |
| 15272 | | 15276 | |
| 15273 | fn getRandomFd(t: *Threaded) posix.fd_t { | 15277 | fn getRandomFd(t: *Threaded) Io.RandomSecureError!posix.fd_t { |
| 15274 | { | 15278 | { |
| 15275 | t.mutex.lock(); | 15279 | t.mutex.lock(); |
| 15276 | defer t.mutex.unlock(); | 15280 | defer t.mutex.unlock(); |
| ... | @@ -15279,13 +15283,15 @@ fn getRandomFd(t: *Threaded) posix.fd_t { | ... | @@ -15279,13 +15283,15 @@ fn getRandomFd(t: *Threaded) posix.fd_t { |
| 15279 | if (t.random_file.fd != -1) return t.random_file.fd; | 15283 | if (t.random_file.fd != -1) return t.random_file.fd; |
| 15280 | } | 15284 | } |
| 15281 | | 15285 | |
| | 15286 | const mode: posix.mode_t = 0; |
| | 15287 | |
| 15282 | const fd: posix.fd_t = fd: { | 15288 | const fd: posix.fd_t = fd: { |
| 15283 | const syscall: Syscall = try .start(); | 15289 | const syscall: Syscall = try .start(); |
| 15284 | while (true) { | 15290 | while (true) { |
| 15285 | const rc = openat_sym(posix.AT.FDCWD, "/dev/urandom", .{ | 15291 | const rc = openat_sym(posix.AT.FDCWD, "/dev/urandom", .{ |
| 15286 | .ACCMODE = .RDONLY, | 15292 | .ACCMODE = .RDONLY, |
| 15287 | .CLOEXEC = true, | 15293 | .CLOEXEC = true, |
| 15288 | }, 0); | 15294 | }, mode); |
| 15289 | switch (posix.errno(rc)) { | 15295 | switch (posix.errno(rc)) { |
| 15290 | .SUCCESS => { | 15296 | .SUCCESS => { |
| 15291 | syscall.finish(); | 15297 | syscall.finish(); |
| ... | @@ -15295,11 +15301,7 @@ fn getRandomFd(t: *Threaded) posix.fd_t { | ... | @@ -15295,11 +15301,7 @@ fn getRandomFd(t: *Threaded) posix.fd_t { |
| 15295 | try syscall.checkCancel(); | 15301 | try syscall.checkCancel(); |
| 15296 | continue; | 15302 | continue; |
| 15297 | }, | 15303 | }, |
| 15298 | else => { | 15304 | else => return syscall.fail(error.EntropyUnavailable), |
| 15299 | syscall.endSyscall(); | | |
| 15300 | t.random_file.fd = -2; | | |
| 15301 | return error.EntropyUnavailable; | | |
| 15302 | }, | | |
| 15303 | } | 15305 | } |
| 15304 | } | 15306 | } |
| 15305 | }; | 15307 | }; |
| ... | @@ -15314,7 +15316,7 @@ fn getRandomFd(t: *Threaded) posix.fd_t { | ... | @@ -15314,7 +15316,7 @@ fn getRandomFd(t: *Threaded) posix.fd_t { |
| 15314 | switch (sys.errno(sys.statx(fd, "", std.os.linux.AT.EMPTY_PATH, .{ .TYPE = true }, &statx))) { | 15316 | switch (sys.errno(sys.statx(fd, "", std.os.linux.AT.EMPTY_PATH, .{ .TYPE = true }, &statx))) { |
| 15315 | .SUCCESS => { | 15317 | .SUCCESS => { |
| 15316 | syscall.finish(); | 15318 | syscall.finish(); |
| 15317 | if (!statx.mask.TYPE) return error.Unexpected; | 15319 | if (!statx.mask.TYPE) return error.EntropyUnavailable; |
| 15318 | t.mutex.lock(); // Another thread might have won the race. | 15320 | t.mutex.lock(); // Another thread might have won the race. |
| 15319 | defer t.mutex.unlock(); | 15321 | defer t.mutex.unlock(); |
| 15320 | if (t.random_file.fd >= 0) { | 15322 | if (t.random_file.fd >= 0) { |
| ... | @@ -15332,10 +15334,7 @@ fn getRandomFd(t: *Threaded) posix.fd_t { | ... | @@ -15332,10 +15334,7 @@ fn getRandomFd(t: *Threaded) posix.fd_t { |
| 15332 | try syscall.checkCancel(); | 15334 | try syscall.checkCancel(); |
| 15333 | continue; | 15335 | continue; |
| 15334 | }, | 15336 | }, |
| 15335 | else => { | 15337 | else => return syscall.fail(error.EntropyUnavailable), |
| 15336 | t.random_file.fd = -2; | | |
| 15337 | return error.EntropyUnavailable; | | |
| 15338 | }, | | |
| 15339 | } | 15338 | } |
| 15340 | } | 15339 | } |
| 15341 | }, | 15340 | }, |
| ... | @@ -15346,6 +15345,8 @@ fn getRandomFd(t: *Threaded) posix.fd_t { | ... | @@ -15346,6 +15345,8 @@ fn getRandomFd(t: *Threaded) posix.fd_t { |
| 15346 | switch (posix.errno(fstat_sym(fd, &stat))) { | 15345 | switch (posix.errno(fstat_sym(fd, &stat))) { |
| 15347 | .SUCCESS => { | 15346 | .SUCCESS => { |
| 15348 | syscall.finish(); | 15347 | syscall.finish(); |
| | 15348 | t.mutex.lock(); // Another thread might have won the race. |
| | 15349 | defer t.mutex.unlock(); |
| 15349 | if (t.random_file.fd >= 0) { | 15350 | if (t.random_file.fd >= 0) { |
| 15350 | posix.close(fd); | 15351 | posix.close(fd); |
| 15351 | return t.random_file.fd; | 15352 | return t.random_file.fd; |
| ... | @@ -15361,10 +15362,7 @@ fn getRandomFd(t: *Threaded) posix.fd_t { | ... | @@ -15361,10 +15362,7 @@ fn getRandomFd(t: *Threaded) posix.fd_t { |
| 15361 | try syscall.checkCancel(); | 15362 | try syscall.checkCancel(); |
| 15362 | continue; | 15363 | continue; |
| 15363 | }, | 15364 | }, |
| 15364 | else => { | 15365 | else => return syscall.fail(error.EntropyUnavailable), |
| 15365 | t.random_file.fd = -2; | | |
| 15366 | return error.EntropyUnavailable; | | |
| 15367 | }, | | |
| 15368 | } | 15366 | } |
| 15369 | } | 15367 | } |
| 15370 | }, | 15368 | }, |