linux中的文件系统uid和gid

Vin*_*a G 8 linux filesystems users

我遇到了一个 linux 内核教程,他们谈到了 4 对标识符,其中之一是文件系统 uid 和 gid。

有人可以解释一下它是什么以及它与uid 和 gid 有什么不同吗?

Ala*_*rry 9

谁会想到这个问题会拖出这么多过于自信和不知情的回答!

文件系统 uid 或fsuid是一个 Linux 特性,旨在帮助 NFS 服务器实现。它是一个额外的(非 POSIX)uid,仅用于文件权限检查。对于任何不调用的setfsuid进程(基本上是任何不尝试成为 NFS 服务器的进程),fsuid 与有效 uid 相同。

它甚至有一个手册页,所以有借口声称它不存在。

更新:我受到启发去寻找 fsuid 的起源。当它在 Linux 1.1.44 中被添加时,这个注释被放在了新sys_setfsuid函数的上面:

+/*
+ * "setfsuid()" sets the fsuid - the uid used for filesystem checks. This
+ * is used for "access()" and for the NFS daemon (letting nfsd stay at
+ * whatever uid it wants to). It normally shadows "euid", except when
+ * explicitly set by setfsuid() or for access..
+ */
Run Code Online (Sandbox Code Playgroud)

此更改是在上面的评论中进行的sys_access

- * XXX we should use the real ids for checking _all_ components of the
- * path.  Now we only use them for the final component of the path.
+ * access() needs to use the real uid/gid, not the effective uid/gid.
+ * We do this by temporarily setting fsuid/fsgid to the wanted values
Run Code Online (Sandbox Code Playgroud)

所以NFS是最初的两个目的之一。另一个是使 access() 正常工作。setuid 程序使用 access() 来确定真实用户是否可以在没有 setuid 的附加权限的情况下访问文件。在 1.1.44 之前,它是有问题的。从那时起,它一直使用临时更改 fsuid 来完成这项工作。由于 fsuid 在 access() 系统调用返回之前恢复,因此您永远不会真正看到来自用户空间的更改。

  • NFS 中的最新技术可能已经向前发展,但我能找到的所有历史信息都表明 fsuid/fsgid 的唯一目的是支持 unfsd,而没有其他任何东西使用它。由于其他答案否认 fsuid/fsgid 的存在,我认为我仍然遥遥领先。 (2认同)