// SPDX-License-Identifier: GPL-2.0 /* * SafeSetID Linux Security Module * * Author: Micah Morton <mortonm@chromium.org> * * Copyright (C) 2018 The Chromium OS Authors. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. *
*/
/* * In the case the input buffer contains one or more invalid IDs, the kid_t * variables pointed to by @parent and @child will get updated but this * function will return an error. * Contents of @buf may be modified.
*/ staticint parse_policy_line(struct file *file, char *buf, struct setid_rule *rule)
{ char *child_str; int ret;
u32 parsed_parent, parsed_child;
/* Format of |buf| string should be <UID>:<UID> or <GID>:<GID> */
child_str = strchr(buf, ':'); if (child_str == NULL) return -EINVAL;
*child_str = '\0';
child_str++;
ret = kstrtou32(buf, 0, &parsed_parent); if (ret) return ret;
ret = kstrtou32(child_str, 0, &parsed_child); if (ret) return ret;
if (rule->type == UID){
rule->src_id.uid = make_kuid(file->f_cred->user_ns, parsed_parent);
rule->dst_id.uid = make_kuid(file->f_cred->user_ns, parsed_child); if (!uid_valid(rule->src_id.uid) || !uid_valid(rule->dst_id.uid)) return -EINVAL;
} elseif (rule->type == GID){
rule->src_id.gid = make_kgid(file->f_cred->user_ns, parsed_parent);
rule->dst_id.gid = make_kgid(file->f_cred->user_ns, parsed_child); if (!gid_valid(rule->src_id.gid) || !gid_valid(rule->dst_id.gid)) return -EINVAL;
} else { /* Error, rule->type is an invalid type */ return -EINVAL;
} return 0;
}
err = verify_ruleset(pol); /* bogus policy falls through after fixing it up */ if (err && err != -EINVAL) goto out_free_buf;
/* * Everything looks good, apply the policy and release the old one. * What we really want here is an xchg() wrapper for RCU, but since that * doesn't currently exist, just use a spinlock for now.
*/ if (policy_type == UID) {
mutex_lock(&uid_policy_update_lock);
pol = rcu_replace_pointer(safesetid_setuid_rules, pol,
lockdep_is_held(&uid_policy_update_lock));
mutex_unlock(&uid_policy_update_lock);
} elseif (policy_type == GID) {
mutex_lock(&gid_policy_update_lock);
pol = rcu_replace_pointer(safesetid_setgid_rules, pol,
lockdep_is_held(&gid_policy_update_lock));
mutex_unlock(&gid_policy_update_lock);
} else { /* Error, policy type is neither UID or GID */
pr_warn("error: bad policy type");
}
err = len;
out_free_buf:
kfree(buf);
out_free_pol: if (pol)
release_ruleset(pol); return err;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.