18 #include <linux/kernel.h>
19 #include <linux/slab.h>
20 #include <linux/errno.h>
25 #define BITS_PER_U64 (sizeof(u64) * 8)
77 #ifdef CONFIG_NETLABEL
88 int ebitmap_netlbl_export(
struct ebitmap *ebmap,
93 u32 cmap_idx, cmap_sft;
103 if (e_iter ==
NULL) {
108 c_iter = netlbl_secattr_catmap_alloc(
GFP_ATOMIC);
116 unsigned int delta, e_startbit, c_endbit;
120 if (e_startbit >= c_endbit) {
124 goto netlbl_export_failure;
125 c_iter = c_iter->
next;
129 delta = e_startbit - c_iter->
startbit;
133 |= e_iter->
maps[
i] << cmap_sft;
135 e_iter = e_iter->
next;
140 netlbl_export_failure:
141 netlbl_secattr_catmap_free(*catmap);
155 int ebitmap_netlbl_import(
struct ebitmap *ebmap,
161 u32 c_idx, c_pos, e_idx, e_sft;
182 e_iter = kzalloc(
sizeof(*e_iter),
GFP_ATOMIC);
184 goto netlbl_import_failure;
187 if (emap_prev ==
NULL)
188 ebmap->
node = e_iter;
190 emap_prev->
next = e_iter;
197 e_iter->
maps[e_idx++] |= map & (-1
UL);
201 c_iter = c_iter->
next;
210 netlbl_import_failure:
256 return ebitmap_node_get_bit(n, bit);
272 ebitmap_node_set_bit(n, bit);
276 ebitmap_node_clr_bit(n, bit);
314 ebitmap_node_set_bit(
new, bit);
321 new->next = prev->
next;
360 rc = next_entry(buf, fp,
sizeof buf);
370 "match my size %Zd (high bit was %d)\n",
384 for (i = 0; i <
count; i++) {
385 rc = next_entry(&startbit, fp,
sizeof(
u32));
392 if (startbit & (mapunit - 1)) {
394 "not a multiple of the map unit size (%u)\n",
398 if (startbit > e->
highbit - mapunit) {
400 "beyond the end of the bitmap (%u)\n",
401 startbit, (e->
highbit - mapunit));
410 "SELinux: ebitmap: out of memory\n");
421 }
else if (startbit <= n->startbit) {
423 " comes after start bit %d\n",
428 rc = next_entry(&map, fp,
sizeof(
u64));
437 n->
maps[index++] = map & (-1
UL);
458 int bit, last_bit, last_startbit,
rc;
468 last_startbit =
rounddown(bit, BITS_PER_U64);
470 last_bit =
roundup(bit + 1, BITS_PER_U64);
475 rc = put_entry(buf,
sizeof(
u32), 3, fp);
487 last_startbit =
rounddown(bit, BITS_PER_U64);
488 map = (
u64)1 << (bit - last_startbit);
494 rc = put_entry(buf,
sizeof(
u32), 1, fp);
499 rc = put_entry(buf64,
sizeof(
u64), 1, fp);
505 last_startbit =
rounddown(bit, BITS_PER_U64);
507 map |= (
u64)1 << (bit - last_startbit);
515 rc = put_entry(buf,
sizeof(
u32), 1, fp);
520 rc = put_entry(buf64,
sizeof(
u64), 1, fp);