Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
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 651119

Summary: getfattr ignores NULs in output when using "text" encoding
Product: Red Hat Enterprise Linux 6 Reporter: Kamil Dudka <kdudka>
Component: attrAssignee: Kamil Dudka <kdudka>
Status: CLOSED ERRATA QA Contact: qe-baseos-daemons
Severity: medium Docs Contact:
Priority: low    
Version: 6.1CC: azelinka, jscotka, ovasik, pebolle, pkovar
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
When the "getfattr -e text" (or "getfattr --encoding=text") command was used to dump attributes with embedded null characters (NULs), the setfattr utility was not able to restore the original values of the attributes later on. This problem has been resolved in this update by fixing the encoding of such values in getfattr in order to prevent any information loss.
Story Points: ---
Clone Of: 650539 Environment:
Last Closed: 2011-09-07 13:07:22 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:
Bug Depends On: 650539    
Bug Blocks:    

Description Kamil Dudka 2010-11-08 20:57:28 UTC
+++ This bug was initially created as a clone of Bug #650539 +++

Description of problem:
There can be NULs in the output of getfattr when using "text" encoding. getfattr should check whether it tries to print a string with an embedded NUL, ie, tries to print a truncated string.

Version-Release number of selected component (if applicable):
attr-2.4.44-5.fc15

How reproducible:
Always

Steps to Reproduce:
1. getfattr -e text -d -m - /usr/bin/getfattr
2.
3.
  
Actual results:
getfattr: Removing leading '/' from absolute path names
# file: usr/bin/getfattr
security.selinux="system_u:object_r:bin_t:s0

Expected results:
getfattr: Removing leading '/' from absolute path names
# file: usr/bin/getfattr
security.selinux="system_u:object_r:bin_t:s0"

Additional info:
The only, entirely trivial, difference is that currently, getfattr doesn't print the closing double quote in the example above.

Apparently, all SELinux extended attributes have a NUL append. See the 0x00 at the end of this output:
getfattr -e hex -d -m - /usr/bin/getfattr
getfattr: Removing leading '/' from absolute path names
# file: usr/bin/getfattr
security.selinux=0x73797374656d5f753a6f626a6563745f723a62696e5f743a733000

I'll try to attach a trivial patch to fix this shortly.

--- Additional comment from pebolle on 2010-11-06 23:45:24 CET ---

Created attachment 458391 [details]
Handle NULs in "text" encoded output

--- Additional comment from kdudka on 2010-11-08 19:56:35 CET ---

Created attachment 458849 [details]
extended version of the patch that handles embedded NULLs, too

Thank you for the bug report and the patch!  It's indeed broken and your patch solves the problem.  It stops on the first occurrence of '\0'.  For some reason 'setfattr --restore' then appends the trailing zero automatically while operating in 'text' mode, and everything works fine in the case of SELinux attributes.

However, the encoding is still broken when embedded NULLs are involved:

$ touch foo
$ setfattr -n user.bar -v 'foo\000bar' foo
$ getfattr --dump -e hex foo
# file: foo
user.bar=0x666f6f00626172

$ getfattr --dump -e text foo | tee dump
# file: foo
user.bar="foo"

$ setfattr --restore dump
$ ./getfattr/.libs/getfattr --dump -e hex foo
# file: foo
user.bar=0x666f6f

It means we are still loosing information at this point ^^^.  We should probably extend your patch this way:

$ setfattr -n user.bar -v 'foo\000bar' foo
$ getfattr --dump -e hex foo
# file: foo
user.bar=0x666f6f00626172

$ getfattr --dump -e text foo | tee dump
# file: foo
user.bar="foo\000bar"

$ setfattr --restore dump
$ ./getfattr/.libs/getfattr --dump -e hex foo
# file: foo
user.bar=0x666f6f00626172

Could you please have a look at the updated patch?

--- Additional comment from kdudka on 2010-11-08 20:29:18 CET ---

Actually, it reminded me an outstanding documentation bug (bug 587516), which is closely related to this one.  Paul, could you please have a look at the following man page fix and check if the wording is clear to you?  Thanks in advance!

attachment #458858 [details]

--- Additional comment from pebolle on 2010-11-08 21:45:53 CET ---

(In reply to comment #3)
> Paul, could you please have a look at the
> following man page fix and check if the wording is clear to you?

One of these days, I hope. Please prod me if you get nervous.

Comment 1 Paul Bolle 2010-11-08 21:06:32 UTC
Nitpick: s/NULLs/NULs/ in summary.

Comment 2 Kamil Dudka 2010-11-08 21:28:52 UTC
Thanks for pointing it out.  I was blindly trusting my spell-checker, which was more happy with NULLs.  Now I realized you meant those ASCII codes denoted NUL.

Comment 4 Suzanne Logcher 2011-02-15 21:44:31 UTC
This issue was proposed for RHEL 6.1 FasTrack but did not get resolved in time.
It has been moved to RHEL 6.2 FasTrack.

Comment 8 Kamil Dudka 2011-06-27 15:19:15 UTC
upstream commit:

http://git.savannah.gnu.org/cgit/attr.git/commit/?id=7fed444

Comment 10 Petr Kovar 2011-06-29 11:11:41 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
When the "getfattr -e text" (or "getfattr --encoding=text") command was used to dump attributes with embedded null characters (NULs), the setfattr utility was not able to restore the original values of the attributes later on. This problem has been resolved in this update by fixing the encoding of such values in getfattr in order to prevent any information loss.

Comment 17 errata-xmlrpc 2011-09-07 13:07:22 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-1272.html