public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs_profile: fix permission octet when suid/guid is set
@ 2025-04-16 12:35 Luca Di Maio
  2025-04-16 15:40 ` Darrick J. Wong
  0 siblings, 1 reply; 3+ messages in thread
From: Luca Di Maio @ 2025-04-16 12:35 UTC (permalink / raw)
  To: linux-xfs; +Cc: Luca Di Maio, dimitri.ledkov, smoser

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.

Before:

    wall                                    --g2755 0 0 rootfs/usr/bin/wall
    sudo                                    -u-4755 0 0 rootfs/usr/bin/sudo

This wrongly generates (suid + 475 permissions):

    -r-Srwxr-x. 1 root root 514704 Apr 16 11:56 /usr/bin/su


After:

    wall                                    --g755 0 0 rootfs/usr/bin/wall
    sudo                                    -u-755 0 0 rootfs/usr/bin/sudo

This correctly generates (suid + 755 permissions):

    -rwsr-xr-x 1 root root 514704 Apr 16 11:56 /usr/bin/su

Signed-off-by: Luca Di Maio <luca.dimaio1@gmail.com>
---
 mkfs/xfs_protofile.in | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mkfs/xfs_protofile.in b/mkfs/xfs_protofile.in
index e83c39f..9672ca3 100644
--- a/mkfs/xfs_protofile.in
+++ b/mkfs/xfs_protofile.in
@@ -43,7 +43,13 @@ def stat_to_str(statbuf):
 	else:
 		sgid = '-'

+	# We already register suid in the proto string, no need
+	# to also represent it into the octet
 	perms = stat.S_IMODE(statbuf.st_mode)
+	if suid == 'u':
+		perms = perms & ~stat.S_ISUID
+	if sgid == 'g':
+		perms = perms & ~stat.S_ISGID

 	return '%s%s%s%03o %d %d' % (type, suid, sgid, perms, statbuf.st_uid, \
 			statbuf.st_gid)
2.49.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-16 16:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-16 12:35 [PATCH] xfs_profile: fix permission octet when suid/guid is set Luca Di Maio
2025-04-16 15:40 ` Darrick J. Wong
2025-04-16 16:16   ` Luca Di Maio

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox