git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] adjust_shared_perm(): leave g+s alone when the group does not matter

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 28, 2022, 21:16 UTC
Message-ID
<xmqqr0yrhco6.fsf@gitster.g>

Julien Moutinho reports that in an environment where directory does not have BSD group semantics and requires g+s (aka FORCE_DIR_SET_GID) but the system cripples chmod() to forbid g+s, adjust_shared_perm() fails even when the repository is for private use with perm = 0600.

When we grant extra access based on group membership (i.e. the directory has either g+r or g+w bit set), which group the directory and its contents are owned by matters. But otherwise (e.g. perm is set to 0600, in Julien's case), flipping g+s bit is not necessary.

Reported-by: Julien Moutinho <julm+git@sourcephile.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 path.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/path.c b/path.c
index a3cfcd8a6e..492e17ad12 100644
--- a/path.c
+++ b/path.c
@@ -901,7 +901,13 @@ int adjust_shared_perm(const char *path)
 	if (S_ISDIR(old_mode)) {
 		/* Copy read bits to execute bits */
 		new_mode |= (new_mode & 0444) >> 2;
-		new_mode |= FORCE_DIR_SET_GID;
+
+		/*
+		 * g+s matters only if any extra access is granted
+		 * based on group membership.
+		 */
+		if (FORCE_DIR_SET_GID && (new_mode & 060))
+			new_mode |= FORCE_DIR_SET_GID;
 	}
 
 	if (((old_mode ^ new_mode) & ~S_IFMT) &&
-- 
2.38.1-280-g63bba4fdd8
Next: brian m. carlson
Message 1 of 5 in “adjust_shared_perm(): leave g+s alone when the group does not matter”
  1. adjust_shared_perm(): leave g+s alone when the group does not matterJunio C Hamano, Oct 28, 2022
  2. brian m. carlsonOct 28, 2022
  3. Junio C HamanoOct 28, 2022
  4. brian m. carlsonOct 28, 2022
  5. Junio C HamanoOct 28, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.