From unknown Sun Jun 22 07:54:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#8752: cp: fchown called before fchmod, unable to set file mode Resent-From: Milan Novak Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Sat, 28 May 2011 17:27:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 8752 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 8752@debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.130660359621100 (code B ref -1); Sat, 28 May 2011 17:27:01 +0000 Received: (at submit) by debbugs.gnu.org; 28 May 2011 17:26:36 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QQNHX-0005UG-TU for submit@debbugs.gnu.org; Sat, 28 May 2011 13:26:36 -0400 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QQJHk-0007NM-U5 for submit@debbugs.gnu.org; Sat, 28 May 2011 09:10:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QQJHe-0006a8-I5 for submit@debbugs.gnu.org; Sat, 28 May 2011 09:10:27 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,T_DKIM_INVALID, T_TO_NO_BRKTS_FREEMAIL autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([140.186.70.17]:34644) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQJHe-0006a4-GZ for submit@debbugs.gnu.org; Sat, 28 May 2011 09:10:26 -0400 Received: from eggs.gnu.org ([140.186.70.92]:37165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQJHd-0000x1-9p for bug-coreutils@gnu.org; Sat, 28 May 2011 09:10:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QQJHb-0006Zt-TQ for bug-coreutils@gnu.org; Sat, 28 May 2011 09:10:25 -0400 Received: from mail-iw0-f169.google.com ([209.85.214.169]:38882) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQJHb-0006Zo-OE for bug-coreutils@gnu.org; Sat, 28 May 2011 09:10:23 -0400 Received: by iwg8 with SMTP id 8so3051294iwg.0 for ; Sat, 28 May 2011 06:10:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=pdy4V5Y1JMOQSUqMSr6m9FZ9DFcO7cH0WcN4rEzeKHQ=; b=I8lSCgQs1Nmaf3N+GqDGGcXFblVwWvBKODChvaKnqoV2TqGBuhYQQHq0bLiDV6hpAE m/BMgvSna17jiMQMUKRcqYQ7TBp3xbFhcgqEzeZHmpst6JNtFz4Nnf+ARe8Iw/XjFrtR SGB6oaFCrk5vqLzX3gIQv3TKBA5NsyUVGiIEo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=UC/NA+pPxbEuBy372WOOK3x1SF6awP3vHgy1vRnSWbK10js0iCNGJknUvG9YFMJ94h 08iKlgpcZAexaPQAKAjf+O0vnA6GapQD7qLmJ3bMhNtvntcAmzs7fEHyPu1dL3A662RR TPL3WT2nQkwb8btTvnRE4+1A01aGrLR9bCAuE= MIME-Version: 1.0 Received: by 10.231.111.228 with SMTP id t36mr3651582ibp.59.1306588222009; Sat, 28 May 2011 06:10:22 -0700 (PDT) Received: by 10.231.15.4 with HTTP; Sat, 28 May 2011 06:10:21 -0700 (PDT) Date: Sat, 28 May 2011 15:10:21 +0200 Message-ID: From: Milan Novak Content-Type: multipart/alternative; boundary=0016e6471764d730f804a455c6e5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.17 X-Spam-Score: -5.9 (-----) X-Mailman-Approved-At: Sat, 28 May 2011 13:26:34 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.9 (-----) --0016e6471764d730f804a455c6e5 Content-Type: text/plain; charset=ISO-8859-1 Hello, I believe that cp uses wrong order of syscalls when applying target file attributes; fchown(2) is called before fchmod(2). As a result it looses access to target file and is unable to apply file mode correctly; error message is as follows "cp: preserving permissions for `target': Not owner" The problem arises when -p (preserve attributes) is present and file owner is different from user doing the copy. Same operation using cp on hp-ux 11.31 is successfull, since hp-ux cp calls chmod(2) before chown(2). Please let me know what do you think about changing order of fchown(2) <=> fchmod(2). Kind Regards, Milan --- hp@mtest:/home/hp/coreutils $ id uid=1058(hp) gid=20(users) groups=65535(last) hp@mtest:/home/hp/coreutils $ ll source target target not found -rwxrwxrwx 1 elzu radia 32 May 20 15:50 source hp@mtest:/home/hp/coreutils $ tusc -o tusc_hpuxcp.out /usr/bin/cp -p source target; echo $? ; ll source target 0 -rwxrwxrwx 1 elzu radia 32 May 20 15:50 source -rwxrwxrwx 1 elzu radia 32 May 20 15:50 target hp@mtest:/home/hp/coreutils $ rm -f target hp@mtest:/home/hp/coreutils $ tusc -o tusc_gnucp.out coreutils-8.11/src/cp -p source target; echo $? ; ll source target coreutils-8.11/src/cp: preserving permissions for `target': Not owner #>>>> ERROR 1 -rwxrwxrwx 1 elzu radia 32 May 20 15:50 source -rwx------ 1 elzu radia 32 May 20 15:50 target #>>> already owned by user elzu, so chmod executed as user hp fails hp@mtest:/home/hp/coreutils $ coreutils-8.11/src/cp --version | head -1 cp (GNU coreutils) 8.11 hp@mtest:/home/hp/coreutils $ uname -a HP-UX mtest B.11.31 U ia64 2263078376 unlimited-user license hp@mtest:/home/hp/coreutils $ egrep "target|chown|chmod|exit" tusc_* tusc_hpuxcp.out:stat64("target", 0x7fffeec0) ............................................ ERR#2 ENT tusc_hpuxcp.out:stat64("target", 0x40021110) ............................................ ERR#2 ENT tusc_hpuxcp.out:stat64("target", 0x40021110) ............................................ ERR#2 ENT tusc_hpuxcp.out:access("target", F_OK) .................................................. ERR#2 ENT tusc_hpuxcp.out:open("target", O_WRONLY|O_CREAT|O_TRUNC|0x800, 0) ....................... = 6 tusc_hpuxcp.out:utime("target", 0x7fffe5f0) ............................................. = 0 tusc_hpuxcp.out:chmod("target", 0100777) ................................................ = 0 tusc_hpuxcp.out:chown("target", 1021, 1005) ............................................. = 0 tusc_hpuxcp.out:chmod("target", 0100777) ................................................ ERR#1 EPM tusc_hpuxcp.out:exit(0) ................................................................. WIFE) tusc_gnucp.out:stat64("target", 0x7fffedf0) ............................................ ERR#2T tusc_gnucp.out:stat64("target", 0x7fffeac0) ............................................ ERR#2T tusc_gnucp.out:open("target", O_WRONLY|O_CREAT|O_EXCL|0x800, 0700) ..................... = 5 tusc_gnucp.out:utime("target", 0x7fffe7a8) ............................................. = 0 tusc_gnucp.out:fchown(5, 1021, 1005) ................................................... = 0 #>>> the problem is HERE, CHOWN goes before CHMOD; tusc_gnucp.out:fchmod(5, 0100777) ...................................................... ERR#1M #>>> this fails, since user hp is not the owner of the file anymore tusc_gnucp.out:exit(1) ................................................................. WIFEX) --0016e6471764d730f804a455c6e5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

