Skip to contentSkip to conversation

xfs_profile: fix permission octet when suid/guid is set

PATCH Superseded Luca Di Maio 2 participants 3 messages Apr 16, 2025

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xfs_profile: fix permission octet when suid/guid is set

When encountering suid or sgid files, we already set the u or g property in the prototype file.
Given that proto.c only supports three numbers for permissions, we need to remove the redundant information from the permission, else it was incorrectly parsed.

[v1] -> [v2]
Improve masking as suggested

---
 mkfs/xfs_protofile.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mkfs/xfs_protofile.in +3 -1
index e83c39f..9418e7f 100644
@@ -43,7 +43,9 @@ def stat_to_str(statbuf):
 	else:
 		sgid = '-'
 
-	perms = stat.S_IMODE(statbuf.st_mode)
+	# We already register suid in the proto string, no need
+	# to also represent it into the octet
+	perms = stat.S_IMODE(statbuf.st_mode) & 0o777
 
 	return '%s%s%s%03o %d %d' % (type, suid, sgid, perms, statbuf.st_uid, \
 			statbuf.st_gid)

--
2.49.0

Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Luca Di Maio

When encountering suid or sgid files, we already set the u or g property in the prototype file.
Given that proto.c only supports three numbers for permissions, we need to remove the redundant information from the permission, else it was incorrectly parsed.

Quoted 6 lines

[v1] -> [v2]
Improve masking as suggested

The subject line should say "xfs_protofile", not "xfs_profile".

With that fixed,

--D

Quoted 22 lines
---
 mkfs/xfs_protofile.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mkfs/xfs_protofile.in +3 -2
index e83c39f..9418e7f 100644
@@ -43,7 +43,9 @@ def stat_to_str(statbuf):
 	else:
 		sgid = '-'
 
-	perms = stat.S_IMODE(statbuf.st_mode)
+	# We already register suid in the proto string, no need
+	# to also represent it into the octet
+	perms = stat.S_IMODE(statbuf.st_mode) & 0o777
 
 	return '%s%s%s%03o %d %d' % (type, suid, sgid, perms, statbuf.st_uid, \
 			statbuf.st_gid)
--

2.49.0

#2 lore raw

Sorry for the typo! Sent the fixed patch

L.

Quoted 44 lines · Darrick J. Wong
Quoted 6 lines · Luca Di Maio

When encountering suid or sgid files, we already set the u or g property in the prototype file.
Given that proto.c only supports three numbers for permissions, we need to remove the redundant information from the permission, else it was incorrectly parsed.

Quoted 6 lines

[v1] -> [v2]
Improve masking as suggested

The subject line should say "xfs_protofile", not "xfs_profile".

With that fixed,

--D

Quoted 22 lines
---
 mkfs/xfs_protofile.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mkfs/xfs_protofile.in +3 -2
index e83c39f..9418e7f 100644
@@ -43,7 +43,9 @@ def stat_to_str(statbuf):
      else:
              sgid = '-'
 
-     perms = stat.S_IMODE(statbuf.st_mode)
+     # We already register suid in the proto string, no need
+     # to also represent it into the octet
+     perms = stat.S_IMODE(statbuf.st_mode) & 0o777
 
      return '%s%s%s%03o %d %d' % (type, suid, sgid, perms, statbuf.st_uid, \
                      statbuf.st_gid)
--

2.49.0