Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

lowest-number-reuse is also a robustness issue. If multi-threaded programs UAF or double-free a file descriptor they likely end up touching FDs owned by other parts of the program which can result in various kinds of corruption and memory-unsafety. Assigning numbers from a large domain, either randomly or from a permutation sequence, would massively reduce that probability and manifest in prompt errors instead.




I want an alternative unix ABI that doesn't guarantee lowest-reuse for this exact reason. I suppose you could (almost) just hijack the close call and replace it with a dup2 of /dev/null or something (but then you'd miss close errors).

It could be emulated in userspace with F_DUPFD. But that's costly because the kernel table is optimized for dense data, not sparse.

The rust standard library aborts the program in debug builds when it detects a double-close; at that point corruption may already have occurred but better than nothing.


> The rust standard library aborts the program in debug builds when it detects a double-close

On EBADF? Neat.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: