Bug 741371

Summary: restorecon exits with 1 when applied on files copied with cp -a ..
Product: Red Hat Enterprise Linux 6 Reporter: Gurhan Ozen <gozen>
Component: policycoreutilsAssignee: Daniel Walsh <dwalsh>
Status: CLOSED DUPLICATE QA Contact: Milos Malik <mmalik>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.2CC: bpeck, dwalsh, jburke, mmalik
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-09-26 18:02:20 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Gurhan Ozen 2011-09-26 17:16:54 UTC
Description of problem:
  This is pretty strange and possibly the underlying reason is somewhere else other than the policycoreutils package. Here is the issue that started appearing in the recent 6.2 nightly trees. If a file is copied with "cp -a $src $dest" , a subsequent restorecon command on the file exits with return code 1, whereas if it's issued on a file copied with "cp $src $dest" it does return with 0. 

For example:
# touch aaa.txt && cp ./aaa.txt /usr/local/bin/.
[root@intel-s3eb1-01 install]# ls -lZ /usr/local/bin/aaa.txt 
-rw-r--r--. root root unconfined_u:object_r:bin_t:s0   /usr/local/bin/aaa.txt
[root@intel-s3eb1-01 install]# restorecon -v /usr/local/bin/aaa.txt ; echo $?
0

This looks ok. However same sequence of commands where s/cp/cp -a/ :

[root@intel-s3eb1-01 install]# touch bbb.txt && cp -a ./bbb.txt /usr/local/bin/.
[root@intel-s3eb1-01 install]# ls -lZ /usr/local/bin/bbb.txt 
-rw-r--r--. root root unconfined_u:object_r:tmp_t:s0   /usr/local/bin/bbb.txt
[root@intel-s3eb1-01 install]# restorecon -v /usr/local/bin/bbb.txt; echo $?
restorecon reset /usr/local/bin/bbb.txt context unconfined_u:object_r:tmp_t:s0->unconfined_u:object_r:bin_t:s0
1

On rhel 6.1 , the same commands return identical exit codes:

[root@dell-pet410-03 ~]# touch aaa.txt && cp ./aaa.txt /usr/local/bin/.
[root@dell-pet410-03 ~]# ls -lZ /usr/local/bin/aaa.txt 
-rw-r--r--. root root unconfined_u:object_r:bin_t:s0   /usr/local/bin/aaa.txt
[root@dell-pet410-03 ~]# restorecon -v /usr/local/bin/aaa.txt ; echo $?
0
[root@dell-pet410-03 ~]# touch bbb.txt && cp -a ./bbb.txt /usr/local/bin/.
[root@dell-pet410-03 ~]# ls -lZ /usr/local/bin/bbb.txt 
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 /usr/local/bin/bbb.txt
[root@dell-pet410-03 ~]# restorecon -v /usr/local/bin/bbb.txt ; echo $?
restorecon reset /usr/local/bin/bbb.txt context unconfined_u:object_r:admin_home_t:s0->system_u:object_r:bin_t:s0
0


Version-Release number of selected component (if applicable):
# rpm -q policycoreutils ; cat /etc/redhat-release ; uname -a
policycoreutils-2.0.83-19.15.el6.x86_64
Red Hat Enterprise Linux Server release 6.2 Beta (Santiago)
Linux intel-s3eb1-01.rhts.eng.bos.redhat.com 2.6.32-202.el6.x86_64 #1 SMP Wed Sep 21 15:27:03 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux



How reproducible:
Everytime. 

Steps to Reproduce:
Create a file, copy to a directory with cp -a , and do restorecon on the new location of the file. 
1.
2.
3.
  
Actual results:


Expected results:


Additional info:

Comment 1 Daniel Walsh 2011-09-26 17:57:46 UTC
Fixed in policycoreutils-2.0.83-19.16.el6

Comment 2 Daniel Walsh 2011-09-26 18:02:20 UTC

*** This bug has been marked as a duplicate of bug 740669 ***