如何在 BUILDROOT 中为 SELINUX 更新 modules.conf?

How to update modules.conf for SELINUX in BUILDROOT?

希望禁用某些 SELinux 模块(设置为关闭)并在 modules.conf 中创建其他模块。我没有看到更新 modules.conf 的明显方法,因为我尝试将我的更改添加为 modules.conf 补丁,但它失败了,因为 modules.conf 文件已构建并且不仅仅是由 BR 下载所以它不能像 refpolicy 目录下的其他东西一样用于修补:

构建window输出:

refpolicy 2.20190609 PatchingApplying 0001-refpolicy-update-modules-conf.patch using patch: can't find file to patch at input line 3

我确实在日志中看到有一个 support/sedoctool.py 自动生成 policy/modules.conf 文件,因此该文件不能像 ref 策略中的大多数其他内容一样进行修补。

buildroot/output/build/refpolicy-2.20190609/Makefile的相关部分:

# policy building support tools
support := support
genxml := $(PYTHON) $(support)/segenxml.py
gendoc := $(PYTHON) $(support)/sedoctool.py

<...snip...>

########################################
#
# Create config files
#
conf: $(mod_conf) $(booleans) generate$(booleans) $(mod_conf): conf.intermediate.INTERMEDIATE: conf.intermediate
conf.intermediate: $(polxml)
        @echo "Updating $(booleans) and $(mod_conf)"
        $(verbose) $(gendoc) -b $(booleans) -m $(mod_conf) -x $(polxml)

部分 hsmlinux build.log 显示 sedoctool.py (gendoc) 运行:

Updating policy/booleans.conf and policy/modules.conf .../build-buildroot-sawshark/buildroot/output/host/usr/bin/python3 support/sedoctool.py -b policy/booleans.conf -m policy/modules.conf -x doc/policy.xml

我确定有一个标准的方法可以做到这一点,只是似乎没有在我能找到的任何地方记录下来。

谢谢。

原来 sedoctool.py 脚本正在读取 doc/policy.xml。看着 sedoctool.py:

#modules enabled and disabled values
MOD_BASE = "base"
MOD_ENABLED = "module"
MOD_DISABLED = "off"

<...剪断...>

def gen_module_conf(doc, file_name, namevalue_list):
        """
        Generates the module configuration file using the XML provided and the
        previous module configuration.
        """
        # If file exists, preserve settings and modify if needed.
        # Otherwise, create it.
<...snip...>
                        mod_name = node.getAttribute("name")
                        mod_layer = node.parentNode.getAttribute("name")
<...snip...>
                        if mod_name and mod_layer:
                                file_name.write("# Layer: %s\n# Module: %s\n" % (mod_layer,mod_name))
                                if required:
                                        file_name.write("# Required in base\n")
                                file_name.write("#\n")

                               if [mod_name, MOD_DISABLED] in namevalue_list:
                                        file_name.write("%s = %s\n\n" % (mod_name, MOD_DISABLED))
                                # If the module is set as enabled.
                                elif [mod_name, MOD_ENABLED] in namevalue_list:
                                        file_name.write("%s = %s\n\n" % (mod_name, MOD_ENABLED))
                                # If the module is set as base.
                                elif [mod_name, MOD_BASE] in namevalue_list:
                                        file_name.write("%s = %s\n\n" % (mod_name, MOD_BASE))

因此 sedoctool.py 具有以下优点:“# 如果文件存在,保留设置并在需要时进行修改。” modules.conf 可以通过完整的文件补丁在这里添加,不需要的模块设置为“关闭”:refpolicy-2.20190609/policy/modules.conf 脚本将根据需要更新期望的政策。

一个更详细的信息是,在下一阶段的 refpolicy Makefile(构建)中,带有更新的 modules.conf 在开始时被删除,这与 sedoctool 保留补丁版本的能力发生了冲突modules.conf...因此在 Makefile 的构建阶段修补了删除。

[7m>>> refpolicy 2.20190609 大楼^[

<...剪断...>

rm -f policy/modules.conf

refpolicy-2.20190609 中的 Makefile 有我修补的这一行,因为我们正在修补我们自己的 modules.conf:

裸:干净 <...剪断...> $(详细) rm -f $(mod_conf)

那个补丁看起来像:

--- BUILDROOT/Makefile  2020-08-17 13:25:06.963804709 -0400
+++ FIX/Makefile  2020-08-17 19:25:29.540607763 -0400
@@ -636,7 +636,6 @@
        $(verbose) rm -f $(modxml)
        $(verbose) rm -f $(tunxml)
        $(verbose) rm -f $(boolxml)
-       $(verbose) rm -f $(mod_conf)
        $(verbose) rm -f $(booleans)
        $(verbose) rm -fR $(htmldir)
        $(verbose) rm -f $(tags)

顺便说一句, 在 pp1:q!:

中使用完整的新文件创建补丁
diff -crB --new-file pp0 pp1 > pp0.patch