20 #include <linux/kernel.h>
21 #include <linux/slab.h>
22 #include <linux/errno.h>
35 avtab_insert_node(
struct avtab *
h,
int hvalue,
40 newnode = kmem_cache_zalloc(avtab_node_cachep,
GFP_KERNEL);
50 h->
htable[hvalue] = newnode;
66 hvalue = avtab_hash(key, h->
mask);
69 prev = cur, cur = cur->
next) {
73 (specified & cur->
key.specified))
86 newnode = avtab_insert_node(h, hvalue, prev, cur, key, datum);
106 hvalue = avtab_hash(key, h->
mask);
109 prev = cur, cur = cur->
next) {
113 (specified & cur->
key.specified))
125 return avtab_insert_node(h, hvalue, prev, cur, key, datum);
137 hvalue = avtab_hash(key, h->
mask);
138 for (cur = h->
htable[hvalue]; cur; cur = cur->
next) {
142 (specified & cur->
key.specified))
172 hvalue = avtab_hash(key, h->
mask);
173 for (cur = h->
htable[hvalue]; cur; cur = cur->
next) {
177 (specified & cur->
key.specified))
202 for (cur = node->
next; cur; cur = cur->
next) {
203 if (node->
key.source_type == cur->
key.source_type &&
204 node->
key.target_type == cur->
key.target_type &&
205 node->
key.target_class == cur->
key.target_class &&
206 (specified & cur->
key.specified))
209 if (node->
key.source_type < cur->
key.source_type)
211 if (node->
key.source_type == cur->
key.source_type &&
212 node->
key.target_type < cur->
key.target_type)
214 if (node->
key.source_type == cur->
key.source_type &&
215 node->
key.target_type == cur->
key.target_type &&
216 node->
key.target_class < cur->
key.target_class)
230 for (i = 0; i < h->
nslot; i++) {
260 goto avtab_alloc_out;
288 int i, chain_len, slots_used, max_chain_len;
289 unsigned long long chain2_len_sum;
295 for (i = 0; i < h->
nslot; i++) {
305 if (chain_len > max_chain_len)
306 max_chain_len = chain_len;
307 chain2_len_sum += chain_len * chain_len;
312 "longest chain length %d sum of chain length^2 %llu\n",
313 tag, h->
nel, slots_used, h->
nslot, max_chain_len,
344 rc = next_entry(buf32, fp,
sizeof(
u32));
355 rc = next_entry(buf32, fp,
sizeof(
u32)*items2);
390 printk(
KERN_ERR "SELinux: avtab: entry has both access vectors and types\n");
394 for (i = 0; i <
ARRAY_SIZE(spec_order); i++) {
395 if (val & spec_order[i]) {
398 rc = insertf(a, &key, &datum, p);
404 if (items != items2) {
405 printk(
KERN_ERR "SELinux: avtab: entry only had %d items, expected %d\n", items2, items);
411 rc = next_entry(buf16, fp,
sizeof(
u16)*4);
431 for (i = 0; i <
ARRAY_SIZE(spec_order); i++) {
435 if (!
set ||
set > 1) {
440 rc = next_entry(buf32, fp,
sizeof(
u32));
451 return insertf(a, &key, &datum, p);
457 return avtab_insert(a, k, d);
467 rc = next_entry(buf, fp,
sizeof(
u32));
483 for (i = 0; i < nel; i++) {
514 rc = put_entry(buf16,
sizeof(
u16), 4, fp);
518 rc = put_entry(buf32,
sizeof(
u32), 1, fp);
532 rc = put_entry(buf,
sizeof(
u32), 1, fp);
536 for (i = 0; i < a->
nslot; i++) {
537 for (cur = a->
htable[i]; cur; cur = cur->
next) {