Post #3969311
2026-07-20 20:46 UTC
Fun Linux fact: If you race dup(5) and close(5), the kernel handles that fine, but it can lead to the unusual result that dup(5) returns 5.
Replies (1)
-
@madcoder@infosec.exchange 2026-07-20 21:53
@jann@infosec.exchange is that allowed? That feels unintuitive to me. I’d implicitly expect that the fd allocation for dup() must be atomic with respect to close() happening and that as a result either dup(5) EBADFs or returns != 5 XNU goes to lengths (that scale poorly) to guarantee it. And I think FreeBSD does too.