Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filedesc: don't use ioctl(FIOCLEX) on Linux #62425

Merged
merged 1 commit into from
Jul 11, 2019

Commits on Jul 10, 2019

  1. 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#62314
    Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
    cyphar committed Jul 10, 2019
    Configuration menu
    Copy the full SHA
    6031a07 View commit details
    Browse the repository at this point in the history