From unknown Sun Jun 22 07:55:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#39237: coreutils cp mishandles error return from lchmod Resent-From: Rich Felker Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Wed, 22 Jan 2020 15:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 39237 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 39237@debbugs.gnu.org Cc: musl@lists.openwall.com X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.15797066775858 (code B ref -1); Wed, 22 Jan 2020 15:25:01 +0000 Received: (at submit) by debbugs.gnu.org; 22 Jan 2020 15:24:37 +0000 Received: from localhost ([127.0.0.1]:51101 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iuHrw-0001WP-CF for submit@debbugs.gnu.org; Wed, 22 Jan 2020 10:24:37 -0500 Received: from lists.gnu.org ([209.51.188.17]:42291) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iuH6p-0008Ii-Qw for submit@debbugs.gnu.org; Wed, 22 Jan 2020 09:35:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60725) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuH6n-0001m4-KJ for bug-coreutils@gnu.org; Wed, 22 Jan 2020 09:35:55 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_20,KHOP_HELO_FCRDNS, RDNS_DYNAMIC autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iuH6l-0008GJ-RD for bug-coreutils@gnu.org; Wed, 22 Jan 2020 09:35:53 -0500 Received: from 216-12-86-13.cv.mvl.ntelos.net ([216.12.86.13]:45828 helo=brightrain.aerifal.cx) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1iuH6j-0008FS-Rh for bug-coreutils@gnu.org; Wed, 22 Jan 2020 09:35:51 -0500 Received: from dalias by brightrain.aerifal.cx with local (Exim 3.15 #2) id 1iuGnV-00027r-00; Wed, 22 Jan 2020 14:15:57 +0000 Date: Wed, 22 Jan 2020 09:15:57 -0500 From: Rich Felker 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) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.12.86.13 X-Spam-Score: -1.4 (-) X-Mailman-Approved-At: Wed, 22 Jan 2020 10:24:35 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) 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