smbd: Ensure share root POSIX attrs are cleared after mode_fn
authorDavid Mulder <dmulder@samba.org>
Thu, 1 Dec 2022 17:53:44 +0000 (10:53 -0700)
committerRalph Boehme <slow@samba.org>
Fri, 31 Mar 2023 20:22:38 +0000 (20:22 +0000)
The call to mode_fn (smbd_dirptr_lanman2_mode_fn)
was filling the cleared attributes back in to the
stat. Ensure the clear happens after this call.

Signed-off-by: David Mulder <dmulder@samba.org>
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/dir.c

index 859c8f0dc83448c0a1b4b9af60adbaf2c3f1c228..09029ee0c23c1141e2f41073c37e95320e75e744 100644 (file)
@@ -979,13 +979,6 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
                        smb_fname = tmp_smb_fname;
                        mode = FILE_ATTRIBUTE_DIRECTORY;
                        get_dosmode = false;
-
-                       /* Ensure posix fileid and sids are hidden
-                        */
-                       smb_fname->st.st_ex_ino = 0;
-                       smb_fname->st.st_ex_dev = 0;
-                       smb_fname->st.st_ex_uid = -1;
-                       smb_fname->st.st_ex_gid = -1;
                }
 
                ok = mode_fn(ctx,
@@ -1005,6 +998,20 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
 
                TALLOC_FREE(atname);
 
+               /*
+                * Don't leak INO/DEV/User SID/Group SID about the containing
+                * directory of the share. This MUST happen AFTER the call to
+                * mode_fn().
+                */
+               if (dirptr_path_is_dot && ISDOTDOT(dname)) {
+                       /* Ensure posix fileid and sids are hidden
+                        */
+                       smb_fname->st.st_ex_ino = 0;
+                       smb_fname->st.st_ex_dev = 0;
+                       smb_fname->st.st_ex_uid = -1;
+                       smb_fname->st.st_ex_gid = -1;
+               }
+
                /*
                 * The only valid cases where we return the directory entry if
                 * it's a symlink are: