From unknown Tue Jun 17 20:19:43 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#30534 <30534@debbugs.gnu.org> To: bug#30534 <30534@debbugs.gnu.org> Subject: Status: cp - Possible bugs when not preserving mode (explicit) and when copying special files Reply-To: bug#30534 <30534@debbugs.gnu.org> Date: Wed, 18 Jun 2025 03:19:43 +0000 retitle 30534 cp - Possible bugs when not preserving mode (explicit) and wh= en copying special files reassign 30534 coreutils submitter 30534 Declercq Laurent severity 30534 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Mon Feb 19 12:30:28 2018 Received: (at submit) by debbugs.gnu.org; 19 Feb 2018 17:30:28 +0000 Received: from localhost ([127.0.0.1]:51550 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1enpGk-00055x-4u for submit@debbugs.gnu.org; Mon, 19 Feb 2018 12:30:26 -0500 Received: from eggs.gnu.org ([208.118.235.92]:47744) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1enibJ-000121-Op for submit@debbugs.gnu.org; Mon, 19 Feb 2018 05:23:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1enib9-0001pa-Uu for submit@debbugs.gnu.org; Mon, 19 Feb 2018 05:23:08 -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.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:38742) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1enib9-0001pU-Rh for submit@debbugs.gnu.org; Mon, 19 Feb 2018 05:23:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1enib8-0004sv-J0 for bug-coreutils@gnu.org; Mon, 19 Feb 2018 05:23:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1enib3-0001kv-IU for bug-coreutils@gnu.org; Mon, 19 Feb 2018 05:23:02 -0500 Received: from so254-43.mailgun.net ([198.61.254.43]:31891) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1enib3-0001g6-D3 for bug-coreutils@gnu.org; Mon, 19 Feb 2018 05:22:57 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=i-mscp.net; q=dns/txt; s=smtp; t=1519035772; h=Content-Transfer-Encoding: Content-Type: In-Reply-To: MIME-Version: Date: Message-ID: References: To: From: Subject: Sender; bh=pL/svPIAPb8cY82EnSZdkX5gCH1B8Nd4Lb+IHoOwDs8=; b=l2Su8crX4lSEj4/Gm15xgksMSXKB9RQuBC/VszNF2mT+xYQ3oo2Oy5bE1Vq72obI16p1rJ7D K0MFlDdMPu4rz+IAHi0hENxhxOpeMt3DFTVAGgcCr4ql0mqflkFb0oLjyFFEqGYazu04NMDT x8gEIblo048rOyMF9bg4CSYZJKk= X-Mailgun-Sid: WyI2NGQwYiIsICJidWctY29yZXV0aWxzQGdudS5vcmciLCAiODY4M2EiXQ== X-Mailgun-Sending-Ip: 198.61.254.43 Received: from srv01.i-mscp.net (srv01.i-mscp.net [178.236.74.98]) by mxa.mailgun.org with ESMTP id 5a8aa57b.7f6922108730-smtp-out-n02; Mon, 19 Feb 2018 10:22:51 -0000 (UTC) Received: from [192.168.1.100] (176-154-36-71.abo.bbox.fr [176.154.36.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: l.declercq@nuxwin.com) by srv01.i-mscp.net (Postfix) with ESMTPSA id 498253E4D8 for ; Mon, 19 Feb 2018 10:22:49 +0000 (UTC) Subject: cp - Possible bugs when not preserving mode (explicit) and when copying special files From: Declercq Laurent To: bug-coreutils@gnu.org References: <4a843995-a7a5-44d5-fd0a-3dae4939a24f@nuxwin.com> <125b106a-cb48-b0b0-ac4f-6de81ae6bd89@nuxwin.com> Organization: iHMS/i-MSCP Message-ID: <01f5127f-2305-62ec-71a6-52900b4c1f0f@nuxwin.com> Date: Mon, 19 Feb 2018 11:22:48 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <125b106a-cb48-b0b0-ac4f-6de81ae6bd89@nuxwin.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -3.8 (---) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Mon, 19 Feb 2018 12:30:24 -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: -3.8 (---) I think that I did found at least two bugs in cp(1) command when the --no-preserve=mode option is involved and when copying special file. I describe each of them below. 1. Mode set on special files seem to be wrong: Original file to copy: prw-rw-rw- 1 root staff 0 févr. 18 18:59 spfile cp(1) command (run as root user): cp -r --no-preserve=mode spfile spfile_copy Current result: prwxr-xr-x 1 root staff 0 févr. 18 22:01 spfile_copy Expected result (considering UMASK 0022): prw-r--r-- 1 root staff 0 févr. 18 22:01 spfile_copy The current behavior is due to the fact that mode used is 0777 while 0666 should be used for files. Possible fix: Differentiate directories from files in the copy_internal function. 2. Non-permission bits are preserved, even when the --no-preserve=mode option is involved. Original file to copy: prwSrw-rw- 1 root staff 0 févr. 18 18:59 spfile cp(1) command (run as root user): cp -r --no-preserve=mode spfile spfile_copy Current result: prwsr-xr-x 1 root staff 0 févr. 18 22:05 spfile_copy Expected result (considering UMASK 0022 and without the first bug above): prw-r--r-- 1 root staff 0 févr. 18 22:05 spfile_copy Possible solution: Clear-out non-permission bits before calling mknod() and similar Environment: Linux jessie64 3.16.0-5-amd64 #1 SMP Debian 3.16.51-3+deb8u1 (2018-01-08) x86_64 GNU/Linux Checked against latest coreutils version. From debbugs-submit-bounces@debbugs.gnu.org Mon Feb 19 22:26:52 2018 Received: (at 30534) by debbugs.gnu.org; 20 Feb 2018 03:26:52 +0000 Received: from localhost ([127.0.0.1]:51969 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1enyZw-00072G-7U for submit@debbugs.gnu.org; Mon, 19 Feb 2018 22:26:52 -0500 Received: from mail.magicbluesmoke.com ([82.195.144.49]:53820) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1enyZu-000726-4k for 30534@debbugs.gnu.org; Mon, 19 Feb 2018 22:26:50 -0500 Received: from localhost.localdomain (unknown [76.21.115.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.magicbluesmoke.com (Postfix) with ESMTPSA id 915F39E43; Tue, 20 Feb 2018 03:26:48 +0000 (GMT) Subject: Re: bug#30534: cp - Possible bugs when not preserving mode (explicit) and when copying special files To: Declercq Laurent , 30534@debbugs.gnu.org References: <4a843995-a7a5-44d5-fd0a-3dae4939a24f@nuxwin.com> <125b106a-cb48-b0b0-ac4f-6de81ae6bd89@nuxwin.com> <01f5127f-2305-62ec-71a6-52900b4c1f0f@nuxwin.com> From: =?UTF-8?Q?P=c3=a1draig_Brady?= Message-ID: <635e2a9a-6ea8-7b43-abba-a663fc213693@draigBrady.com> Date: Mon, 19 Feb 2018 19:26:46 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <01f5127f-2305-62ec-71a6-52900b4c1f0f@nuxwin.com> Content-Type: multipart/mixed; boundary="------------319F347D8760926188D2DFC8" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 30534 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: 0.0 (/) This is a multi-part message in MIME format. --------------319F347D8760926188D2DFC8 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 19/02/18 02:22, Declercq Laurent wrote: > I think that I did found at least two bugs in cp(1) command when the > --no-preserve=mode option is involved and when copying special file. I > describe each of them below. > > 1. Mode set on special files seem to be wrong: > > Original file to copy: prw-rw-rw- 1 root staff 0 févr. 18 18:59 spfile > cp(1) command (run as root user): cp -r --no-preserve=mode spfile > spfile_copy > > Current result: > > prwxr-xr-x 1 root staff 0 févr. 18 22:01 spfile_copy > > Expected result (considering UMASK 0022): > > prw-r--r-- 1 root staff 0 févr. 18 22:01 spfile_copy > > The current behavior is due to the fact that mode used is 0777 while > 0666 should be used for files. > > Possible fix: Differentiate directories from files in the copy_internal > function. Thanks for the clear details. The attached should fix this up. > 2. Non-permission bits are preserved, even when the --no-preserve=mode > option is involved. > > Original file to copy: prwSrw-rw- 1 root staff 0 févr. 18 18:59 spfile > cp(1) command (run as root user): cp -r --no-preserve=mode spfile > spfile_copy > > Current result: > > prwsr-xr-x 1 root staff 0 févr. 18 22:05 spfile_copy I'm not seeing this. I get 'x' rather than 's' here (and '-' with the fix) > Expected result (considering UMASK 0022 and without the first bug above): > > prw-r--r-- 1 root staff 0 févr. 18 22:05 spfile_copy thanks! Pádraig --------------319F347D8760926188D2DFC8 Content-Type: text/x-patch; name="cp-default-perms.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="cp-default-perms.patch" =46rom 71e05111fa9dd6a4ad29630752d95289cb6d0274 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?P=3DC3=3DA1draig=3D20Brady?=3D Date: Mon, 19 Feb 2018 19:10:14 -0800 Subject: [PATCH] cp: set appropriate default permissions for special file= s This issue was introduced in commit v8.19-145-g24ebca6 * src/copy.c (copy_internal): When setting default permissions to use with --no-preserve=3Dmode, only set executable bits for directories or sockets. * NEWS: Mention the fix. * tests/cp/preserve-mode.sh: Add a test case. Fixes https://bugs.gnu.org/30534 --- NEWS | 5 +++++ src/copy.c | 6 ++++-- tests/cp/preserve-mode.sh | 10 +++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 8a9e09e..5fa6928 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,11 @@ GNU coreutils NEWS = -*- outline -*- that caused -u to sometimes override -n. [bug introduced with coreutils-7.1] =20 + 'cp -a --no-preserve=3Dmode' now sets appropriate default permissions + for non regular files like fifos and character device nodes etc. + Previously it would have set executable bits on created special files.= + [bug introduced with coreutils-8.20] + =20 * Noteworthy changes in release 8.29 (2017-12-27) [stable] =20 diff --git a/src/copy.c b/src/copy.c index e050d41..233b498 100644 --- a/src/copy.c +++ b/src/copy.c @@ -1378,7 +1378,7 @@ preserve_metadata: } else if (x->explicit_no_preserve_mode) { - if (set_acl (dst_name, dest_desc, 0666 & ~cached_umask ()) !=3D 0)= + if (set_acl (dst_name, dest_desc, MODE_RW_UGO & ~cached_umask ()) = !=3D 0) return_val =3D false; } else if (omitted_permissions) @@ -2860,7 +2860,9 @@ copy_internal (char const *src_name, char const *ds= t_name, } else if (x->explicit_no_preserve_mode) { - if (set_acl (dst_name, -1, 0777 & ~cached_umask ()) !=3D 0) + int default_permissions =3D S_ISDIR (src_mode) || S_ISSOCK (src_mo= de) + ? S_IRWXUGO : MODE_RW_UGO; + if (set_acl (dst_name, -1, default_permissions & ~cached_umask ())= !=3D 0) return false; } else diff --git a/tests/cp/preserve-mode.sh b/tests/cp/preserve-mode.sh index 1cd173a..3b0aca8 100755 --- a/tests/cp/preserve-mode.sh +++ b/tests/cp/preserve-mode.sh @@ -19,7 +19,7 @@ . "${srcdir=3D.}/tests/init.sh"; path_prepend_ ./src print_ver_ cp =20 -get_mode() { ls -ld "$1" | cut -b-10; } +get_mode() { stat -c%f "$1"; } =20 rm -f a b c umask 0022 @@ -47,4 +47,12 @@ chmod 600 a cp --no-preserve=3Dmode --preserve=3Dall a b || fail=3D1 test "$(get_mode a)" =3D "$(get_mode b)" || fail=3D1 =20 +#fifo test +if mkfifo fifo; then + cp -a --no-preserve=3Dmode fifo fifo_copy || fail=3D1 + #ensure default perms set appropriate for non regular files + #which wasn't done between v8.20 and 8.29 inclusive + test "$(get_mode fifo)" =3D "$(get_mode fifo_copy)" || fail=3D1 +fi + Exit $fail --=20 2.9.3 --------------319F347D8760926188D2DFC8-- From debbugs-submit-bounces@debbugs.gnu.org Tue Feb 20 03:05:00 2018 Received: (at 30534) by debbugs.gnu.org; 20 Feb 2018 08:05:00 +0000 Received: from localhost ([127.0.0.1]:52096 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eo2v6-0005gE-Bk for submit@debbugs.gnu.org; Tue, 20 Feb 2018 03:05:00 -0500 Received: from so254-43.mailgun.net ([198.61.254.43]:35812) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eo2v4-0005fz-K9 for 30534@debbugs.gnu.org; Tue, 20 Feb 2018 03:04:59 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=i-mscp.net; q=dns/txt; s=smtp; t=1519113893; h=Content-Type: In-Reply-To: MIME-Version: Date: Message-ID: From: References: To: Subject: Sender; bh=zjQC5GLaOPL0WY6P96MS75qfU8fqARXa2A5zVOsdHjI=; b=YFxA3rdD8860EzNWC/YPGgEDqvP07WMXJZlHXUZdyL+Z0JU4cm9ks930K29rDUCG6cC5cNsk 5jtapk4z/4QYqRyQLuedTNQeCkJS1qkz3gxfYIKGOgSEFN88p9Rwn6z0tCwtlJtG3OE6N9vM bZnGTIUdgANTVSfPj0hSKDd0kok= X-Mailgun-Sid: WyI3M2M0NCIsICIzMDUzNEBkZWJidWdzLmdudS5vcmciLCAiODY4M2EiXQ== X-Mailgun-Sending-Ip: 198.61.254.43 Received: from srv01.i-mscp.net (srv01.i-mscp.net [178.236.74.98]) by mxa.mailgun.org with ESMTP id 5a8bd6a4.7f293c6b9378-smtp-out-n03; Tue, 20 Feb 2018 08:04:52 -0000 (UTC) Received: from [192.168.1.100] (176-154-36-71.abo.bbox.fr [176.154.36.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: l.declercq@nuxwin.com) by srv01.i-mscp.net (Postfix) with ESMTPSA id 30D2C3E4DA; Tue, 20 Feb 2018 08:04:50 +0000 (UTC) Subject: Re: bug#30534: cp - Possible bugs when not preserving mode (explicit) and when copying special files To: =?UTF-8?Q?P=c3=a1draig_Brady?= , 30534@debbugs.gnu.org References: <4a843995-a7a5-44d5-fd0a-3dae4939a24f@nuxwin.com> <125b106a-cb48-b0b0-ac4f-6de81ae6bd89@nuxwin.com> <01f5127f-2305-62ec-71a6-52900b4c1f0f@nuxwin.com> <635e2a9a-6ea8-7b43-abba-a663fc213693@draigBrady.com> From: Declercq Laurent Organization: iHMS/i-MSCP Message-ID: <5dfe7b17-ef82-3752-eede-ea923c0c7067@nuxwin.com> Date: Tue, 20 Feb 2018 09:04:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <635e2a9a-6ea8-7b43-abba-a663fc213693@draigBrady.com> Content-Type: multipart/mixed; boundary="------------59CD68E987AE19E2C3CB4528" Content-Language: fr X-Spam-Score: 0.3 (/) X-Debbugs-Envelope-To: 30534 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: 0.3 (/) This is a multi-part message in MIME format. --------------59CD68E987AE19E2C3CB4528 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Le 20/02/2018 à 04:26, Pádraig Brady a écrit : >> 2. Non-permission bits are preserved, even when the --no-preserve=mode >> option is involved. >> >> Original file to copy: prwSrw-rw- 1 root staff 0 févr. 18 18:59 spfile >> cp(1) command (run as root user): cp -r --no-preserve=mode spfile >> spfile_copy >> >> Current result: >> >> prwsr-xr-x 1 root staff 0 févr. 18 22:05 spfile_copy > I'm not seeing this. I get 'x' rather than 's' here (and '-' with the fix) > >> Expected result (considering UMASK 0022 and without the first bug above): >> >> prw-r--r-- 1 root staff 0 févr. 18 22:05 spfile_copy > thanks! > Pádraig > I'll make a new try, providing you relevant STRACE(1) output if necessary. Thank you for your fast reaction. --------------59CD68E987AE19E2C3CB4528 Content-Type: text/x-vcard; charset=utf-8; name="l_declercq.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="l_declercq.vcf" begin:vcard fn:Laurent Declercq n:Declercq;Laurent org:i-MSCP adr;quoted-printable:;;23 rue des Lavandi=C3=A8res;Essons;Calvados;14220;FRANCE email;internet:l.declercq@nuxwin.com title:CEO & Lead Developer tel;work:+33 750 246 177 tel;home:+33 231 930 054 tel;cell:+33 750 246 177 url:https://i-mscp.net/ version:2.1 end:vcard --------------59CD68E987AE19E2C3CB4528-- From debbugs-submit-bounces@debbugs.gnu.org Sat Feb 24 21:24:22 2018 Received: (at 30534-done) by debbugs.gnu.org; 25 Feb 2018 02:24:22 +0000 Received: from localhost ([127.0.0.1]:59315 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eplzC-0007En-6y for submit@debbugs.gnu.org; Sat, 24 Feb 2018 21:24:22 -0500 Received: from mail.magicbluesmoke.com ([82.195.144.49]:49410) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eplzB-0007Ef-86 for 30534-done@debbugs.gnu.org; Sat, 24 Feb 2018 21:24:21 -0500 Received: from localhost.localdomain (unknown [76.21.115.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.magicbluesmoke.com (Postfix) with ESMTPSA id 7AA139BEB; Sun, 25 Feb 2018 02:24:19 +0000 (GMT) Subject: Re: bug#30534: cp - Possible bugs when not preserving mode (explicit) and when copying special files To: Declercq Laurent , 30534-done@debbugs.gnu.org References: <4a843995-a7a5-44d5-fd0a-3dae4939a24f@nuxwin.com> <125b106a-cb48-b0b0-ac4f-6de81ae6bd89@nuxwin.com> <01f5127f-2305-62ec-71a6-52900b4c1f0f@nuxwin.com> <635e2a9a-6ea8-7b43-abba-a663fc213693@draigBrady.com> <5dfe7b17-ef82-3752-eede-ea923c0c7067@nuxwin.com> From: =?UTF-8?Q?P=c3=a1draig_Brady?= Message-ID: Date: Sat, 24 Feb 2018 18:24:17 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <5dfe7b17-ef82-3752-eede-ea923c0c7067@nuxwin.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 30534-done 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: 0.0 (/) On 20/02/18 00:04, Declercq Laurent wrote: > Le 20/02/2018 à 04:26, Pádraig Brady a écrit : >>> 2. Non-permission bits are preserved, even when the --no-preserve=mode >>> option is involved. >>> >>> Original file to copy: prwSrw-rw- 1 root staff 0 févr. 18 18:59 spfile >>> cp(1) command (run as root user): cp -r --no-preserve=mode spfile >>> spfile_copy >>> >>> Current result: >>> >>> prwsr-xr-x 1 root staff 0 févr. 18 22:05 spfile_copy >> I'm not seeing this. I get 'x' rather than 's' here (and '-' with the fix) >> >>> Expected result (considering UMASK 0022 and without the first bug above): >>> >>> prw-r--r-- 1 root staff 0 févr. 18 22:05 spfile_copy >> thanks! >> Pádraig >> > > I'll make a new try, providing you relevant STRACE(1) output if necessary. > > Thank you for your fast reaction. > I've pushed this fix. Whether setuid is cleared may be file system dependent. set_acl() corresponds to a setxattr() here, and that was enough to clear the setuid perm on various file systems here at least. We can expand on this in future if needed, which would be better as a separate patch anyway. cheers, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Sat Feb 24 21:43:11 2018 Received: (at 30534-done) by debbugs.gnu.org; 25 Feb 2018 02:43:11 +0000 Received: from localhost ([127.0.0.1]:59325 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1epmHO-0007fz-Q2 for submit@debbugs.gnu.org; Sat, 24 Feb 2018 21:43:11 -0500 Received: from so254-43.mailgun.net ([198.61.254.43]:15984) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1epmHN-0007fk-30 for 30534-done@debbugs.gnu.org; Sat, 24 Feb 2018 21:43:09 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=i-mscp.net; q=dns/txt; s=smtp; t=1519526582; h=Content-Type: In-Reply-To: MIME-Version: Date: Message-ID: From: References: To: Subject: Sender; bh=R2vFVBz3fQFxmGYCuubnjXEnES0EyFVuIrQXK5v0e64=; b=lsA0MOYpDZljUarxFgj7BO2wiReyTRGxBm8dZbkLXZrtA28l868HvossMpU/VBnSH9q72fhQ cBh+vcMRUF9cFx8oPUihxfk1LjN9c0S9gIBRvRYGy1x1xmPGXF7PhV4J7sTRqcI6OSEE+lzz zi8qb9EhenrNx/Eq9tu8SGwZPEM= X-Mailgun-Sid: WyJjMzMzNCIsICIzMDUzNC1kb25lQGRlYmJ1Z3MuZ251Lm9yZyIsICI4NjgzYSJd X-Mailgun-Sending-Ip: 198.61.254.43 Received: from srv01.i-mscp.net (srv01.i-mscp.net [178.236.74.98]) by mxa.mailgun.org with ESMTP id 5a9222b6.7fbed87c32d0-smtp-out-n02; Sun, 25 Feb 2018 02:43:02 -0000 (UTC) Received: from [192.168.1.100] (176-154-36-71.abo.bbox.fr [176.154.36.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: l.declercq@nuxwin.com) by srv01.i-mscp.net (Postfix) with ESMTPSA id BA5C73E4E7; Sun, 25 Feb 2018 02:42:58 +0000 (UTC) Subject: Re: bug#30534: cp - Possible bugs when not preserving mode (explicit) and when copying special files To: =?UTF-8?Q?P=c3=a1draig_Brady?= , 30534-done@debbugs.gnu.org References: <4a843995-a7a5-44d5-fd0a-3dae4939a24f@nuxwin.com> <125b106a-cb48-b0b0-ac4f-6de81ae6bd89@nuxwin.com> <01f5127f-2305-62ec-71a6-52900b4c1f0f@nuxwin.com> <635e2a9a-6ea8-7b43-abba-a663fc213693@draigBrady.com> <5dfe7b17-ef82-3752-eede-ea923c0c7067@nuxwin.com> From: Declercq Laurent Organization: iHMS/i-MSCP Message-ID: Date: Sun, 25 Feb 2018 03:42:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------2FBE102738343419C8CF591C" Content-Language: fr X-Spam-Score: 0.3 (/) X-Debbugs-Envelope-To: 30534-done 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: 0.3 (/) This is a multi-part message in MIME format. --------------2FBE102738343419C8CF591C Content-Type: multipart/alternative; boundary="------------17BA6FF4036715955BBE8F41" --------------17BA6FF4036715955BBE8F41 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Le 25/02/2018 à 03:24, Pádraig Brady a écrit : > On 20/02/18 00:04, Declercq Laurent wrote: >> Le 20/02/2018 à 04:26, Pádraig Brady a écrit : >>>> 2. Non-permission bits are preserved, even when the --no-preserve=mode >>>> option is involved. >>>> >>>> Original file to copy: prwSrw-rw- 1 root staff 0 févr. 18 18:59 spfile >>>> cp(1) command (run as root user): cp -r --no-preserve=mode spfile >>>> spfile_copy >>>> >>>> Current result: >>>> >>>> prwsr-xr-x 1 root staff 0 févr. 18 22:05 spfile_copy >>> I'm not seeing this. I get 'x' rather than 's' here (and '-' with the fix) >>> >>>> Expected result (considering UMASK 0022 and without the first bug above): >>>> >>>> prw-r--r-- 1 root staff 0 févr. 18 22:05 spfile_copy >>> thanks! >>> Pádraig >>> >> I'll make a new try, providing you relevant STRACE(1) output if necessary. >> >> Thank you for your fast reaction. >> > I've pushed this fix. > > Whether setuid is cleared may be file system dependent. > set_acl() corresponds to a setxattr() here, > and that was enough to clear the setuid perm on various > file systems here at least. > > We can expand on this in future if needed, > which would be better as a separate patch anyway. > > cheers, > Pádraig. That is exactly what a strace showed me: setxattr() doesn't remove non-permission bits while with the explicit no-preserve=mode option, we could expect them to goes away. From my point of view, there should be a new option, allowing us to explicitely discard ACL too, eg: no-preserve=mode,acl and then, enforce usage of chmod in such a case instead of relying on setxattr(). That is just an idea through, that  would make us able to not break old behavior for those relying on it. Yes, that is system dependent. Should I create another issue for that issue? Anyway, thank for your involvement here. That is much appreciated. -- Laurent Declercq iHMS/i-MSCP CEO & Lead Developer ------------------------------------------------------------------------ This message and any attachment are intended solely for the addressees and are confidential. iHMS/i-MSCP, including any part representing these entities may not be held responsible for their contents whose accuracy and completeness cannot be guaranteed over the Internet. Unauthorized use, disclosure, distribution, copying, or any part thereof is strictly prohibited. If you are not the intended recipient of this message, please notify the sender immediately and delete it. ------------------------------------------------------------------------ --------------17BA6FF4036715955BBE8F41 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
Le 25/02/2018 à 03:24, Pádraig Brady a écrit :
On 20/02/18 00:04, Declercq Laurent wrote:
Le 20/02/2018 à 04:26, Pádraig Brady a écrit :
2. Non-permission bits are preserved, even when the --no-preserve=mode
option is involved.

