Bug 1895013

Summary: unsquashfs does not preserve file capabilities
Product: Red Hat Enterprise Linux 7 Reporter: Christophe Besson <cbesson>
Component: squashfs-toolsAssignee: Abhijith Das <adas>
Status: CLOSED WONTFIX QA Contact: qe-baseos-daemons
Severity: medium Docs Contact:
Priority: medium    
Version: 7.9CC: adas, amepatil, darcari, dconsoli, dlehman, dwysocha, snejoshi, swhiteho
Target Milestone: rcKeywords: Patch, Reproducer, Triaged
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1895017 (view as bug list) Environment:
Last Closed: 2021-07-06 14:25:23 UTC Type: Bug
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:    
Bug Blocks: 1895017    

Description Christophe Besson 2020-11-05 15:06:32 UTC
Description of problem:
While running unsquashfs, file capabilities are not preserved.

Version-Release number of selected component (if applicable):
squashfs-tools-4.3-0.21.gitaae0aff4

How reproducible:
100%

Steps to Reproduce:
~~~
# mksquashfs /usr/bin/ping /tmp/test.img
# mount /tmp/test.img /mnt
# getcap /mnt/ping 
/mnt/ping = cap_net_admin,cap_net_raw+p
# unsquashfs /tmp/test.img
# getcap squashfs-root/ping
<EMPTY OUTPUT>
~~~

Additional info:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=804194

Applying blindly that patch against the RHEL srpm fixed the issue for me.
~~~
--- squashfs4.3.orig/squashfs-tools/unsquashfs.c	2020-11-05 13:08:22.000000000 +0100
+++ squashfs4.3/squashfs-tools/unsquashfs.c	2020-11-05 13:09:02.000000000 +0100
@@ -818,8 +818,6 @@
 {
 	struct utimbuf times = { time, time };
 
-	write_xattr(pathname, xattr);
-
 	if(utime(pathname, &times) == -1) {
 		ERROR("set_attributes: failed to set time on %s, because %s\n",
 			pathname, strerror(errno));
@@ -842,6 +840,8 @@
 		return FALSE;
 	}
 
+	write_xattr(pathname, xattr);
+
 	return TRUE;
 }
~~~

Issue has been fixed a little bit differently in 4.4 upstream.
The bug also concerns the RHEL 8 version, so cloning this bug.

Comment 2 Abhijith Das 2021-01-18 17:16:38 UTC
https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=34344140

Here's a rhel7 test build with the above patch. It passed the test case outlined in the description. Could you please run additional tests to make sure the patch didn't break anything else? If all looks fine, I'll go ahead and file an erratum.

Out of curiosity, who is the customer and what is their use-case for squashfs?

Comment 3 Christophe Besson 2021-01-19 13:41:54 UTC
Thanks, requesting to verify if it works in that environment.