Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp259484imm; Tue, 22 May 2018 18:19:25 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpAIaMR5LDUbG8LnNgVz+RRnaEihQd5jhGk7I5p6cBFoS5k346c/BQqcSDmhiAjAhPb+VYh X-Received: by 2002:a62:ca4a:: with SMTP id n71-v6mr747532pfg.149.1527038365433; Tue, 22 May 2018 18:19:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527038365; cv=none; d=google.com; s=arc-20160816; b=I43plM0+hhshclLv0VpSbyJsqwMkLd/BOisdEFpp12wDFJU6cSKRA3WJQFXxYSfaGi u+EVjvOAwzHfzVp/NVYuntNXbu3a45CMsRoRXzzEtTgCeGxBEXP1nACfAoC428Bb6emG 4MuWarfKJQ6wEh8ce+jXBEZ4n8kTv1kBgDg50UoApwEQ8rn2ueg0R+WbPGzffrhR1OfB BxxPTq4ay1Wfyhsp283UQteors51pfXe6Zitw5tmiSV16sxETCDAdbYxKFJQ+GsyX6nc xpJrftQVJRkzFT77ArAM8hSREwTdSPPY/BOs6qBpmDfuBe/32jkMkrqgw2JAog6yc4MO mhDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=fqcIWIBm6Hyuq9PYogvdxrGWMM3tXyyxXhWyaGvXexk=; b=gpc9d5Bhh2rewBS+iRxYu92SojGVNJTkdrctlqM+2KzE1Hj6gNlPrq0DznOytDh1in lGN5yrLDpcr2r86UU7jmlWtzr7s3vYPlxZOZRJoZ25ml7dAC5aT6fxmJ4X1UqLGOTzXg Lc0lFkacm9J0ZkzJHPklK5Nhn1MT5ClybtTc4FGZ/yv8mf46wFUVemAhJqtRCx2jsZVB 8x/XuF4xhdjfkktSYuDxDtkIvAuo2KiuLvs19YWvTnAw9WwC00byicq8xHDREJ5oDL2K XWtHkoce6ZPZoDlKx5r0QFPOl4jfPlR042tUfXPumpXd+nP7m1IfNhGdDmefCpGz7rRF UisA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=boMSu9Ug; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e11-v6si13030093pgs.476.2018.05.22.18.19.09; Tue, 22 May 2018 18:19:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=boMSu9Ug; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753715AbeEWBS6 (ORCPT + 99 others); Tue, 22 May 2018 21:18:58 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:45785 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753662AbeEWBSv (ORCPT ); Tue, 22 May 2018 21:18:51 -0400 Received: by mail-qk0-f194.google.com with SMTP id a8-v6so16184916qkj.12; Tue, 22 May 2018 18:18:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fqcIWIBm6Hyuq9PYogvdxrGWMM3tXyyxXhWyaGvXexk=; b=boMSu9UgWT7WoWR5EsJQv17c1oGWU52qqxg/uCwCxvfCpaHAM37Kgja4ujNJO9duIp 8NGIXrGDmOGv2Ilqrl97+SZ6XpB1d0bZFlVC3aPnHseK6Jl1LsLtLXREBqPU7Q+GY9JD hKfXRTRn203tK4brIFhB+jZQnicnwVS1bWNwUocnmyWIByltJbhEfigRp+/2baP+pza4 1oYPrhlyzFuiJFiaFAD/KI6k8L/mhfJa/Qz/vQLrZkh0p88BNPldzFkuCN99Eqsekrmu bI0xHNhwIOn5pC1u5W+WDmk5dl8eiqXfruPPao31rhkveoyWGQXtO6iUz6dd2lH3myFn GFDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fqcIWIBm6Hyuq9PYogvdxrGWMM3tXyyxXhWyaGvXexk=; b=Wq5fsIuXLWt8lImI68d51ITJ6Wb+jdENy9zuVh1QvMCTBrCQCuEmYWJTf2BUY37qoS XdjjY4bs22q1qUjp+2oX6jVZS/SWpPoufrtnaL/pSx/o/9pEkL3ngoinZb0V1FkUTJ/3 5Lke5IBh7ygNtqQKI6+XoDjxtBmVxrAjX1l6NTjTHZf92icdQ/pbKmOL4Et0sKOQyz9n MbxrF8rAsaHMWJDmnMXs6sMNxO0R7EYAx9RYI8y9+/GMhBz31YXb8q75GY4bFp8k0R6T A1+eKZ9taVrTJCIKY7HmiDL50CJJwkxIcP/TtYQQBucGezFplbOYPhAv4SoRlwehFGju BQSw== X-Gm-Message-State: ALKqPwfA7k9OArKPDwf414wzIAbVLC5WHqCUUUTm+gZXNOy2e6B0ZgxS vZl3UaSpOFaVRQfFF/ZhMmSALyJ31w== X-Received: by 2002:a37:6747:: with SMTP id b68-v6mr709134qkc.108.1527038329840; Tue, 22 May 2018 18:18:49 -0700 (PDT) Received: from localhost.localdomain (c-71-234-172-214.hsd1.vt.comcast.net. [71.234.172.214]) by smtp.gmail.com with ESMTPSA id s127-v6sm12604251qkf.21.2018.05.22.18.18.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 18:18:48 -0700 (PDT) From: Kent Overstreet To: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org, willy@infradead.org, gregkh@linuxfoundation.org, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, dev@openvswitch.org, shli@kernel.org, linux-raid@vger.kernel.org Cc: Kent Overstreet Subject: [PATCH 5/6] selinux: convert to genradix Date: Tue, 22 May 2018 21:18:20 -0400 Message-Id: <20180523011821.12165-5-kent.overstreet@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180523011821.12165-1-kent.overstreet@gmail.com> References: <20180523011821.12165-1-kent.overstreet@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org the new generic radix trees have a simpler API and implementation, and no limitations on number of elements, so all flex_array users are being converted Signed-off-by: Kent Overstreet --- security/selinux/ss/avtab.c | 44 +++++------ security/selinux/ss/avtab.h | 5 +- security/selinux/ss/conditional.c | 8 +- security/selinux/ss/policydb.c | 127 +++++++++++------------------- security/selinux/ss/policydb.h | 12 ++- security/selinux/ss/services.c | 25 +++--- 6 files changed, 86 insertions(+), 135 deletions(-) diff --git a/security/selinux/ss/avtab.c b/security/selinux/ss/avtab.c index 2c3c7d010d..7066d52e74 100644 --- a/security/selinux/ss/avtab.c +++ b/security/selinux/ss/avtab.c @@ -93,12 +93,10 @@ avtab_insert_node(struct avtab *h, int hvalue, newnode->next = prev->next; prev->next = newnode; } else { - newnode->next = flex_array_get_ptr(h->htable, hvalue); - if (flex_array_put_ptr(h->htable, hvalue, newnode, - GFP_KERNEL|__GFP_ZERO)) { - kmem_cache_free(avtab_node_cachep, newnode); - return NULL; - } + struct avtab_node **n = genradix_ptr(&h->htable, hvalue); + + newnode->next = *n; + *n = newnode; } h->nel++; @@ -111,11 +109,11 @@ static int avtab_insert(struct avtab *h, struct avtab_key *key, struct avtab_dat struct avtab_node *prev, *cur, *newnode; u16 specified = key->specified & ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD); - if (!h || !h->htable) + if (!h) return -EINVAL; hvalue = avtab_hash(key, h->mask); - for (prev = NULL, cur = flex_array_get_ptr(h->htable, hvalue); + for (prev = NULL, cur = *genradix_ptr(&h->htable, hvalue); cur; prev = cur, cur = cur->next) { if (key->source_type == cur->key.source_type && @@ -156,10 +154,10 @@ avtab_insert_nonunique(struct avtab *h, struct avtab_key *key, struct avtab_datu struct avtab_node *prev, *cur; u16 specified = key->specified & ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD); - if (!h || !h->htable) + if (!h) return NULL; hvalue = avtab_hash(key, h->mask); - for (prev = NULL, cur = flex_array_get_ptr(h->htable, hvalue); + for (prev = NULL, cur = *genradix_ptr(&h->htable, hvalue); cur; prev = cur, cur = cur->next) { if (key->source_type == cur->key.source_type && @@ -186,11 +184,11 @@ struct avtab_datum *avtab_search(struct avtab *h, struct avtab_key *key) struct avtab_node *cur; u16 specified = key->specified & ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD); - if (!h || !h->htable) + if (!h) return NULL; hvalue = avtab_hash(key, h->mask); - for (cur = flex_array_get_ptr(h->htable, hvalue); cur; + for (cur = *genradix_ptr(&h->htable, hvalue); cur; cur = cur->next) { if (key->source_type == cur->key.source_type && key->target_type == cur->key.target_type && @@ -222,11 +220,11 @@ avtab_search_node(struct avtab *h, struct avtab_key *key) struct avtab_node *cur; u16 specified = key->specified & ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD); - if (!h || !h->htable) + if (!h) return NULL; hvalue = avtab_hash(key, h->mask); - for (cur = flex_array_get_ptr(h->htable, hvalue); cur; + for (cur = *genradix_ptr(&h->htable, hvalue); cur; cur = cur->next) { if (key->source_type == cur->key.source_type && key->target_type == cur->key.target_type && @@ -281,11 +279,11 @@ void avtab_destroy(struct avtab *h) int i; struct avtab_node *cur, *temp; - if (!h || !h->htable) + if (!h) return; for (i = 0; i < h->nslot; i++) { - cur = flex_array_get_ptr(h->htable, i); + cur = *genradix_ptr(&h->htable, i); while (cur) { temp = cur; cur = cur->next; @@ -295,15 +293,14 @@ void avtab_destroy(struct avtab *h) kmem_cache_free(avtab_node_cachep, temp); } } - flex_array_free(h->htable); - h->htable = NULL; + genradix_free(&h->htable); h->nslot = 0; h->mask = 0; } int avtab_init(struct avtab *h) { - h->htable = NULL; + genradix_init(&h->htable); h->nel = 0; return 0; } @@ -329,9 +326,8 @@ int avtab_alloc(struct avtab *h, u32 nrules) nslot = MAX_AVTAB_HASH_BUCKETS; mask = nslot - 1; - h->htable = flex_array_alloc(sizeof(struct avtab_node *), nslot, - GFP_KERNEL | __GFP_ZERO); - if (!h->htable) + genradix_init(&h->htable); + if (genradix_prealloc(&h->htable, nslot, GFP_KERNEL)) return -ENOMEM; avtab_alloc_out: @@ -353,7 +349,7 @@ void avtab_hash_eval(struct avtab *h, char *tag) max_chain_len = 0; chain2_len_sum = 0; for (i = 0; i < h->nslot; i++) { - cur = flex_array_get_ptr(h->htable, i); + cur = *genradix_ptr(&h->htable, i); if (cur) { slots_used++; chain_len = 0; @@ -645,7 +641,7 @@ int avtab_write(struct policydb *p, struct avtab *a, void *fp) return rc; for (i = 0; i < a->nslot; i++) { - for (cur = flex_array_get_ptr(a->htable, i); cur; + for (cur = *genradix_ptr(&a->htable, i); cur; cur = cur->next) { rc = avtab_write_item(p, cur, fp); if (rc) diff --git a/security/selinux/ss/avtab.h b/security/selinux/ss/avtab.h index 725853cadc..7f00c41e96 100644 --- a/security/selinux/ss/avtab.h +++ b/security/selinux/ss/avtab.h @@ -24,7 +24,7 @@ #define _SS_AVTAB_H_ #include "security.h" -#include +#include struct avtab_key { u16 source_type; /* source type */ @@ -84,11 +84,10 @@ struct avtab_node { }; struct avtab { - struct flex_array *htable; + GENRADIX(struct avtab_node *) htable; u32 nel; /* number of elements */ u32 nslot; /* number of hash slots */ u32 mask; /* mask to compute hash func */ - }; int avtab_init(struct avtab *); diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c index c91543a617..d25ef70748 100644 --- a/security/selinux/ss/conditional.c +++ b/security/selinux/ss/conditional.c @@ -195,7 +195,6 @@ int cond_index_bool(void *key, void *datum, void *datap) { struct policydb *p; struct cond_bool_datum *booldatum; - struct flex_array *fa; booldatum = datum; p = datap; @@ -203,10 +202,9 @@ int cond_index_bool(void *key, void *datum, void *datap) if (!booldatum->value || booldatum->value > p->p_bools.nprim) return -EINVAL; - fa = p->sym_val_to_name[SYM_BOOLS]; - if (flex_array_put_ptr(fa, booldatum->value - 1, key, - GFP_KERNEL | __GFP_ZERO)) - BUG(); + *genradix_ptr(&p->sym_val_to_name[SYM_BOOLS], + booldatum->value - 1) = key; + p->bool_val_to_struct[booldatum->value - 1] = booldatum; return 0; diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index 6e8c8056d7..3df39258c9 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -36,7 +36,6 @@ #include #include #include -#include #include "security.h" #include "policydb.h" @@ -341,17 +340,15 @@ static int common_index(void *key, void *datum, void *datap) { struct policydb *p; struct common_datum *comdatum; - struct flex_array *fa; comdatum = datum; p = datap; if (!comdatum->value || comdatum->value > p->p_commons.nprim) return -EINVAL; - fa = p->sym_val_to_name[SYM_COMMONS]; - if (flex_array_put_ptr(fa, comdatum->value - 1, key, - GFP_KERNEL | __GFP_ZERO)) - BUG(); + *genradix_ptr(&p->sym_val_to_name[SYM_COMMONS], + comdatum->value - 1) = key; + return 0; } @@ -359,16 +356,15 @@ static int class_index(void *key, void *datum, void *datap) { struct policydb *p; struct class_datum *cladatum; - struct flex_array *fa; cladatum = datum; p = datap; if (!cladatum->value || cladatum->value > p->p_classes.nprim) return -EINVAL; - fa = p->sym_val_to_name[SYM_CLASSES]; - if (flex_array_put_ptr(fa, cladatum->value - 1, key, - GFP_KERNEL | __GFP_ZERO)) - BUG(); + + *genradix_ptr(&p->sym_val_to_name[SYM_CLASSES], + cladatum->value - 1) = key; + p->class_val_to_struct[cladatum->value - 1] = cladatum; return 0; } @@ -377,7 +373,6 @@ static int role_index(void *key, void *datum, void *datap) { struct policydb *p; struct role_datum *role; - struct flex_array *fa; role = datum; p = datap; @@ -386,10 +381,9 @@ static int role_index(void *key, void *datum, void *datap) || role->bounds > p->p_roles.nprim) return -EINVAL; - fa = p->sym_val_to_name[SYM_ROLES]; - if (flex_array_put_ptr(fa, role->value - 1, key, - GFP_KERNEL | __GFP_ZERO)) - BUG(); + *genradix_ptr(&p->sym_val_to_name[SYM_ROLES], + role->value - 1) = key; + p->role_val_to_struct[role->value - 1] = role; return 0; } @@ -398,7 +392,6 @@ static int type_index(void *key, void *datum, void *datap) { struct policydb *p; struct type_datum *typdatum; - struct flex_array *fa; typdatum = datum; p = datap; @@ -408,15 +401,11 @@ static int type_index(void *key, void *datum, void *datap) || typdatum->value > p->p_types.nprim || typdatum->bounds > p->p_types.nprim) return -EINVAL; - fa = p->sym_val_to_name[SYM_TYPES]; - if (flex_array_put_ptr(fa, typdatum->value - 1, key, - GFP_KERNEL | __GFP_ZERO)) - BUG(); + *genradix_ptr(&p->sym_val_to_name[SYM_TYPES], + typdatum->value - 1) = key; - fa = p->type_val_to_struct_array; - if (flex_array_put_ptr(fa, typdatum->value - 1, typdatum, - GFP_KERNEL | __GFP_ZERO)) - BUG(); + *genradix_ptr(&p->type_val_to_struct_array, + typdatum->value - 1) = typdatum; } return 0; @@ -426,7 +415,6 @@ static int user_index(void *key, void *datum, void *datap) { struct policydb *p; struct user_datum *usrdatum; - struct flex_array *fa; usrdatum = datum; p = datap; @@ -435,10 +423,9 @@ static int user_index(void *key, void *datum, void *datap) || usrdatum->bounds > p->p_users.nprim) return -EINVAL; - fa = p->sym_val_to_name[SYM_USERS]; - if (flex_array_put_ptr(fa, usrdatum->value - 1, key, - GFP_KERNEL | __GFP_ZERO)) - BUG(); + *genradix_ptr(&p->sym_val_to_name[SYM_USERS], + usrdatum->value - 1) = key; + p->user_val_to_struct[usrdatum->value - 1] = usrdatum; return 0; } @@ -447,7 +434,6 @@ static int sens_index(void *key, void *datum, void *datap) { struct policydb *p; struct level_datum *levdatum; - struct flex_array *fa; levdatum = datum; p = datap; @@ -456,10 +442,8 @@ static int sens_index(void *key, void *datum, void *datap) if (!levdatum->level->sens || levdatum->level->sens > p->p_levels.nprim) return -EINVAL; - fa = p->sym_val_to_name[SYM_LEVELS]; - if (flex_array_put_ptr(fa, levdatum->level->sens - 1, key, - GFP_KERNEL | __GFP_ZERO)) - BUG(); + *genradix_ptr(&p->sym_val_to_name[SYM_LEVELS], + levdatum->level->sens - 1) = key; } return 0; @@ -469,7 +453,6 @@ static int cat_index(void *key, void *datum, void *datap) { struct policydb *p; struct cat_datum *catdatum; - struct flex_array *fa; catdatum = datum; p = datap; @@ -477,10 +460,8 @@ static int cat_index(void *key, void *datum, void *datap) if (!catdatum->isalias) { if (!catdatum->value || catdatum->value > p->p_cats.nprim) return -EINVAL; - fa = p->sym_val_to_name[SYM_CATS]; - if (flex_array_put_ptr(fa, catdatum->value - 1, key, - GFP_KERNEL | __GFP_ZERO)) - BUG(); + *genradix_ptr(&p->sym_val_to_name[SYM_CATS], + catdatum->value - 1) = key; } return 0; @@ -566,15 +547,10 @@ static int policydb_index(struct policydb *p) if (!p->user_val_to_struct) return -ENOMEM; - /* Yes, I want the sizeof the pointer, not the structure */ - p->type_val_to_struct_array = flex_array_alloc(sizeof(struct type_datum *), - p->p_types.nprim, - GFP_KERNEL | __GFP_ZERO); - if (!p->type_val_to_struct_array) - return -ENOMEM; + genradix_init(&p->type_val_to_struct_array); - rc = flex_array_prealloc(p->type_val_to_struct_array, 0, - p->p_types.nprim, GFP_KERNEL | __GFP_ZERO); + rc = genradix_prealloc(&p->type_val_to_struct_array, + p->p_types.nprim, GFP_KERNEL); if (rc) goto out; @@ -583,15 +559,10 @@ static int policydb_index(struct policydb *p) goto out; for (i = 0; i < SYM_NUM; i++) { - p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *), - p->symtab[i].nprim, - GFP_KERNEL | __GFP_ZERO); - if (!p->sym_val_to_name[i]) - return -ENOMEM; + genradix_init(&p->sym_val_to_name[i]); - rc = flex_array_prealloc(p->sym_val_to_name[i], - 0, p->symtab[i].nprim, - GFP_KERNEL | __GFP_ZERO); + rc = genradix_prealloc(&p->sym_val_to_name[i], + p->symtab[i].nprim, GFP_KERNEL); if (rc) goto out; @@ -807,16 +778,13 @@ void policydb_destroy(struct policydb *p) hashtab_destroy(p->symtab[i].table); } - for (i = 0; i < SYM_NUM; i++) { - if (p->sym_val_to_name[i]) - flex_array_free(p->sym_val_to_name[i]); - } + for (i = 0; i < SYM_NUM; i++) + genradix_free(&p->sym_val_to_name[i]); kfree(p->class_val_to_struct); kfree(p->role_val_to_struct); kfree(p->user_val_to_struct); - if (p->type_val_to_struct_array) - flex_array_free(p->type_val_to_struct_array); + genradix_free(&p->type_val_to_struct_array); avtab_destroy(&p->te_avtab); @@ -869,17 +837,15 @@ void policydb_destroy(struct policydb *p) hashtab_map(p->range_tr, range_tr_destroy, NULL); hashtab_destroy(p->range_tr); - if (p->type_attr_map_array) { - for (i = 0; i < p->p_types.nprim; i++) { - struct ebitmap *e; + for (i = 0; i < p->p_types.nprim; i++) { + struct ebitmap *e; - e = flex_array_get(p->type_attr_map_array, i); - if (!e) - continue; - ebitmap_destroy(e); - } - flex_array_free(p->type_attr_map_array); + e = genradix_ptr(&p->type_attr_map_array, i); + if (!e) + continue; + ebitmap_destroy(e); } + genradix_free(&p->type_attr_map_array); ebitmap_destroy(&p->filename_trans_ttypes); ebitmap_destroy(&p->policycaps); @@ -1760,8 +1726,8 @@ static int type_bounds_sanity_check(void *key, void *datum, void *datap) return -EINVAL; } - upper = flex_array_get_ptr(p->type_val_to_struct_array, - upper->bounds - 1); + upper = *genradix_ptr(&p->type_val_to_struct_array, + upper->bounds - 1); BUG_ON(!upper); if (upper->attribute) { @@ -2518,21 +2484,16 @@ int policydb_read(struct policydb *p, void *fp) if (rc) goto bad; - rc = -ENOMEM; - p->type_attr_map_array = flex_array_alloc(sizeof(struct ebitmap), - p->p_types.nprim, - GFP_KERNEL | __GFP_ZERO); - if (!p->type_attr_map_array) - goto bad; + genradix_init(&p->type_attr_map_array); /* preallocate so we don't have to worry about the put ever failing */ - rc = flex_array_prealloc(p->type_attr_map_array, 0, p->p_types.nprim, - GFP_KERNEL | __GFP_ZERO); + rc = genradix_prealloc(&p->type_attr_map_array, p->p_types.nprim, + GFP_KERNEL); if (rc) goto bad; for (i = 0; i < p->p_types.nprim; i++) { - struct ebitmap *e = flex_array_get(p->type_attr_map_array, i); + struct ebitmap *e = genradix_ptr(&p->type_attr_map_array, i); BUG_ON(!e); ebitmap_init(e); @@ -3523,7 +3484,7 @@ int policydb_write(struct policydb *p, void *fp) return rc; for (i = 0; i < p->p_types.nprim; i++) { - struct ebitmap *e = flex_array_get(p->type_attr_map_array, i); + struct ebitmap *e = genradix_ptr(&p->type_attr_map_array, i); BUG_ON(!e); rc = ebitmap_write(e, fp); diff --git a/security/selinux/ss/policydb.h b/security/selinux/ss/policydb.h index 215f8f30ac..1ba102463e 100644 --- a/security/selinux/ss/policydb.h +++ b/security/selinux/ss/policydb.h @@ -24,7 +24,7 @@ #ifndef _SS_POLICYDB_H_ #define _SS_POLICYDB_H_ -#include +#include #include "symtab.h" #include "avtab.h" @@ -251,13 +251,13 @@ struct policydb { #define p_cats symtab[SYM_CATS] /* symbol names indexed by (value - 1) */ - struct flex_array *sym_val_to_name[SYM_NUM]; + GENRADIX(char *) sym_val_to_name[SYM_NUM]; /* class, role, and user attributes indexed by (value - 1) */ struct class_datum **class_val_to_struct; struct role_datum **role_val_to_struct; struct user_datum **user_val_to_struct; - struct flex_array *type_val_to_struct_array; + GENRADIX(struct type_datum *) type_val_to_struct_array; /* type enforcement access vectors and transitions */ struct avtab te_avtab; @@ -294,7 +294,7 @@ struct policydb { struct hashtab *range_tr; /* type -> attribute reverse mapping */ - struct flex_array *type_attr_map_array; + GENRADIX(struct ebitmap) type_attr_map_array; struct ebitmap policycaps; @@ -369,9 +369,7 @@ static inline int put_entry(const void *buf, size_t bytes, int num, struct polic static inline char *sym_name(struct policydb *p, unsigned int sym_num, unsigned int element_nr) { - struct flex_array *fa = p->sym_val_to_name[sym_num]; - - return flex_array_get_ptr(fa, element_nr); + return *genradix_ptr(&p->sym_val_to_name[sym_num], element_nr); } extern u16 string_to_security_class(struct policydb *p, const char *name); diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index 8900ea5cba..79a56e4653 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -50,7 +50,6 @@ #include #include #include -#include #include #include @@ -562,15 +561,15 @@ static void type_attribute_bounds_av(struct context *scontext, struct type_datum *target; u32 masked = 0; - source = flex_array_get_ptr(policydb.type_val_to_struct_array, - scontext->type - 1); + source = *genradix_ptr(&policydb.type_val_to_struct_array, + scontext->type - 1); BUG_ON(!source); if (!source->bounds) return; - target = flex_array_get_ptr(policydb.type_val_to_struct_array, - tcontext->type - 1); + target = *genradix_ptr(&policydb.type_val_to_struct_array, + tcontext->type - 1); BUG_ON(!target); memset(&lo_avd, 0, sizeof(lo_avd)); @@ -669,9 +668,9 @@ static void context_struct_compute_av(struct context *scontext, */ avkey.target_class = tclass; avkey.specified = AVTAB_AV | AVTAB_XPERMS; - sattr = flex_array_get(policydb.type_attr_map_array, scontext->type - 1); + sattr = genradix_ptr(&policydb.type_attr_map_array, scontext->type - 1); BUG_ON(!sattr); - tattr = flex_array_get(policydb.type_attr_map_array, tcontext->type - 1); + tattr = genradix_ptr(&policydb.type_attr_map_array, tcontext->type - 1); BUG_ON(!tattr); ebitmap_for_each_positive_bit(sattr, snode, i) { ebitmap_for_each_positive_bit(tattr, tnode, j) { @@ -895,8 +894,8 @@ int security_bounded_transition(u32 old_sid, u32 new_sid) index = new_context->type; while (true) { - type = flex_array_get_ptr(policydb.type_val_to_struct_array, - index - 1); + type = *genradix_ptr(&policydb.type_val_to_struct_array, + index - 1); BUG_ON(!type); /* not bounded anymore */ @@ -1053,11 +1052,11 @@ void security_compute_xperms_decision(u32 ssid, avkey.target_class = tclass; avkey.specified = AVTAB_XPERMS; - sattr = flex_array_get(policydb.type_attr_map_array, - scontext->type - 1); + sattr = genradix_ptr(&policydb.type_attr_map_array, + scontext->type - 1); BUG_ON(!sattr); - tattr = flex_array_get(policydb.type_attr_map_array, - tcontext->type - 1); + tattr = genradix_ptr(&policydb.type_attr_map_array, + tcontext->type - 1); BUG_ON(!tattr); ebitmap_for_each_positive_bit(sattr, snode, i) { ebitmap_for_each_positive_bit(tattr, tnode, j) { -- 2.17.0