Bug 651119 - getfattr ignores NULs in output when using "text" encoding
Summary: getfattr ignores NULs in output when using "text" encoding
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: attr
Version: 6.1
Hardware: Unspecified
OS: Unspecified
low
medium
Target Milestone: rc
: ---
Assignee: Kamil Dudka
QA Contact: qe-baseos-daemons
URL:
Whiteboard:
Depends On: 650539
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-11-08 20:57 UTC by Kamil Dudka
Modified: 2011-09-07 13:07 UTC (History)
5 users (show)

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.
Clone Of: 650539
Environment:
Last Closed: 2011-09-07 13:07:22 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2011:1272 0 normal SHIPPED_LIVE attr bug fix update 2011-09-07 13:07:08 UTC

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


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