Hello,=A0

I= believe that cp uses wrong order of syscalls when applying target file att= ributes; fchown(2) is called before fchmod(2).=A0
As a result it looses = access to target file and is unable to apply file mode correctly; error mes= sage is as follows=A0
"cp: preserving permissions for `target': Not owner"=A0

The problem aris= es when -p (preserve attributes) is present and file owner is different fro= m user doing the copy.=A0

Same operation= using cp on hp-ux 11.31 is successfull, since hp-ux cp calls chmod(2) befo= re chown(2).=A0

Please let me know what do you think about changing order of fchown(2) <= =3D> fchmod(2).=A0

Kind Regards,=A0
Milan=A0

---=A0

hp@m= test:/home/hp/coreutils $ id=A0
uid=3D1058(hp) gid=3D20(users) groups=3D= 65535(last)=A0
hp@mtest:/home/hp/coreutils $ ll source target=A0
targ= et not found=A0
-rwxrwxrwx 1 elzu radia 32 May 20 15:50 source=A0
hp@mtest:/home/hp/core= utils $ tusc -o tusc_hpuxcp.out /usr/bin/cp -p source target; echo $? ; ll = source target=A0
0=A0
-rwxrwxrwx 1 elzu radia 32 May 20 15:50 source= =A0
-rwxrwxrwx 1 elzu radia 32 May 20 15:50 target=A0
hp@mtest:/home/hp/core= utils $ rm -f target=A0

