kernel: fmt
This commit is contained in:
@@ -19,16 +19,16 @@ static struct avtab_node *get_avtab_node(struct policydb *db,
|
||||
struct avtab_extended_perms *xperms);
|
||||
|
||||
static bool add_rule(struct policydb *db, const char *s, const char *t,
|
||||
const char *c, const char *p, int effect, bool invert);
|
||||
const char *c, const char *p, int effect, bool invert);
|
||||
|
||||
static void add_rule_raw(struct policydb *db, struct type_datum *src,
|
||||
struct type_datum *tgt, struct class_datum *cls,
|
||||
struct perm_datum *perm, int effect, bool invert);
|
||||
|
||||
static void add_xperm_rule_raw(struct policydb *db, struct type_datum *src,
|
||||
struct type_datum *tgt, struct class_datum *cls,
|
||||
uint16_t low, uint16_t high, int effect,
|
||||
bool invert);
|
||||
struct type_datum *tgt, struct class_datum *cls,
|
||||
uint16_t low, uint16_t high, int effect,
|
||||
bool invert);
|
||||
static bool add_xperm_rule(struct policydb *db, const char *s, const char *t,
|
||||
const char *c, const char *range, int effect,
|
||||
bool invert);
|
||||
@@ -37,8 +37,8 @@ static bool add_type_rule(struct policydb *db, const char *s, const char *t,
|
||||
const char *c, const char *d, int effect);
|
||||
|
||||
static bool add_filename_trans(struct policydb *db, const char *s,
|
||||
const char *t, const char *c, const char *d,
|
||||
const char *o);
|
||||
const char *t, const char *c, const char *d,
|
||||
const char *o);
|
||||
|
||||
static bool add_genfscon(struct policydb *db, const char *fs_name,
|
||||
const char *path, const char *context);
|
||||
@@ -52,7 +52,7 @@ static void add_typeattribute_raw(struct policydb *db, struct type_datum *type,
|
||||
struct type_datum *attr);
|
||||
|
||||
static bool add_typeattribute(struct policydb *db, const char *type,
|
||||
const char *attr);
|
||||
const char *attr);
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Implementation
|
||||
@@ -62,18 +62,18 @@ static bool add_typeattribute(struct policydb *db, const char *type,
|
||||
// rules
|
||||
#define strip_av(effect, invert) ((effect == AVTAB_AUDITDENY) == !invert)
|
||||
|
||||
#define ksu_hash_for_each(node_ptr, n_slot, cur) \
|
||||
int i; \
|
||||
for (i = 0; i < n_slot; ++i) \
|
||||
#define ksu_hash_for_each(node_ptr, n_slot, cur) \
|
||||
int i; \
|
||||
for (i = 0; i < n_slot; ++i) \
|
||||
for (cur = node_ptr[i]; cur; cur = cur->next)
|
||||
|
||||
// htable is a struct instead of pointer above 5.8.0:
|
||||
// https://elixir.bootlin.com/linux/v5.8-rc1/source/security/selinux/ss/symtab.h
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0)
|
||||
#define ksu_hashtab_for_each(htab, cur) \
|
||||
#define ksu_hashtab_for_each(htab, cur) \
|
||||
ksu_hash_for_each(htab.htable, htab.size, cur)
|
||||
#else
|
||||
#define ksu_hashtab_for_each(htab, cur) \
|
||||
#define ksu_hashtab_for_each(htab, cur) \
|
||||
ksu_hash_for_each(htab->htable, htab->size, cur)
|
||||
#endif
|
||||
|
||||
@@ -84,7 +84,7 @@ static bool add_typeattribute(struct policydb *db, const char *type,
|
||||
#define symtab_insert(s, name, datum) hashtab_insert((s)->table, name, datum)
|
||||
#endif
|
||||
|
||||
#define avtab_for_each(avtab, cur) \
|
||||
#define avtab_for_each(avtab, cur) \
|
||||
ksu_hash_for_each(avtab.htable, avtab.nslot, cur);
|
||||
|
||||
static struct avtab_node *get_avtab_node(struct policydb *db,
|
||||
@@ -99,8 +99,8 @@ static struct avtab_node *get_avtab_node(struct policydb *db,
|
||||
node = avtab_search_node(&db->te_avtab, key);
|
||||
while (node) {
|
||||
if ((node->datum.u.xperms->specified ==
|
||||
xperms->specified) &&
|
||||
(node->datum.u.xperms->driver == xperms->driver)) {
|
||||
xperms->specified) &&
|
||||
(node->datum.u.xperms->driver == xperms->driver)) {
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
@@ -115,9 +115,9 @@ static struct avtab_node *get_avtab_node(struct policydb *db,
|
||||
if (!node) {
|
||||
struct avtab_datum avdatum = {};
|
||||
/*
|
||||
* AUDITDENY, aka DONTAUDIT, are &= assigned, versus |= for
|
||||
* others. Initialize the data accordingly.
|
||||
*/
|
||||
* AUDITDENY, aka DONTAUDIT, are &= assigned, versus |= for
|
||||
* others. Initialize the data accordingly.
|
||||
*/
|
||||
if (key->specified & AVTAB_XPERMS) {
|
||||
avdatum.u.xperms = xperms;
|
||||
} else {
|
||||
@@ -133,7 +133,7 @@ static struct avtab_node *get_avtab_node(struct policydb *db,
|
||||
grow_size += sizeof(u8);
|
||||
grow_size += sizeof(u8);
|
||||
grow_size += sizeof(u32) *
|
||||
ARRAY_SIZE(avdatum.u.xperms->perms.p);
|
||||
ARRAY_SIZE(avdatum.u.xperms->perms.p);
|
||||
}
|
||||
db->len += grow_size;
|
||||
}
|
||||
@@ -142,7 +142,7 @@ static struct avtab_node *get_avtab_node(struct policydb *db,
|
||||
}
|
||||
|
||||
static bool add_rule(struct policydb *db, const char *s, const char *t,
|
||||
const char *c, const char *p, int effect, bool invert)
|
||||
const char *c, const char *p, int effect, bool invert)
|
||||
{
|
||||
struct type_datum *src = NULL, *tgt = NULL;
|
||||
struct class_datum *cls = NULL;
|
||||
@@ -202,8 +202,8 @@ static void add_rule_raw(struct policydb *db, struct type_datum *src,
|
||||
ksu_hashtab_for_each(db->p_types.table, node)
|
||||
{
|
||||
add_rule_raw(db,
|
||||
(struct type_datum *)node->datum,
|
||||
tgt, cls, perm, effect, invert);
|
||||
(struct type_datum *)node->datum,
|
||||
tgt, cls, perm, effect, invert);
|
||||
};
|
||||
} else {
|
||||
ksu_hashtab_for_each(db->p_types.table, node)
|
||||
@@ -212,7 +212,7 @@ static void add_rule_raw(struct policydb *db, struct type_datum *src,
|
||||
(struct type_datum *)(node->datum);
|
||||
if (type->attribute) {
|
||||
add_rule_raw(db, type, tgt, cls, perm,
|
||||
effect, invert);
|
||||
effect, invert);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -222,8 +222,8 @@ static void add_rule_raw(struct policydb *db, struct type_datum *src,
|
||||
ksu_hashtab_for_each(db->p_types.table, node)
|
||||
{
|
||||
add_rule_raw(db, src,
|
||||
(struct type_datum *)node->datum,
|
||||
cls, perm, effect, invert);
|
||||
(struct type_datum *)node->datum,
|
||||
cls, perm, effect, invert);
|
||||
};
|
||||
} else {
|
||||
ksu_hashtab_for_each(db->p_types.table, node)
|
||||
@@ -232,7 +232,7 @@ static void add_rule_raw(struct policydb *db, struct type_datum *src,
|
||||
(struct type_datum *)(node->datum);
|
||||
if (type->attribute) {
|
||||
add_rule_raw(db, src, type, cls, perm,
|
||||
effect, invert);
|
||||
effect, invert);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -241,8 +241,8 @@ static void add_rule_raw(struct policydb *db, struct type_datum *src,
|
||||
ksu_hashtab_for_each(db->p_classes.table, node)
|
||||
{
|
||||
add_rule_raw(db, src, tgt,
|
||||
(struct class_datum *)node->datum, perm,
|
||||
effect, invert);
|
||||
(struct class_datum *)node->datum, perm,
|
||||
effect, invert);
|
||||
}
|
||||
} else {
|
||||
struct avtab_key key;
|
||||
@@ -275,9 +275,9 @@ static void add_rule_raw(struct policydb *db, struct type_datum *src,
|
||||
#define xperm_clear(x, p) (p[x >> 5] &= ~(1 << (x & 0x1f)))
|
||||
|
||||
static void add_xperm_rule_raw(struct policydb *db, struct type_datum *src,
|
||||
struct type_datum *tgt, struct class_datum *cls,
|
||||
uint16_t low, uint16_t high, int effect,
|
||||
bool invert)
|
||||
struct type_datum *tgt, struct class_datum *cls,
|
||||
uint16_t low, uint16_t high, int effect,
|
||||
bool invert)
|
||||
{
|
||||
if (src == NULL) {
|
||||
struct hashtab_node *node;
|
||||
@@ -331,7 +331,7 @@ static void add_xperm_rule_raw(struct policydb *db, struct type_datum *src,
|
||||
int i;
|
||||
if (xperms.specified == AVTAB_XPERMS_IOCTLDRIVER) {
|
||||
for (i = ioctl_driver(low); i <= ioctl_driver(high);
|
||||
++i) {
|
||||
++i) {
|
||||
if (invert)
|
||||
xperm_clear(i, xperms.perms.p);
|
||||
else
|
||||
@@ -497,8 +497,8 @@ static const struct hashtab_key_params filenametr_key_params = {
|
||||
#endif
|
||||
|
||||
static bool add_filename_trans(struct policydb *db, const char *s,
|
||||
const char *t, const char *c, const char *d,
|
||||
const char *o)
|
||||
const char *t, const char *c, const char *d,
|
||||
const char *o)
|
||||
{
|
||||
struct type_datum *src, *tgt, *def;
|
||||
struct class_datum *cls;
|
||||
@@ -553,16 +553,16 @@ static bool add_filename_trans(struct policydb *db, const char *s,
|
||||
|
||||
if (trans == NULL) {
|
||||
trans = (struct filename_trans_datum *)kcalloc(sizeof(*trans),
|
||||
1, GFP_ATOMIC);
|
||||
1, GFP_ATOMIC);
|
||||
struct filename_trans_key *new_key =
|
||||
(struct filename_trans_key *)kzalloc(sizeof(*new_key),
|
||||
GFP_ATOMIC);
|
||||
GFP_ATOMIC);
|
||||
*new_key = key;
|
||||
new_key->name = kstrdup(key.name, GFP_ATOMIC);
|
||||
trans->next = last;
|
||||
trans->otype = def->value;
|
||||
hashtab_insert(&db->filename_trans, new_key, trans,
|
||||
filenametr_key_params);
|
||||
filenametr_key_params);
|
||||
}
|
||||
|
||||
db->compat_filename_trans_count++;
|
||||
@@ -579,7 +579,7 @@ static bool add_filename_trans(struct policydb *db, const char *s,
|
||||
|
||||
if (trans == NULL) {
|
||||
trans = (struct filename_trans_datum *)kcalloc(sizeof(*trans),
|
||||
1, GFP_ATOMIC);
|
||||
1, GFP_ATOMIC);
|
||||
if (!trans) {
|
||||
pr_err("add_filename_trans: Failed to alloc datum\n");
|
||||
return false;
|
||||
@@ -598,7 +598,7 @@ static bool add_filename_trans(struct policydb *db, const char *s,
|
||||
}
|
||||
|
||||
return ebitmap_set_bit(&db->filename_trans_ttypes, src->value - 1, 1) ==
|
||||
0;
|
||||
0;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -635,7 +635,7 @@ static bool add_type(struct policydb *db, const char *type_name, bool attr)
|
||||
|
||||
u32 value = ++db->p_types.nprim;
|
||||
type = (struct type_datum *)kzalloc(sizeof(struct type_datum),
|
||||
GFP_ATOMIC);
|
||||
GFP_ATOMIC);
|
||||
if (!type) {
|
||||
pr_err("add_type: alloc type_datum failed.\n");
|
||||
return false;
|
||||
@@ -659,8 +659,8 @@ static bool add_type(struct policydb *db, const char *type_name, bool attr)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0)
|
||||
struct ebitmap *new_type_attr_map_array =
|
||||
ksu_realloc(db->type_attr_map_array,
|
||||
value * sizeof(struct ebitmap),
|
||||
(value - 1) * sizeof(struct ebitmap));
|
||||
value * sizeof(struct ebitmap),
|
||||
(value - 1) * sizeof(struct ebitmap));
|
||||
|
||||
if (!new_type_attr_map_array) {
|
||||
pr_err("add_type: alloc type_attr_map_array failed\n");
|
||||
@@ -669,8 +669,8 @@ static bool add_type(struct policydb *db, const char *type_name, bool attr)
|
||||
|
||||
struct type_datum **new_type_val_to_struct =
|
||||
ksu_realloc(db->type_val_to_struct,
|
||||
sizeof(*db->type_val_to_struct) * value,
|
||||
sizeof(*db->type_val_to_struct) * (value - 1));
|
||||
sizeof(*db->type_val_to_struct) * value,
|
||||
sizeof(*db->type_val_to_struct) * (value - 1));
|
||||
|
||||
if (!new_type_val_to_struct) {
|
||||
pr_err("add_type: alloc type_val_to_struct failed\n");
|
||||
@@ -679,8 +679,8 @@ static bool add_type(struct policydb *db, const char *type_name, bool attr)
|
||||
|
||||
char **new_val_to_name_types =
|
||||
ksu_realloc(db->sym_val_to_name[SYM_TYPES],
|
||||
sizeof(char *) * value,
|
||||
sizeof(char *) * (value - 1));
|
||||
sizeof(char *) * value,
|
||||
sizeof(char *) * (value - 1));
|
||||
if (!new_val_to_name_types) {
|
||||
pr_err("add_type: alloc val_to_name failed\n");
|
||||
return false;
|
||||
@@ -809,7 +809,7 @@ static bool add_type(struct policydb *db, const char *type_name, bool attr)
|
||||
old_elem = flex_array_get(db->type_attr_map_array, j);
|
||||
if (old_elem)
|
||||
flex_array_put(new_type_attr_map_array, j, old_elem,
|
||||
GFP_ATOMIC | __GFP_ZERO);
|
||||
GFP_ATOMIC | __GFP_ZERO);
|
||||
}
|
||||
|
||||
for (j = 0; j < db->type_val_to_struct_array->total_nr_elements; j++) {
|
||||
@@ -880,7 +880,7 @@ static bool set_type_state(struct policydb *db, const char *type_name,
|
||||
{
|
||||
type = (struct type_datum *)(node->datum);
|
||||
if (ebitmap_set_bit(&db->permissive_map, type->value,
|
||||
permissive))
|
||||
permissive))
|
||||
pr_info("Could not set bit in permissive map\n");
|
||||
};
|
||||
} else {
|
||||
@@ -891,7 +891,7 @@ static bool set_type_state(struct policydb *db, const char *type_name,
|
||||
return false;
|
||||
}
|
||||
if (ebitmap_set_bit(&db->permissive_map, type->value,
|
||||
permissive)) {
|
||||
permissive)) {
|
||||
pr_info("Could not set bit in permissive map\n");
|
||||
return false;
|
||||
}
|
||||
@@ -909,7 +909,7 @@ static void add_typeattribute_raw(struct policydb *db, struct type_datum *type,
|
||||
* HISI_SELINUX_EBITMAP_RO is Huawei's unique features.
|
||||
*/
|
||||
struct ebitmap *sattr = &db->type_attr_map[type->value - 1],
|
||||
HISI_SELINUX_EBITMAP_RO;
|
||||
HISI_SELINUX_EBITMAP_RO;
|
||||
#else
|
||||
struct ebitmap *sattr =
|
||||
flex_array_get(db->type_attr_map_array, type->value - 1);
|
||||
@@ -925,8 +925,8 @@ static void add_typeattribute_raw(struct policydb *db, struct type_datum *type,
|
||||
for (n = cls->constraints; n; n = n->next) {
|
||||
for (e = n->expr; e; e = e->next) {
|
||||
if (e->expr_type == CEXPR_NAMES &&
|
||||
ebitmap_get_bit(&e->type_names->types,
|
||||
attr->value - 1)) {
|
||||
ebitmap_get_bit(&e->type_names->types,
|
||||
attr->value - 1)) {
|
||||
ebitmap_set_bit(&e->names,
|
||||
type->value - 1, 1);
|
||||
}
|
||||
@@ -936,7 +936,7 @@ static void add_typeattribute_raw(struct policydb *db, struct type_datum *type,
|
||||
}
|
||||
|
||||
static bool add_typeattribute(struct policydb *db, const char *type,
|
||||
const char *attr)
|
||||
const char *attr)
|
||||
{
|
||||
struct type_datum *type_d = symtab_search(&db->p_types, type);
|
||||
if (type_d == NULL) {
|
||||
@@ -995,19 +995,19 @@ bool ksu_exists(struct policydb *db, const char *type)
|
||||
|
||||
// Access vector rules
|
||||
bool ksu_allow(struct policydb *db, const char *src, const char *tgt,
|
||||
const char *cls, const char *perm)
|
||||
const char *cls, const char *perm)
|
||||
{
|
||||
return add_rule(db, src, tgt, cls, perm, AVTAB_ALLOWED, false);
|
||||
}
|
||||
|
||||
bool ksu_deny(struct policydb *db, const char *src, const char *tgt,
|
||||
const char *cls, const char *perm)
|
||||
const char *cls, const char *perm)
|
||||
{
|
||||
return add_rule(db, src, tgt, cls, perm, AVTAB_ALLOWED, true);
|
||||
}
|
||||
|
||||
bool ksu_auditallow(struct policydb *db, const char *src, const char *tgt,
|
||||
const char *cls, const char *perm)
|
||||
const char *cls, const char *perm)
|
||||
{
|
||||
return add_rule(db, src, tgt, cls, perm, AVTAB_AUDITALLOW, false);
|
||||
}
|
||||
@@ -1019,24 +1019,24 @@ bool ksu_dontaudit(struct policydb *db, const char *src, const char *tgt,
|
||||
|
||||
// Extended permissions access vector rules
|
||||
bool ksu_allowxperm(struct policydb *db, const char *src, const char *tgt,
|
||||
const char *cls, const char *range)
|
||||
const char *cls, const char *range)
|
||||
{
|
||||
return add_xperm_rule(db, src, tgt, cls, range, AVTAB_XPERMS_ALLOWED,
|
||||
false);
|
||||
false);
|
||||
}
|
||||
|
||||
bool ksu_auditallowxperm(struct policydb *db, const char *src, const char *tgt,
|
||||
const char *cls, const char *range)
|
||||
{
|
||||
return add_xperm_rule(db, src, tgt, cls, range, AVTAB_XPERMS_AUDITALLOW,
|
||||
false);
|
||||
false);
|
||||
}
|
||||
|
||||
bool ksu_dontauditxperm(struct policydb *db, const char *src, const char *tgt,
|
||||
const char *cls, const char *range)
|
||||
{
|
||||
return add_xperm_rule(db, src, tgt, cls, range, AVTAB_XPERMS_DONTAUDIT,
|
||||
false);
|
||||
false);
|
||||
}
|
||||
|
||||
// Type rules
|
||||
@@ -1051,13 +1051,13 @@ bool ksu_type_transition(struct policydb *db, const char *src, const char *tgt,
|
||||
}
|
||||
|
||||
bool ksu_type_change(struct policydb *db, const char *src, const char *tgt,
|
||||
const char *cls, const char *def)
|
||||
const char *cls, const char *def)
|
||||
{
|
||||
return add_type_rule(db, src, tgt, cls, def, AVTAB_CHANGE);
|
||||
}
|
||||
|
||||
bool ksu_type_member(struct policydb *db, const char *src, const char *tgt,
|
||||
const char *cls, const char *def)
|
||||
const char *cls, const char *def)
|
||||
{
|
||||
return add_type_rule(db, src, tgt, cls, def, AVTAB_MEMBER);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user