diff mbox series

[pseudo,4/6] pseudo_client.h: Add +s to PSEUDO_DB_MODE for mkdir

Message ID 1780519148-30836-5-git-send-email-mark.hatle@kernel.crashing.org
State New
Headers show
Series Permission/setuid/setgid handling | expand

Commit Message

Mark Hatle June 3, 2026, 8:39 p.m. UTC
From: Mark Hatle <mark.hatle@amd.com>

During a mkdir the kernel will automatically filter out S_ISUID and
S_ISGID for non-root users.

This would result in an emulated ug+s on a directory losing the +s.

This resolves the issue, and we need to remember to account for it in
the future.

AI-Generated: Implemented with the assistance of github CoPilot (Claude Opus 4.6)

Signed-off-by: Mark Hatle <mark.hatle@amd.com>
Signed-off-by: Mark Hatle <mark.hatle@kernel.crashing.org>
---
 pseudo_client.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/pseudo_client.h b/pseudo_client.h
index b5ec204..9d98ea1 100644
--- a/pseudo_client.h
+++ b/pseudo_client.h
@@ -90,7 +90,10 @@  extern int read_pidfile(FILE *, int *);
  *
  * Note: PSEUDO_DB_MODE must be kept in sync with PSEUDO_FS_MODE, as the
  * former defined which filesystem mode bits must be loaded from the DB.
+ *
+ * Note: S_ISUID and S_ISGID may be stripped during a mkdir as a user,
+ * account for this in PSEUDO_DB_MODE.
  */
 #define PSEUDO_FS_MODE(mode, isdir) (((mode) | S_IRUSR | S_IWUSR | ((isdir) ? S_IXUSR : 0)) & ~(S_IWGRP | S_IWOTH))
-#define PSEUDO_DB_MODE(fs_mode, user_mode) (((fs_mode) & ~(S_IRUSR | S_IWUSR | S_IXUSR | S_IWGRP | S_IWOTH)) | ((user_mode) & (S_IRUSR | S_IWUSR | S_IXUSR | S_IWGRP | S_IWOTH)))
+#define PSEUDO_DB_MODE(fs_mode, user_mode) (((fs_mode) & ~(S_IRUSR | S_IWUSR | S_IXUSR | S_IWGRP | S_IWOTH | S_ISUID | S_ISGID)) | ((user_mode) & (S_IRUSR | S_IWUSR | S_IXUSR | S_IWGRP | S_IWOTH | S_ISUID | S_ISGID)))