hp@mtest:/home/hp/coreutils $ tusc -o tusc_gnucp.out coreutils= -8.11/src/cp -p source target; echo $? ; ll source target=A0
coreutils-8.11/src/cp: preserving permissions for `target': Not owner = #>>>> ERROR=A0
1=A0
-rwxrwxrwx 1 elzu radia 32 May 20 15:= 50 source=A0
-rwx------ 1 elzu radia 32 May 20 15:50 target #>>&g= t; already owned by user elzu, so chmod executed as user hp fails=A0

hp@mtest:/home= /hp/coreutils $ coreutils-8.11/src/cp --version | head -1=A0
cp (GNU cor= eutils) 8.11=A0

hp@mtest:/home/hp/coreutils $ uname -a=A0
HP-UX mtest B.11.31 U ia64 226= 3078376 unlimited-user license=A0

hp@mtest:/home/hp/coreutils $ egrep "target|cho= wn|chmod|exit" tusc_*=A0
tusc_hpuxcp.out:stat64("target", 0x7fffeec0) ....................= ........................ ERR#2 ENT=A0
tusc_hpuxcp.out:stat64("targe= t", 0x40021110) ............................................ ERR#2 ENT= =A0
tusc_hpuxcp.out:stat64("target", 0x40021110) ....................= ........................ ERR#2 ENT=A0
tusc_hpuxcp.out:access("targe= t", F_OK) .................................................. ERR#2 ENT= =A0
tusc_hpuxcp.out:open("target", O_WRONLY|O_CREAT|O_TRUNC|0x800, 0)= ....................... =3D 6=A0
tusc_hpuxcp.out:utime("target&quo= t;, 0x7fffe5f0) ............................................. =3D 0=A0
t= usc_hpuxcp.out:chmod("target", 0100777) .........................= ....................... =3D 0=A0
tusc_hpuxcp.out:chown("target", 1021, 1005) .....................= ........................ =3D 0=A0
tusc_hpuxcp.out:chmod("target&quo= t;, 0100777) ................................................ ERR#1 EPM=A0<= br> tusc_hpuxcp.out:exit(0) ...................................................= .............. WIFE)=A0

tusc_gnucp.out:stat64("target", 0x7fffedf0) ........= .................................... ERR#2T=A0
tusc_gnucp.out:stat64("target", 0x7fffeac0) .....................= ....................... ERR#2T=A0
tusc_gnucp.out:open("target"= , O_WRONLY|O_CREAT|O_EXCL|0x800, 0700) ..................... =3D 5=A0
tu= sc_gnucp.out:utime("target", 0x7fffe7a8) ........................= ..................... =3D 0=A0
tusc_gnucp.out:fchown(5, 1021, 1005) ......................................= ............. =3D 0 =A0 =A0 #>>> the problem is HERE, CHOWN goes b= efore CHMOD;=A0
tusc_gnucp.out:fchmod(5, 0100777) ......................= ................................ ERR#1M =A0 =A0 #>>> this fails, s= ince user hp is not the owner of the file anymore=A0
tusc_gnucp.out:exit(1) ....................................................= ............. WIFEX)=A0

--0016e6471764d730f804a455c6e5-- From unknown Sun Jun 22 07:54:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#8752: cp: fchown called before fchmod, unable to set file mode Resent-From: Paul Eggert Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Sun, 29 May 2011 19:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8752 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Milan Novak Cc: 8752@debbugs.gnu.org Received: via spool by 8752-submit@debbugs.gnu.org id=B8752.130669728331264 (code B ref 8752); Sun, 29 May 2011 19:29:01 +0000 Received: (at 8752) by debbugs.gnu.org; 29 May 2011 19:28:03 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QQleb-00088D-Ly for submit@debbugs.gnu.org; Sun, 29 May 2011 15:28:02 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QQleY-00087u-OD for 8752@debbugs.gnu.org; Sun, 29 May 2011 15:28:00 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 95FE139E8106; Sun, 29 May 2011 12:27:52 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ny4eWo5OsPuY; Sun, 29 May 2011 12:27:51 -0700 (PDT) Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id CC30F39E8100; Sun, 29 May 2011 12:27:51 -0700 (PDT) Message-ID: <4DE29E32.3010307@cs.ucla.edu> Date: Sun, 29 May 2011 12:27:46 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10 MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Score: -3.0 (---) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.0 (---) On 05/28/11 06:10, Milan Novak wrote: > I believe that cp uses wrong order of syscalls when applying target file > attributes; fchown(2) is called before fchmod(2). > As a result it looses access to target file and is unable to apply file mode > correctly; error message is as follows > "cp: preserving permissions for `target': Not owner" The general idea in coreutils is given in the following comment in lib/dirchownmod.c: /* On some systems, chown clears S_ISUID and S_ISGID, so do chown before chmod. On older System V hosts, ordinary users can give their files away via chown; don't worry about that here, since users shouldn't do that. */ HP-UX is one of the "older System V hosts" that by default allows ordinary users to give their files away. This is a mild security hole, so modern operating systems typically don't allow it. To get this safer behavior on HP-UX, you can do something like the following, as the superuser: # echo "-n CHOWN" >>/etc/privgrp # setprivgrp -f /etc/privgroup I suppose coreutils might be modified to work in this (from our point of view) dinosaurian environment, but it wouldn't be trivial, since it's vital for the code to still work in the more-typical case where one should chown before chmod. If someone (maybe you?) could suggest a patch to coreutils that fixes the problem on HP-UX and is easy to follow and that doesn't break or slow down coreutils on typical systems, that'd be nice. But I suspect you'd be better off disabling CHOWN as shown above, as that's more secure; besides, coreutils is not the only package that has problems with the default HP-UX settings. For more on this please see: http://lists.gnu.org/archive/html/bug-gzip/2007-06/msg00005.html You might also want to look at HP's Bastille product: it's free and it should improve your site's security (the above is one of the hundreds of security holes it'll close). From unknown Sun Jun 22 07:54:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#8752: cp: fchown called before fchmod, unable to set file mode Resent-From: Paul Eggert Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Sun, 29 May 2011 19:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8752 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Milan Novak Cc: 8752@debbugs.gnu.org Received: via spool by 8752-submit@debbugs.gnu.org id=B8752.13066975192296 (code B ref 8752); Sun, 29 May 2011 19:32:01 +0000 Received: (at 8752) by debbugs.gnu.org; 29 May 2011 19:31:59 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QQliQ-0000ay-T8 for submit@debbugs.gnu.org; Sun, 29 May 2011 15:31:59 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QQliN-0000an-UB for 8752@debbugs.gnu.org; Sun, 29 May 2011 15:31:56 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 7CF6C39E8106; Sun, 29 May 2011 12:31:50 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id u12il+3z--3K; Sun, 29 May 2011 12:31:50 -0700 (PDT) Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 30DEB39E8100; Sun, 29 May 2011 12:31:50 -0700 (PDT) Message-ID: <4DE29F25.8010505@cs.ucla.edu> Date: Sun, 29 May 2011 12:31:49 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10 MIME-Version: 1.0 References: <4DE29E32.3010307@cs.ucla.edu> In-Reply-To: <4DE29E32.3010307@cs.ucla.edu> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Score: -3.0 (---) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.0 (---) On 05/29/11 12:27, Paul Eggert wrote: > # echo "-n CHOWN" >>/etc/privgrp > # setprivgrp -f /etc/privgroup Whoops, obviously I misspelled one of those two file names. I think the second one is right. But you should read the manuals and check before trying it (I haven't used HP-UX in years). From unknown Sun Jun 22 07:54:14 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.427 (Entity 5.427) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Milan Novak Subject: bug#8752: closed (Re: bug#8752: cp: fchown called before fchmod, unable to set file mode) Message-ID: References: <20110601191728.GA19127@hysteria.proulx.com> X-Gnu-PR-Message: they-closed 8752 X-Gnu-PR-Package: coreutils Reply-To: 8752@debbugs.gnu.org Date: Wed, 01 Jun 2011 19:18:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1306955882-13685-1" This is a multi-part message in MIME format... ------------=_1306955882-13685-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #8752: cp: fchown called before fchmod, unable to set file mode which was filed against the coreutils package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 8752@debbugs.gnu.org. --=20 8752: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D8752 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1306955882-13685-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 8752-done) by debbugs.gnu.org; 1 Jun 2011 19:17:36 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QRqvA-0003Y5-J3 for submit@debbugs.gnu.org; Wed, 01 Jun 2011 15:17:36 -0400 Received: from joseki.proulx.com ([216.17.153.58]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QRqv8-0003Xs-7l for 8752-done@debbugs.gnu.org; Wed, 01 Jun 2011 15:17:35 -0400 Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id 8A40F21412; Wed, 1 Jun 2011 13:17:28 -0600 (MDT) Received: by hysteria.proulx.com (Postfix, from userid 1000) id 535662DC58; Wed, 1 Jun 2011 13:17:28 -0600 (MDT) Date: Wed, 1 Jun 2011 13:17:28 -0600 From: Bob Proulx To: Milan Novak , 8752-done@debbugs.gnu.org Subject: Re: bug#8752: cp: fchown called before fchmod, unable to set file mode Message-ID: <20110601191728.GA19127@hysteria.proulx.com> References: <4DE29E32.3010307@cs.ucla.edu> <4DE29F25.8010505@cs.ucla.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4DE29F25.8010505@cs.ucla.edu> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Score: -2.4 (--) X-Debbugs-Envelope-To: 8752-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.4 (--) Paul Eggert wrote: > Paul Eggert wrote: > > # echo "-n CHOWN" >>/etc/privgrp > > # setprivgrp -f /etc/privgroup > > Whoops, obviously I misspelled one of those two file names. > I think the second one is right. But you should read the > manuals and check before trying it (I haven't used HP-UX > in years). The first was the misspelling, the second was the correct name. Just to be clear, this next command will set it interactively. You can test the behavior without having made any permanent changes. But if you reboot the change will be gone. # setprivgrp -n CHOWN Setting this file /etc/privgroup with the following contents will make it persistent at boot time: -n CHOWN See 'man 1m setprivgrp' for the HP-UX documentation. And since I think this completely resolves the issue I am going to close the ticket on it. Please feel free to add additional comments. If needed the ticket can be reopened at any time. Bob ------------=_1306955882-13685-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 28 May 2011 17:26:36 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QQNHX-0005UG-TU for submit@debbugs.gnu.org; Sat, 28 May 2011 13:26:36 -0400 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QQJHk-0007NM-U5 for submit@debbugs.gnu.org; Sat, 28 May 2011 09:10:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QQJHe-0006a8-I5 for submit@debbugs.gnu.org; Sat, 28 May 2011 09:10:27 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,T_DKIM_INVALID, T_TO_NO_BRKTS_FREEMAIL autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([140.186.70.17]:34644) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQJHe-0006a4-GZ for submit@debbugs.gnu.org; Sat, 28 May 2011 09:10:26 -0400 Received: from eggs.gnu.org ([140.186.70.92]:37165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQJHd-0000x1-9p for bug-coreutils@gnu.org; Sat, 28 May 2011 09:10:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QQJHb-0006Zt-TQ for bug-coreutils@gnu.org; Sat, 28 May 2011 09:10:25 -0400 Received: from mail-iw0-f169.google.com ([209.85.214.169]:38882) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQJHb-0006Zo-OE for bug-coreutils@gnu.org; Sat, 28 May 2011 09:10:23 -0400 Received: by iwg8 with SMTP id 8so3051294iwg.0 for ; Sat, 28 May 2011 06:10:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=pdy4V5Y1JMOQSUqMSr6m9FZ9DFcO7cH0WcN4rEzeKHQ=; b=I8lSCgQs1Nmaf3N+GqDGGcXFblVwWvBKODChvaKnqoV2TqGBuhYQQHq0bLiDV6hpAE m/BMgvSna17jiMQMUKRcqYQ7TBp3xbFhcgqEzeZHmpst6JNtFz4Nnf+ARe8Iw/XjFrtR SGB6oaFCrk5vqLzX3gIQv3TKBA5NsyUVGiIEo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=UC/NA+pPxbEuBy372WOOK3x1SF6awP3vHgy1vRnSWbK10js0iCNGJknUvG9YFMJ94h 08iKlgpcZAexaPQAKAjf+O0vnA6GapQD7qLmJ3bMhNtvntcAmzs7fEHyPu1dL3A662RR TPL3WT2nQkwb8btTvnRE4+1A01aGrLR9bCAuE= MIME-Version: 1.0 Received: by 10.231.111.228 with SMTP id t36mr3651582ibp.59.1306588222009; Sat, 28 May 2011 06:10:22 -0700 (PDT) Received: by 10.231.15.4 with HTTP; Sat, 28 May 2011 06:10:21 -0700 (PDT) Date: Sat, 28 May 2011 15:10:21 +0200 Message-ID: Subject: cp: fchown called before fchmod, unable to set file mode From: Milan Novak To: bug-coreutils@gnu.org Content-Type: multipart/alternative; boundary=0016e6471764d730f804a455c6e5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.17 X-Spam-Score: -5.9 (-----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Sat, 28 May 2011 13:26:34 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.9 (-----) --0016e6471764d730f804a455c6e5 Content-Type: text/plain; charset=ISO-8859-1 Hello, I believe that cp uses wrong order of syscalls when applying target file attributes; fchown(2) is called before fchmod(2). As a result it looses access to target file and is unable to apply file mode correctly; error message is as follows "cp: preserving permissions for `target': Not owner" The problem arises when -p (preserve attributes) is present and file owner is different from user doing the copy. Same operation using cp on hp-ux 11.31 is successfull, since hp-ux cp calls chmod(2) before chown(2). Please let me know what do you think about changing order of fchown(2) <=> fchmod(2). Kind Regards, Milan --- hp@mtest:/home/hp/coreutils $ id uid=1058(hp) gid=20(users) groups=65535(last) hp@mtest:/home/hp/coreutils $ ll source target target not found -rwxrwxrwx 1 elzu radia 32 May 20 15:50 source hp@mtest:/home/hp/coreutils $ tusc -o tusc_hpuxcp.out /usr/bin/cp -p source target; echo $? ; ll source target 0 -rwxrwxrwx 1 elzu radia 32 May 20 15:50 source -rwxrwxrwx 1 elzu radia 32 May 20 15:50 target hp@mtest:/home/hp/coreutils $ rm -f target hp@mtest:/home/hp/coreutils $ tusc -o tusc_gnucp.out coreutils-8.11/src/cp -p source target; echo $? ; ll source target coreutils-8.11/src/cp: preserving permissions for `target': Not owner #>>>> ERROR 1 -rwxrwxrwx 1 elzu radia 32 May 20 15:50 source -rwx------ 1 elzu radia 32 May 20 15:50 target #>>> already owned by user elzu, so chmod executed as user hp fails hp@mtest:/home/hp/coreutils $ coreutils-8.11/src/cp --version | head -1 cp (GNU coreutils) 8.11 hp@mtest:/home/hp/coreutils $ uname -a HP-UX mtest B.11.31 U ia64 2263078376 unlimited-user license hp@mtest:/home/hp/coreutils $ egrep "target|chown|chmod|exit" tusc_* tusc_hpuxcp.out:stat64("target", 0x7fffeec0) ............................................ ERR#2 ENT tusc_hpuxcp.out:stat64("target", 0x40021110) ............................................ ERR#2 ENT tusc_hpuxcp.out:stat64("target", 0x40021110) ............................................ ERR#2 ENT tusc_hpuxcp.out:access("target", F_OK) .................................................. ERR#2 ENT tusc_hpuxcp.out:open("target", O_WRONLY|O_CREAT|O_TRUNC|0x800, 0) ....................... = 6 tusc_hpuxcp.out:utime("target", 0x7fffe5f0) ............................................. = 0 tusc_hpuxcp.out:chmod("target", 0100777) ................................................ = 0 tusc_hpuxcp.out:chown("target", 1021, 1005) ............................................. = 0 tusc_hpuxcp.out:chmod("target", 0100777) ................................................ ERR#1 EPM tusc_hpuxcp.out:exit(0) ................................................................. WIFE) tusc_gnucp.out:stat64("target", 0x7fffedf0) ............................................ ERR#2T tusc_gnucp.out:stat64("target", 0x7fffeac0) ............................................ ERR#2T tusc_gnucp.out:open("target", O_WRONLY|O_CREAT|O_EXCL|0x800, 0700) ..................... = 5 tusc_gnucp.out:utime("target", 0x7fffe7a8) ............................................. = 0 tusc_gnucp.out:fchown(5, 1021, 1005) ................................................... = 0 #>>> the problem is HERE, CHOWN goes before CHMOD; tusc_gnucp.out:fchmod(5, 0100777) ...................................................... ERR#1M #>>> this fails, since user hp is not the owner of the file anymore tusc_gnucp.out:exit(1) ................................................................. WIFEX) --0016e6471764d730f804a455c6e5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

