]> git.lizzy.rs Git - rust.git/commit
filedesc: don't use ioctl(FIOCLEX) on Linux
authorAleksa Sarai <cyphar@cyphar.com>
Fri, 5 Jul 2019 14:51:19 +0000 (00:51 +1000)
committerAleksa Sarai <cyphar@cyphar.com>
Wed, 10 Jul 2019 13:59:46 +0000 (23:59 +1000)
commit6031a07a464eae202cc43fbb15fada094171488d
treed7cab21a0799626ec0ddac28a5a1e4dd2c51e568
parent481068a707679257e2a738b40987246e0420e787
filedesc: don't use ioctl(FIOCLEX) on Linux

All ioctl(2)s will fail on O_PATH file descriptors on Linux (because
they use &empty_fops as a security measure against O_PATH descriptors
affecting the backing file).

As a result, File::try_clone() and various other methods would always
fail with -EBADF on O_PATH file descriptors. The solution is to simply
use F_SETFD (as is used on other unices) which works on O_PATH
descriptors because it operates through the fnctl(2) layer and not
through ioctl(2)s.

Since this code is usually only used in strange error paths (a broken or
ancient kernel), the extra overhead of one syscall shouldn't cause any
dramas. Most other systems programming languages also use the fnctl(2)
so this brings us in line with them.

Fixes: rust-lang/rust#62314
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
src/libstd/sys/unix/fd.rs