加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – NFS rootfs上的Busybox SUID

发布时间:2020-12-13 19:20:23 所属栏目:Linux 来源:网络整理
导读:我正在从底部为Beagle Bone板构建一个 Linux系统.我编译了vanilla内核并使用busybox构建了一个基本的根文件系统.系统使用U-boot启动,而rootfs位于Linux PC上并通过NFS导出: /path/to/rootfs 10.42.0.17(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,
我正在从底部为Beagle Bone板构建一个 Linux系统.我编译了vanilla内核并使用busybox构建了一个基本的根文件系统.系统使用U-boot启动,而rootfs位于Linux PC上并通过NFS导出:
/path/to/rootfs  10.42.0.17(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,rw,secure,no_all_squash)

U-boot bootargs是:

bootargs console=ttyO0,115200n8 root=/dev/nfs rw nfsroot=${serverip}:/path/to/rootfs,v3,tcp ip=dhcp

我在尝试为非root用户工作时遇到了问题.为了解决这个问题,互联网上的人们建议为busybox二进制文件设置suid位.
这样做之后:

$sudo chmod u+s busybox

并验证:

$ls -la
...
-rwsr-xr-x  1 myuser myuser 1882976 Jan 13 21:47 busybox
...

$stat -c "%a %n" busybox 
4755 busybox

有些不对劲.内核正在启动并显示所有常用消息,但它最后会卡住,并且不会显示任何登录行.以下是启动顺序的最后几行:

[    3.776185] IP-Config: Complete:
[    3.779656]      device=eth0,hwaddr=c8:a0:30:c5:80:e9,ipaddr=10.42.0.17,mask=255.255.255.0,gw=10.42.0.1
[    3.789877]      host=10.42.0.17,domain=,nis-domain=(none)
[    3.795822]      bootserver=10.42.0.1,rootserver=10.42.0.1,rootpath=
[    3.802492]      nameserver0=10.42.0.1
[    3.871575] VFS: Mounted root (nfs filesystem) on device 0:15.
[    3.879903] devtmpfs: mounted
[    3.883713] Freeing unused kernel memory: 380K (c07ef000 - c084e000)

如果删除标志,事情将恢复正常:

....
[    3.862291] Freeing unused kernel memory: 380K (c07ef000 - c084e000)

10.42.0.17 login:

如果在Beagle Bone板本身的运行shell中设置标志,则shell在执行chmod后立即停止响应.
我怀疑这与NFS导出rootfs的方式有关,但这只是猜测,所以合格的解释和可能的解决方案会有所帮助.

解决方法

经过一番研究后,我会自己回答我的问题.答案很简单.为了使上述工作正常,busybox二进制文件应由root:root拥有.最简单的解决方案就是改变所有权.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读