From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.2 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by inbox.vuxu.org (OpenSMTPD) with SMTP id 6217b5b2 for ; Wed, 22 Jan 2020 14:16:12 +0000 (UTC) Received: (qmail 14267 invoked by uid 550); 22 Jan 2020 14:16:10 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 14235 invoked from network); 22 Jan 2020 14:16:10 -0000 Date: Wed, 22 Jan 2020 09:15:57 -0500 From: Rich Felker To: bug-coreutils@gnu.org Cc: musl@lists.openwall.com Message-ID: <20200122141557.GA8157@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: Rich Felker Subject: [musl] coreutils cp mishandles error return from lchmod cp (and perhaps other utilities) are treating EOPNOTSUPP from lchmod as a hard error rather than an indication that the system does not support modes for symlinks. This recently came up on https://bugs.gentoo.org/687236#c17 where users are claiming recent changes to gnulib made the problem go away, but I'm not sure what the mechanism was, since the underlying problem is still there. Users only hit the problem on cross-compiling, presumably due to logic in how gnulib replaces lchmod, and due to gnulib's replacement wrongly following symlinks (it just #defines it to chmod). gnulib documents that the caller must check before calling lchmod that the file is not a symlink, but this is unsafe in the presence of race conditions, While lchmod is not a standard function, fchmodat with AT_SYMLINK_NOFOLLOW is, and specifies EOPNOTSUPP for the case where the system does not support modes on symlinks. musl provides lchmod as a simple wrapper for this, yielding a version that is safe. coreutils should be opting to use the system-provided lchmod, which is safe, and correctly handling error returns (silently treating EOPNOTSUPP as success) rather than as hard errors. Rich