为什么 ttk 小部件会导致 Tcl/Tk 程序读取 /etc/passwd 和 /etc/nsswitch.conf?

问题描述 投票:0回答:1

下面是一个简单的 Tcl/Tk GUI 程序,它打开一个窗口并在窗口中显示“Hello”一词。脚本的文件名是“hello.tk”。

#!/bin/sh
# The next line is executed by /bin/sh, but not by Tcl \
exec wish "$0" ${1+"$@"}

pack [ttk::label .l -text "Hello"]

在运行程序之前,我使用以下 Linux AppArmor 配置来限制程序。

abi <abi/3.0>,

include <tunables/global>

profile hello.tk @{HOME}/hello.tk {
  include <abstractions/base>
  include <abstractions/fonts>

  /{usr/,}bin/{da,}sh ix,
  /{usr/,}bin/wish[0-9]*.[0-9]* ix,

  @{HOME}/hello.tk r,
  /usr/share/tcltk/** r,
  owner /run/user/@{uid}/gdm/Xauthority r,
}

但是,运行程序后,

sudo journalctl --since='today' --grep 'hello.tk' -f
中会出现以下日志条目:

Jan 08 12:34:56 myhost audit[9500]: AVC apparmor="DENIED" operation="open" profile="hello.tk" name="/etc/nsswitch.conf" pid=9500 comm="wish" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
Jan 08 12:34:56 myhost audit[9500]: AVC apparmor="DENIED" operation="open" profile="hello.tk" name="/etc/passwd" pid=9500 comm="wish" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
Jan 08 12:34:56 myhost audit[9500]: AVC apparmor="DENIED" operation="open" profile="hello.tk" name="/etc/nsswitch.conf" pid=9500 comm="wish" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
Jan 08 12:34:56 myhost audit[9500]: AVC apparmor="DENIED" operation="open" profile="hello.tk" name="/etc/passwd" pid=9500 comm="wish" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

根据上面的日志条目,相关 Tk 程序在执行开始时尝试读取文件

/etc/passwd
/etc/nsswitch.conf
。如果我将
ttk::label
更改为
label
,程序不会尝试读取这些文件。这表明 ttk(主题 Tk 小部件)负责尝试读取这些文件。

为什么这么简单的 Tcl/Tk 程序需要对

/etc/passwd
/etc/nsswitch.conf
具有读取权限?

操作系统:Debian 12; Tcl/Tk 版本:8.6.13.

linux tcl tk-toolkit ttk apparmor
1个回答
0
投票

对于这些文件,我猜您正在某处查看对

getpwent()
的调用,它是 POSIX API 的一部分,很可能由 Linux 上的 GNU C 库实现。 (文件
/etc/nsswitch.conf
包含元信息来说明在哪里寻找此类内容,而
/etc/passwd
是信息的传统后备位置。)其中的信息是(大部分)良性,特别是在现代系统上将密码存储在其他地方。

很可能所查找的是用户(即您的)主目录,与您设置的环境变量无关。我不知道哪个图书馆正在这样做; Tcl 实现当然具有该功能(因此它可以理解如何 open ~/myfile.txt

,尽管我认为它默认尊重 
$env(HOME)
),Tk 可能会委托给 Tcl(可能不是,因为您没有在您的文件中指定此类文件)脚本),但其他依赖项可能会做自己的事情。 X11 客户端库和字体配置库都很有可能是可疑的。也许这就是事情出现两次的原因?

访问这些文件并不可疑。将对它们的读取权限添加到配置文件中。

© www.soinside.com 2019 - 2024. All rights reserved.