GNU bug report logs - #43415
coreutils 8.32: install: fchmod fails with EBADF

Previous Next

Package: coreutils;

Reported by: Cameron Nemo <cnemo <at> tutanota.com>

Date: Tue, 15 Sep 2020 08:13:02 UTC

Severity: normal

To reply to this bug, email your comments to 43415 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#43415; Package coreutils. (Tue, 15 Sep 2020 08:13:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Cameron Nemo <cnemo <at> tutanota.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Tue, 15 Sep 2020 08:13:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Cameron Nemo <cnemo <at> tutanota.com>
To: bug-coreutils <at> gnu.org
Subject: coreutils 8.32: install: fchmod fails with EBADF
Date: Tue, 15 Sep 2020 03:31:43 +0200 (CEST)
[Message part 1 (text/plain, inline)]
Hello,

I am experiencing some curious behavior when trying to set the file mode using
the install command.

Version info: install (GNU coreutils) 8.32

Summary of behavior: fchmod to 1777 fails with EBADF

The log from strace shows the following:

    ...
    geteuid()                               = 0
    umask(000)                              = 022
    mkdirat(AT_FDCWD, "tmp", 01755)         = -1 EEXIST (File exists)
    openat(AT_FDCWD, "tmp", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_LARGEFILE|O_PATH|O_DIRECTORY) = 3
    fstat(3, {st_mode=S_IFDIR|S_ISVTX|0755, st_size=40, ...}) = 0
    fchmod(3, 01777)                        = -1 EBADF (Bad file descriptor)
    fcntl(3, F_GETFD)                       = 0
    fchmodat(AT_FDCWD, "/proc/self/fd/3", 01777) = 0
    close(3)                                = 0
    ...

For some odd reason, the call to fchmod is failing with EBADF.
This is causing the chmod() function to fall back to using an fd link in /proc.

Normally (i.e. when /proc is mounted) this poses no issues.
But I am trying to use the install command in a bootstrap/chroot environment,
and having to incorporate mount and unmount logic adds a significant amount of
non-idempodent complexity.

It seems like relying on the /proc link is not ideal,
and a bug is being hidden by such behavior.
Is there any chance that this can be resolved?

Regards,
--
Cameron Nemo
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#43415; Package coreutils. (Tue, 15 Sep 2020 23:50:02 GMT) Full text and rfc822 format available.

Message #8 received at 43415 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Cameron Nemo <cnemo <at> tutanota.com>
Cc: 43415 <at> debbugs.gnu.org
Subject: Re: bug#43415: coreutils 8.32: install: fchmod fails with EBADF
Date: Tue, 15 Sep 2020 16:49:04 -0700
On 9/14/20 6:31 PM, Cameron Nemo via GNU coreutils Bug Reports wrote:
> It seems like relying on the /proc link is not ideal,
> and a bug is being hidden by such behavior.
> Is there any chance that this can be resolved?

It really should be fixed in the Linux kernel: it needs a proper way to 
implement POSIX fchmodat <https://pubs.opengroup.org/onlinepubs/9699919799/> 
with the AT_SYMLINK_NOFOLLOW flag, in order to plug some security holes 
involving symlink attacks. See:

https://bugzilla.redhat.com/show_bug.cgi?id=1810141
https://lkml.org/lkml/2020/6/9/548

In the meantime, mounting /proc may be your best bet. I vaguely recall there are 
other places in glibc that assume /proc.




This bug report was last modified 4 years and 73 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.