sepolicy 中unlabeled 修改

本文介绍了解决persist分区SELinux权限问题的过程。通过分析init启动过程,明确了需要在init.rc文件中添加restorecon_recursive命令来确保persist分区正确应用SELinux策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

文章出处:http://blog.youkuaiyun.com/shift_wwx/article/details/77500458

请转载的朋友标明出处~~

 

 

 

最近需要在平台上添加一个persist 分区,需要添加sepolicy,但是不管怎么修改,发现分区最终 ls -Z 出来一直是:u:object_r:unlabeled:s0,而不是想要的persist_file 属性。

 

修改如下:

file.te 中:

type persist_file, file_type;

file_contexts中:

/persist(/.*)?       u:object_r:persist_file:s0

 

 

可是为什么没有生效了?

 

查看了init 中的code:

    int main(int argc, char** argv) {
    ......
	
    if (is_first_stage) {
        mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755");
        mkdir("/dev/pts", 0755);
        mkdir("/dev/socket", 0755);
        mount("devpts", "/dev/pts", "devpts", 0, NULL);
        #define MAKE_STR(x) __STRING(x)
        mount("proc", "/proc", "proc", 0, "hidepid=2,gid=" MAKE_STR(AID_READPROC));
        mount("sysfs", "/sys", "sysfs", 0, NULL);
    }

    // We must have some place other than / to create the device nodes for
    // kmsg and null, otherwise we won't be able to remount / read-only
    // later on. Now that tmpfs is mounted on /dev, we can actually talk
    // to the outside world.
    open_devnull_stdio();
    klog_init();
    klog_set_level(KLOG_NOTICE_LEVEL);

    NOTICE("init %s started!\n", is_first_stage ? "first stage" : "second stage");

    if (!is_first_stage) {
        // Indicate that booting is in progress to background fw loaders, etc.
        close(open("/dev/.booting", O_WRONLY | O_CREAT | O_CLOEXEC, 0000));

        property_init();

        // If arguments are passed both on the command line and in DT,
        // properties set in DT always have priority over the command-line ones.
        process_kernel_dt();
        process_kernel_cmdline();

        // Propagate the kernel variables to internal variables
        // used by init as well as the current required properties.
        export_kernel_boot_props();
    }

    // Set up SELinux, including loading the SELinux policy if we're in the kernel domain.
    selinux_initialize(is_first_stage);

    // If we're in the kernel domain, re-exec init to transition to the init domain now
    // that the SELinux policy has been loaded.
    if (is_first_stage) {
        if (restorecon("/init") == -1) {
            ERROR("restorecon failed: %s\n", strerror(errno));
            security_failure();
        }
        char* path = argv[0];
        char* args[] = { path, const_cast<char*>("--second-stage"), nullptr };
        if (execv(path, args) == -1) {
            ERROR("execv(\"%s\") failed: %s\n", path, strerror(errno));
            security_failure();
        }
    }

    // These directories were necessarily created before initial policy load
    // and therefore need their security context restored to the proper value.
    // This must happen before /dev is populated by ueventd.
    NOTICE("Running restorecon...\n");
    restorecon("/dev");
    restorecon("/dev/socket");
    restorecon("/dev/__properties__");
    restorecon("/property_contexts");
    restorecon_recursive("/sys");

    ......
	
    parser.ParseConfig("/init.rc");
	
	......
	
    selinux_initialize(is_first_stage);

    // If we're in the kernel domain, re-exec init to transition to the init domain now
    // that the SELinux policy has been loaded.
    if (is_first_stage) {
        if (restorecon("/init") == -1) {
            ERROR("restorecon failed: %s\n", strerror(errno));
            security_failure();
        }
        char* path = argv[0];
        char* args[] = { path, const_cast<char*>("--second-stage"), nullptr };
        if (execv(path, args) == -1) {
            ERROR("execv(\"%s\") failed: %s\n", path, strerror(errno));
            security_failure();
        }
    }

    // These directories were necessarily created before initial policy load
    // and therefore need their security context restored to the proper value.
    // This must happen before /dev is populated by ueventd.
    NOTICE("Running restorecon...\n");
    restorecon("/dev");
    restorecon("/dev/socket");
    restorecon("/dev/__properties__");
    restorecon("/property_contexts");
    restorecon_recursive("/sys");

    ......
	
    parser.ParseConfig("/init.rc");
	
	......
	

可以看到在init.rc 解析之前做了selinux 的load,在load 之后都会对一些分区做restorecon的操作,这个应该是说在init.rc 解析之前先做了selinux 的load,也就是file_contexts等load,但是此时并没有persist 分区,所以sepolicy 并没有生效。

 

看到这,大概就知道之前为什么一直不行了,因为需要restore的操作,所以,最终修改如下:(在init.rc 或者init.*.rc 中:)

restorecon_recursive /persist

 

对于,restorecon 和 restorecon_recursive 的区别,可以看下code,就是一个递归的效果。




 

 

 

 

 

 

<think>嗯,用户这次想了解"unlabeledwilddata"的含义及其在机器学习中的应用。结合之前的对话历史,用户似乎对机器学习中的数据处理方法很感兴趣,之前讨论过集成学习的留出策略,现在转向了数据类型的探讨。从用户提供的引用材料来看,虽然引用内容主要涉及PCA降维、人脸识别数据集等,但其中引用[4]关于高维数据的描述特别值得注意——它暗示了现实世界中原始数据的复杂性和高维特性,这恰好与"wilddata"的特征高度吻合。用户可能正在处理实际项目中的数据,遇到了未标注的原始数据问题。需要明确区分几个关键概念:1"unlabeled"指没有人工标注的标签(如分类类别、检测框等)2"wild"强调数据的原始性、未加工性和现实复杂性3这类数据与实验室常用数据集(如MNIST)形成鲜明对比在应用场景部分,应该突出半监督学习和自监督学习这两个典型用途,因为引用[2]提到的人脸识别项目就涉及数据预处理,而wilddata往往需要类似的预处理流程。同时要强调现实数据的挑战性,比如引用[3]中PCA处理高维数据的场景就适用于wilddata的降维。需要特别提醒用户注意数据预处理的重要性,因为引用[1][2]都展示了sklearn处理标准数据集的流程,而wilddata往往需要更复杂的清洗步骤。最后生成的问题要引导用户思考如何将理论应用到实际,比如数据标注成本问题就很关键。</think>### Unlabeled Wild Data 的定义与机器学习应用 #### 一、核心定义 **Unlabeled wild data**(未标注野生数据)指**未经人工标注且直接从现实环境采集的原始数据**,其特征包括: 1. **无监督性** 缺乏人工标注的标签(如分类标签、检测框等),需通过算法挖掘内在结构。 2. **原始复杂性** 包含真实场景的噪声、异常值和不规则分布(如用户上传的模糊图片、社交媒体文本)。 3. **高维度性** 通常具有冗余特征,需降维处理(如 $100\times100$ RGB图像产生30,000维向量[^4])。 4. **分布偏移风险** 数据分布可能与训练集存在差异(如不同光照条件下的人脸图像)。 > 示例:直接从监控摄像头获取的未标记视频流、电商平台未分类的用户评论。 #### 二、典型应用场景 ##### 1. **半监督学习(Semi-Supervised Learning)** - **场景**:少量标注数据 + 大量未标注野生数据 - **方法**: 1. 用标注数据训练初始模型 2. 对未标注数据生成伪标签(Pseudo-labeling) 3. 联合训练提升泛化能力 - **优势**:降低标注成本,提升模型鲁棒性[^2] ##### 2. **自监督学习(Self-Supervised Learning)** - **场景**:完全无标注的野生数据 - **方法**: - 通过数据自身构造代理任务(Pretext Task) - 图像:拼图重建、旋转角度预测 - 文本:掩码语言建模(如 BERT) - 学习通用表征后迁移到下游任务 - **案例**:人脸识别中使用未标注图像学习特征表达[^2] ##### 3. **异常检测(Anomaly Detection)** - **场景**:网络入侵检测、工业设备故障预警 - **方法**: 1. 用正常野生数据训练自动编码器(Autoencoder) 2. 重构误差 $||x - \text{decoder}(\text{encoder}(x))||^2$ 作为异常分数 3. 设定阈值识别异常点 ##### 4. **数据预处理与特征工程** - **降维处理**: 对高维野生数据(如文本、图像)使用 PCA 压缩: $$X_{\text{reduced}} = X \cdot W_k$$ 其中 $W_k$ 是前 $k$ 个特征向量组成的矩阵[^3] - **数据增强**: 扩充小样本数据集(如对未标注图像做旋转/裁剪) #### 三、实践挑战与解决方案 | **挑战** | **解决策略** | |-------------------------|---------------------------------------| | 数据噪声大 | 鲁棒模型(如随机森林)+ 异常值过滤 | | 特征维度灾难 | PCA/ t-SNE 降维[^3][^4] | | 分布偏移(Domain Shift)| 域自适应(Domain Adaptation) | | 存储与计算成本高 | 分布式处理(Spark)+ 特征哈希(Hashing) | > **典型流程**: > ```mermaid > graph LR > A[采集Wild Data] --> B[数据清洗] > B --> C[特征提取/降维] > C --> D[自监督预训练] > D --> E[下游任务微调] > ``` #### 四、价值与意义 1. **突破标注瓶颈**:利用海量野生数据减少对昂贵标注的依赖 2. **提升模型泛化性**:暴露模型于真实数据分布,避免过拟合 3. **发现隐藏模式**:挖掘数据内在结构(如用户行为聚类) --- ### 相关问题 1. 如何评估未标注数据对模型性能的提升效果? 2. 自监督学习中哪些代理任务最适合处理图像类野生数据? 3. 如何处理野生数据中的分布偏移(Domain Shift)问题? 4. 降维技术(如 PCA)在野生数据处理中有哪些局限性?[^3][^4] [^1]: 野生数据需经过清洗和特征工程才能有效利用 [^2]: 人脸识别等项目常依赖未标注数据预训练特征提取器 [^3]: PCA 降维可缓解高维野生数据的计算压力 [^4]: 现实世界数据常呈现高维特性,需特殊处理
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

私房菜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值