函数源码

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source File:security\tomoyo\file.c Create Date:2022-07-27 21:11:08
首页 Copyright©Brick

893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
/**
 * tomoyo_path2_perm - Check permission for "rename", "link" and "pivot_root".
 *
 * @operation: Type of operation.
 * @path1:      Pointer to "struct path".
 * @path2:      Pointer to "struct path".
 *
 * Returns 0 on success, negative value otherwise.
 */
int tomoyo_path2_perm(const u8 operation, const struct path *path1,
              const struct path *path2)
{
    int error = -ENOMEM;
    struct tomoyo_path_info buf1;
    struct tomoyo_path_info buf2;
    struct tomoyo_request_info r;
    struct tomoyo_obj_info obj = {
        .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
        .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
    };
    int idx;
 
    if (tomoyo_init_request_info(&r, NULL, tomoyo_pp2mac[operation])
        == TOMOYO_CONFIG_DISABLED)
        return 0;
    buf1.name = NULL;
    buf2.name = NULL;
    idx = tomoyo_read_lock();
    if (!tomoyo_get_realpath(&buf1, path1) ||
        !tomoyo_get_realpath(&buf2, path2))
        goto out;
    switch (operation) {
    case TOMOYO_TYPE_RENAME:
    case TOMOYO_TYPE_LINK:
        if (!d_is_dir(path1->dentry))
            break;
        /* fall through */
    case TOMOYO_TYPE_PIVOT_ROOT:
        tomoyo_add_slash(&buf1);
        tomoyo_add_slash(&buf2);
        break;
    }
    r.obj = &obj;
    r.param_type = TOMOYO_TYPE_PATH2_ACL;
    r.param.path2.operation = operation;
    r.param.path2.filename1 = &buf1;
    r.param.path2.filename2 = &buf2;
    do {
        tomoyo_check_acl(&r, tomoyo_check_path2_acl);
        error = tomoyo_audit_path2_log(&r);
    } while (error == TOMOYO_RETRY_REQUEST);
 out:
    kfree(buf1.name);
    kfree(buf2.name);
    tomoyo_read_unlock(idx);
    if (r.mode != TOMOYO_CONFIG_ENFORCING)
        error = 0;
    return error;
}