RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1099508 - ls -Z trumps other arguments
Summary: ls -Z trumps other arguments
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: coreutils
Version: 7.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Ondrej Vasik
QA Contact: qe-baseos-daemons
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-05-20 13:29 UTC by Nenad Peric
Modified: 2015-11-19 12:44 UTC (History)
2 users (show)

Fixed In Version: coreutils-8.22-13.el7
Doc Type: Bug Fix
Doc Text:
Cause: Red Hat specific patch handles --scontext, --context and --lcontext ls options differently from upstream. Option --context behaves like a SELinux format option. Consequence: In ls, only the last format option is used. Previous format options are overridden. Fix: Documentation was adjusted, explicitly mentioning this behaviour and reasons why ls -Zl differs from ls -lZ. Result: Users should no longer be confused by this expected behaviour.
Clone Of:
Environment:
Last Closed: 2015-11-19 12:44:19 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2015:2160 0 normal SHIPPED_LIVE coreutils bug fix and enhancement update 2015-11-19 11:10:56 UTC

Description Nenad Peric 2014-05-20 13:29:15 UTC
Description of problem:

If you use ls for displaying selinux context of files, the order of arguments entered changes the output of the command (very unintuitively).

Version-Release number of selected component (if applicable):

coreutils-8.22-11.el7.x86_64

How reproducible:
Everytime

Steps to Reproduce:

[root@virt-002 .ssh]# ls -liZ
-rw-------. root root unconfined_u:object_r:admin_home_t:s0 authorized_keys
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 config
-rw-------. root root unconfined_u:object_r:admin_home_t:s0 id_rsa
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 id_rsa.pub

[root@virt-002 .ssh]# ls -Zli
total 16
185337 -rw-------. 1 unconfined_u:object_r:admin_home_t:s0 root root  429 May 20 12:37 authorized_keys
185338 -rw-r--r--. 1 unconfined_u:object_r:admin_home_t:s0 root root   33 May 20 12:37 config
185339 -rw-------. 1 unconfined_u:object_r:admin_home_t:s0 root root 1671 May 20 12:37 id_rsa
185340 -rw-r--r--. 1 unconfined_u:object_r:admin_home_t:s0 root root  429 May 20 12:37 id_rsa.pub


Actual results:

The output changes for the same command but different order of arguments.


Expected results:

The output with the same arguments should remain the same. That would be the logical course of action, since the other display commands are additive in nature.


Additional info:
This seems to be a "feature (tm)" based on Bugs 771843, 448903, 524202... BUT 
there's NO information regarding this up-side-down illogical behavior (from user/admin perspective), neither in man pages nor in 'info' documentation of coreutils.

Comment 2 Ondrej Vasik 2014-05-20 13:44:13 UTC
Simply - no - it is just another format option. It is documented in 'info' documentation of coreutils, so your last sentence is wrong - as you can see on the following citation:
"Note: When multiple format options are used in `ls', the last one
      is used. Therefore `ls -lZ' (security format is last - same as `ls
      --context') differs from `ls -Zl' (long format with selinux
      context is shown, same as `ls --lcontext')"

Comment 3 Ondrej Vasik 2014-05-20 13:50:17 UTC
Just to clarify the incomplete statement in the summary/description. -Z is not different from other formatting options of ls ... so ANY format options overrides the previous ones. This means from -Z, -1 , -l , -x , -m , -C options, only last one is used for the formatting.

Comment 4 Nenad Peric 2014-05-20 14:13:10 UTC
Can you write in WHICH version of coreutils info is the citation you mention in Comment 2 found?

What I can see in info ls (/usr/share/info/coreutils.info.gz) is this:

'-Z'
'--context'
     Display the SELinux security context or '?' if none is found.  When
     used with the '-l' option, print the security context to the left
     of the size column.


And that is it! There is no Note you mention. 

So, please stop just screaming over bugzilla how everyone is daft and all that, and take a look at the package in RHEL7 and you will see that the "Note" you are mentioning does not exist (at least not in coreutils-8.22-11.el7.x86_64)

Is there another version of RHEL7 coreutils packages we should be using somehow?

Comment 5 Ondrej Vasik 2014-05-20 14:31:43 UTC
Sorry for not checking the latest build, the statement was likely removed with the "closer to upstream" changes in coreutils-8.22. I checked my local RHEL-7 build before closing this, but not the right one.

Statement -Z is no different from other format options is still valid and this will not change. Statement I'm not going to add the note to the man page is still valid. But you are right, that even info documentation doesn't mention it - and it doesn't even mention the format option. 
I'll add something more generic about the formats into info documentation for RHEL 7.1 after clarification upstream (as this part was always downstream part). Let's keep it opened.

Comment 6 Pádraig Brady 2014-05-26 17:07:05 UTC
Note this behavior is downstream only.
Can we drop it for RHEL7/Feodra?
We've made lots of changes wrt -Z in other tools, so this would be a good time.
The current downstream behavior is very confusing to me anyway.

For the record the upstream format is consistent no matter what the option order and is:

$ ls -ldZ /
dr-xr-xr-x. 26 root root system_u:object_r:root_t:s0 4096 May  2 21:41 /

$ ls -Zld /
dr-xr-xr-x. 26 root root system_u:object_r:root_t:s0 4096 May  2 21:41 /

Comment 7 Ondrej Vasik 2014-05-27 05:34:12 UTC
For Rawhide, I'm going to drop the downstream changes. For RHEL 7 it is too late to change the behaviour (actually, it was kept as the downstream syntax was used by several training materials). I will improve the documentation of the downstream changes for RHEL 7.

Upstream, there is no issue with the -Z - as it behaves as a flag, downstream, -Z is a format option. However - one thing probably worth of improvement upstream is better documenting of --format options in info docs or even man page, stating that only last format option is used.

Comment 9 Ondrej Vasik 2015-06-12 13:13:55 UTC
I improved information about --scontext/--context and --lcontext option in info documentation, and mentioned deprecation of these options. Info about "only last format option counts" was added as well.

These options were already removed in Fedora, following upstream behaviour.

Comment 12 errata-xmlrpc 2015-11-19 12:44:19 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-2160.html


Note You need to log in before you can comment on or make changes to this bug.