Original file to copy: prwSrw-rw- 1 root staff 0 févr. 18 18:59 spfile
cp(1) command (run as root user): cp -r --no-preserve=mode spfile
spfile_copy

Current result:

prwsr-xr-x 1 root staff 0 févr. 18 22:05 spfile_copy
I'm not seeing this. I get 'x' rather than 's' here (and '-' with the fix)

Expected result (considering UMASK 0022 and without the first bug above):

prw-r--r-- 1 root staff 0 févr. 18 22:05 spfile_copy
thanks!
Pádraig

I'll make a new try, providing you relevant STRACE(1) output if necessary.

Thank you for your fast reaction.

I've pushed this fix.

Whether setuid is cleared may be file system dependent.
set_acl() corresponds to a setxattr() here,
and that was enough to clear the setuid perm on various
file systems here at least.

We can expand on this in future if needed,
which would be better as a separate patch anyway.

cheers,
Pádraig.
That is exactly what a strace showed me: setxattr() doesn't remove non-permission bits while with the explicit no-preserve=mode option, we could expect them to goes away.

From my point of view, there should be a new option, allowing us to explicitely discard ACL too, eg: no-preserve=mode,acl and then, enforce usage of chmod in such a case instead of relying on setxattr(). That is just an idea through, that  would make us able to not break old behavior for those relying on it.

