Search code examples
linuxmacosunixfreebsdsetuid

Does any Unix-like system ascribe meaning to the SUID bit on a directory?


As the title says, does any Unix-like system ascribe a meaning to the SUID bit on a directory, and if so, what does it mean?

The SVTX (saved text, or sticky) bit has a meaning - thou shalt not delete a file from this directory unless you can write to the file. It is used on /tmp, for example.

The SGID (set GID) bit has a meaning - files created in this directory shall belong to the group that owns the directory (though that assignment can later be changed by an explicit call to chown(2)).

What about the SUID bit?


Solution

  • As a followup on Node's answer, I will post the following from the FreeBSD man page for mount(8):

                 suiddir
                     A directory on the mounted file system will respond to
                     the SUID bit being set, by setting the owner of any new
                     files to be the same as the owner of the directory.  New
                     directories will inherit the bit from their parents.
                     Execute bits are removed from the file, and it will not
                     be given to root.
    
                     This feature is designed for use on fileservers serving
                     PC users via ftp, SAMBA, or netatalk.  It provides secu-
                     rity holes for shell users and as such should not be used
                     on shell machines, especially on home directories.  This
                     option requires the SUIDDIR option in the kernel to work.
                     Only UFS file systems support this option.  See chmod(2)
                     for more information.
    

    And the chmod(2) man page section that refers to the suid bit:

               4000    (the setuid bit).  Executable files with this bit set will
                   run with effective uid set to the uid of the file owner.
                   Directories with this bit set will force all files and sub-
                   directories created in them to be owned by the directory
                   owner and not by the uid of the creating process, if the
                   underlying file system supports this feature: see chmod(2)
                   and the suiddir option to mount(8).
    

    Please be aware that this is a security risk and know what you are doing when you enable it, in FreeBSD but I believe Linux as well it requires special mount flag to be enabled and will change the way files in that directory behave.