Hello,=A0

I= believe that cp uses wrong order of syscalls when applying target file att= ributes; fchown(2) is called before fchmod(2).=A0
As a result it looses = access to target file and is unable to apply file mode correctly; error mes= sage is as follows=A0
"cp: preserving permissions for `target': Not owner"=A0

The problem aris= es when -p (preserve attributes) is present and file owner is different fro= m user doing the copy.=A0

Same operation= using cp on hp-ux 11.31 is successfull, since hp-ux cp calls chmod(2) befo= re chown(2).=A0

Please let me know what do you think about changing order of fchown(2) <= =3D> fchmod(2).=A0

Kind Regards,=A0
Milan=A0

---=A0

hp@m= test:/home/hp/coreutils $ id=A0
uid=3D1058(hp) gid=3D20(users) groups=3D= 65535(last)=A0
hp@mtest:/home/hp/coreutils $ ll source target=A0
targ= et not found=A0
-rwxrwxrwx 1 elzu radia 32 May 20 15:50 source=A0
hp@mtest:/home/hp/core= utils $ tusc -o tusc_hpuxcp.out /usr/bin/cp -p source target; echo $? ; ll = source target=A0
0=A0
-rwxrwxrwx 1 elzu radia 32 May 20 15:50 source= =A0
-rwxrwxrwx 1 elzu radia 32 May 20 15:50 target=A0
hp@mtest:/home/hp/core= utils $ rm -f target=A0

