开源改变世界

kernel_lockdown 块 iopl 调用 #1272

推推 grbl 3年前 (2023-01-30) 156次浏览
关闭
safarir 打开了这个问题 2021 年 9 月 24 日 · 0 条评论
关闭

kernel_lockdown 块 iopl 调用#1272

safarir 打开了这个问题 2021 年 9 月 24 日 · 0 条评论

注释

kernel_lockdown 块 iopl 调用 #1272
贡献者

以下是我重现该问题所遵循的步骤:

在具有安全启动的系统上运行任何 rtapi_app

这是我期望发生的事情:

进行延迟测试

这是发生了什么:

cannot gain I/O privileges - forgot 'sudo make setuid'?

和程序退出

在此之前它工作正常:

我更换了硬件,它在我的旧电脑上运行良好

有关我的硬件和软件的信息:

硬件:HP z240、i5-7500、8GB 内存、NVME SSD
最新的 debian buster live CDlinuxcnc-2.8.2-buster.iso

评论

行为由以下因素控制src/rtapi/uspace_rtapi_app.cc

#if defined(__linux__) && (defined(__x86_64__) || defined(__i386__))
    if (iopl(3) < 0) {
        rtapi_print_msg(RTAPI_MSG_ERR,
                        "cannot gain I/O privileges - "
                        "forgot 'sudo make setuid'?\n");
        return -EPERM;
    }
#endif

这段代码似乎试图在那里允许访问并行端口。但是,使用现代内核和安全启动 (kernel_lockdown),iopl 被阻止,请参阅参考资料 2。

When lockdown is in effect, a number of features are disabled or have their use restricted
[...]
The use of the ioperm and iopl instructions on x86.

我运行了一个小的测试 c 程序,并以 root 身份运行它。在我的系统上,iopl(3) 在所有情况下都失败了。一旦禁用安全启动,iopl 调用就会工作。

在这种情况下,当前的错误消息可能确实具有误导性。和参考文献1中的使用一样,看了半天我的setuid才意识到问题所在。

由于使用并行端口不是 linuxcnc 的要求,而且越来越少的机器没有串行端口,我建议简单地打印一条警告消息。这会警告尝试使用串行端口的人,同时允许具有现代内核和硬件的人毫无问题地运行 linuxcnc。

参考

  1. https://forum.linuxcnc.org/9-installing-linuxcnc/41261-halrun-error-cannot-gain-io-privileges-error
  2. https://www.mankier.com/7/kernel_lockdown#