函数源码

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source File:security\tomoyo\util.c Create Date:2022-07-27 21:17:45
首页 Copyright©Brick

1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
/**
 * tomoyo_domain_quota_is_ok - Check for domain's quota.
 *
 * @r: Pointer to "struct tomoyo_request_info".
 *
 * Returns true if the domain is not exceeded quota, false otherwise.
 *
 * Caller holds tomoyo_read_lock().
 */
bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r)
{
    unsigned int count = 0;
    struct tomoyo_domain_info *domain = r->domain;
    struct tomoyo_acl_info *ptr;
 
    if (r->mode != TOMOYO_CONFIG_LEARNING)
        return false;
    if (!domain)
        return true;
    list_for_each_entry_rcu(ptr, &domain->acl_info_list, list,
                srcu_read_lock_held(&tomoyo_ss)) {
        u16 perm;
        u8 i;
 
        if (ptr->is_deleted)
            continue;
        switch (ptr->type) {
        case TOMOYO_TYPE_PATH_ACL:
            perm = container_of(ptr, struct tomoyo_path_acl, head)
                ->perm;
            break;
        case TOMOYO_TYPE_PATH2_ACL:
            perm = container_of(ptr, struct tomoyo_path2_acl, head)
                ->perm;
            break;
        case TOMOYO_TYPE_PATH_NUMBER_ACL:
            perm = container_of(ptr, struct tomoyo_path_number_acl,
                        head)->perm;
            break;
        case TOMOYO_TYPE_MKDEV_ACL:
            perm = container_of(ptr, struct tomoyo_mkdev_acl,
                        head)->perm;
            break;
        case TOMOYO_TYPE_INET_ACL:
            perm = container_of(ptr, struct tomoyo_inet_acl,
                        head)->perm;
            break;
        case TOMOYO_TYPE_UNIX_ACL:
            perm = container_of(ptr, struct tomoyo_unix_acl,
                        head)->perm;
            break;
        case TOMOYO_TYPE_MANUAL_TASK_ACL:
            perm = 0;
            break;
        default:
            perm = 1;
        }
        for (i = 0; i < 16; i++)
            if (perm & (1 << i))
                count++;
    }
    if (count < tomoyo_profile(domain->ns, domain->profile)->
        pref[TOMOYO_PREF_MAX_LEARNING_ENTRY])
        return true;
    if (!domain->flags[TOMOYO_DIF_QUOTA_WARNED]) {
        domain->flags[TOMOYO_DIF_QUOTA_WARNED] = true;
        /* r->granted = false; */
        tomoyo_write_log(r, "%s", tomoyo_dif[TOMOYO_DIF_QUOTA_WARNED]);
#ifndef CONFIG_SECURITY_TOMOYO_INSECURE_BUILTIN_SETTING
        pr_warn("WARNING: Domain '%s' has too many ACLs to hold. Stopped learning mode.\n",
            domain->domainname->name);
#endif
    }
    return false;
}