gpt4 book ai didi

linux - 为什么 mount 会忽略有效的用户 ID

转载 作者:太空宇宙 更新时间:2023-11-04 12:02:59 26 4
gpt4 key购买 nike

我想知道为什么我的 mount 版本似乎忽略了有效用户 ID...

我有这个 C 程序,由 root 拥有,具有 u+s 权限:

int main() {
execl("/bin/mount", "/bin/mount", "/mnt/abc", (char *)0);
}

当普通用户运行它时,它会提示不是 root。我可以像这样解决它:

int main() {
setuid(0);
execl("/bin/mount", "/bin/mount", "/mnt/abc", (char *)0);
}

我读到 bash 将有效 uid 更改为真实 uid 作为一项安全功能。 (参见 Calling a script from a setuid root C program - script does not run as root)但是,我不明白为什么 mount 应该这样做。有人知道吗?

我的挂载版本是:

mount from util-linux 2.29.2 (libmount 2.29.2: selinux, btrfs, assert, debug)

最佳答案

发生这种情况是因为 mount 被设计为以 suid root 身份运行。

$ ls -l /bin/mount
-rwsr-xr-x 1 root root 44200 Mar 6 13:31 /bin/mount
^

CD 或软盘驱动器通常会在 fstab 中设置 user 选项,以允许非 root 用户访问可移动媒体。 mount 被设为 SUID root 来支持这一点,因此它会检查真实的 UID 以确定您可以做什么。

关于linux - 为什么 mount 会忽略有效的用户 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51715847/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com