hp@mtest:/home/hp/coreutils $ tusc -o tusc_gnucp.out coreutils= -8.11/src/cp -p source target; echo $? ; ll source target=A0
coreutils-8.11/src/cp: preserving permissions for `target': Not owner = #>>>> ERROR=A0
1=A0
-rwxrwxrwx 1 elzu radia 32 May 20 15:= 50 source=A0
-rwx------ 1 elzu radia 32 May 20 15:50 target #>>&g= t; already owned by user elzu, so chmod executed as user hp fails=A0

hp@mtest:/home= /hp/coreutils $ coreutils-8.11/src/cp --version | head -1=A0
cp (GNU cor= eutils) 8.11=A0

hp@mtest:/home/hp/coreutils $ uname -a=A0
HP-UX mtest B.11.31 U ia64 226= 3078376 unlimited-user license=A0

hp@mtest:/home/hp/coreutils $ egrep "target|cho= wn|chmod|exit" tusc_*=A0
tusc_hpuxcp.out:stat64("target", 0x7fffeec0) ....................= ........................ ERR#2 ENT=A0
tusc_hpuxcp.out:stat64("targe= t", 0x40021110) ............................................ ERR#2 ENT= =A0
tusc_hpuxcp.out:stat64("target", 0x40021110) ....................= ........................ ERR#2 ENT=A0
tusc_hpuxcp.out:access("targe= t", F_OK) .................................................. ERR#2 ENT= =A0
tusc_hpuxcp.out:open("target", O_WRONLY|O_CREAT|O_TRUNC|0x800, 0)= ....................... =3D 6=A0
tusc_hpuxcp.out:utime("target&quo= t;, 0x7fffe5f0) ............................................. =3D 0=A0
t= usc_hpuxcp.out:chmod("target", 0100777) .........................= ....................... =3D 0=A0
tusc_hpuxcp.out:chown("target", 1021, 1005) .....................= ........................ =3D 0=A0
tusc_hpuxcp.out:chmod("target&quo= t;, 0100777) ................................................ ERR#1 EPM=A0<= br> tusc_hpuxcp.out:exit(0) ...................................................= .............. WIFE)=A0

tusc_gnucp.out:stat64("target", 0x7fffedf0) ........= .................................... ERR#2T=A0
tusc_gnucp.out:stat64("target", 0x7fffeac0) .....................= ....................... ERR#2T=A0
tusc_gnucp.out:open("target"= , O_WRONLY|O_CREAT|O_EXCL|0x800, 0700) ..................... =3D 5=A0
tu= sc_gnucp.out:utime("target", 0x7fffe7a8) ........................= ..................... =3D 0=A0
tusc_gnucp.out:fchown(5, 1021, 1005) ......................................= ............. =3D 0 =A0 =A0 #>>> the problem is HERE, CHOWN goes b= efore CHMOD;=A0
tusc_gnucp.out:fchmod(5, 0100777) ......................= ................................ ERR#1M =A0 =A0 #>>> this fails, s= ince user hp is not the owner of the file anymore=A0
tusc_gnucp.out:exit(1) ....................................................= ............. WIFEX)=A0

--0016e6471764d730f804a455c6e5-- ------------=_1306955882-13685-1--