Yes, that is system dependent. Should I create another issue for that issue?

Anyway, thank for your involvement here. That is much appreciated.

--

Laurent Declercq
iHMS/i-MSCP CEO & Lead Developer


This message and any attachment are intended solely for the addressees and are
confidential. iHMS/i-MSCP, including any part representing these entities may
not be held responsible for their contents whose accuracy and completeness cannot
be guaranteed over the Internet. Unauthorized use, disclosure, distribution, copying,
or any part thereof is strictly prohibited. If you are not the intended recipient of
this message, please notify the sender immediately and delete it.


--------------17BA6FF4036715955BBE8F41-- --------------2FBE102738343419C8CF591C Content-Type: text/x-vcard; charset=utf-8; name="l_declercq.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="l_declercq.vcf" begin:vcard fn:Laurent Declercq n:Declercq;Laurent org:i-MSCP adr;quoted-printable:;;23 rue des Lavandi=C3=A8res;Essons;Calvados;14220;FRANCE email;internet:l.declercq@nuxwin.com title:CEO & Lead Developer tel;work:+33 750 246 177 tel;home:+33 231 930 054 tel;cell:+33 750 246 177 url:https://i-mscp.net/ version:2.1 end:vcard --------------2FBE102738343419C8CF591C-- From unknown Tue Jun 17 20:19:43 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 25 Mar 2018 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator