NFS rootfs上的Busybox SUID

时间:2015-06-03 12:18:10

标签: linux embedded-linux boot nfs rootfs

我正在从底部为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_root_squash,no_all_squash)

U-boot bootargs是:

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

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

$ 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

出了点问题。内核正在启动,并且显示了所有常用消息,但它最后卡住了,并且没有显示login行。以下是引导顺序的最后几行:

[    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的方式有关,但它只是一个猜测,所以合格的解释和可能的解决方案会有所帮助。

1 个答案:

答案 0 :(得分:0)

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

相关问题