hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/security/selinux/ss/ebitmap.c
....@@ -19,6 +19,7 @@
1919 #include <linux/kernel.h>
2020 #include <linux/slab.h>
2121 #include <linux/errno.h>
22
+#include <linux/jhash.h>
2223 #include <net/netlabel.h>
2324 #include "ebitmap.h"
2425 #include "policydb.h"
....@@ -76,6 +77,24 @@
7677 dst->highbit = src->highbit;
7778 return 0;
7879 }
80
+
81
+int ebitmap_and(struct ebitmap *dst, struct ebitmap *e1, struct ebitmap *e2)
82
+{
83
+ struct ebitmap_node *n;
84
+ int bit, rc;
85
+
86
+ ebitmap_init(dst);
87
+
88
+ ebitmap_for_each_positive_bit(e1, n, bit) {
89
+ if (ebitmap_get_bit(e2, bit)) {
90
+ rc = ebitmap_set_bit(dst, bit, 1);
91
+ if (rc < 0)
92
+ return rc;
93
+ }
94
+ }
95
+ return 0;
96
+}
97
+
7998
8099 #ifdef CONFIG_NETLABEL
81100 /**
....@@ -347,7 +366,9 @@
347366 {
348367 struct ebitmap_node *n = NULL;
349368 u32 mapunit, count, startbit, index;
369
+ __le32 ebitmap_start;
350370 u64 map;
371
+ __le64 mapbits;
351372 __le32 buf[3];
352373 int rc, i;
353374
....@@ -381,12 +402,12 @@
381402 goto bad;
382403
383404 for (i = 0; i < count; i++) {
384
- rc = next_entry(&startbit, fp, sizeof(u32));
405
+ rc = next_entry(&ebitmap_start, fp, sizeof(u32));
385406 if (rc < 0) {
386407 pr_err("SELinux: ebitmap: truncated map\n");
387408 goto bad;
388409 }
389
- startbit = le32_to_cpu(startbit);
410
+ startbit = le32_to_cpu(ebitmap_start);
390411
391412 if (startbit & (mapunit - 1)) {
392413 pr_err("SELinux: ebitmap start bit (%d) is "
....@@ -423,12 +444,12 @@
423444 goto bad;
424445 }
425446
426
- rc = next_entry(&map, fp, sizeof(u64));
447
+ rc = next_entry(&mapbits, fp, sizeof(u64));
427448 if (rc < 0) {
428449 pr_err("SELinux: ebitmap: truncated map\n");
429450 goto bad;
430451 }
431
- map = le64_to_cpu(map);
452
+ map = le64_to_cpu(mapbits);
432453
433454 index = (startbit - n->startbit) / EBITMAP_UNIT_SIZE;
434455 while (map) {
....@@ -522,6 +543,19 @@
522543 return 0;
523544 }
524545
546
+u32 ebitmap_hash(const struct ebitmap *e, u32 hash)
547
+{
548
+ struct ebitmap_node *node;
549
+
550
+ /* need to change hash even if ebitmap is empty */
551
+ hash = jhash_1word(e->highbit, hash);
552
+ for (node = e->node; node; node = node->next) {
553
+ hash = jhash_1word(node->startbit, hash);
554
+ hash = jhash(node->maps, sizeof(node->maps), hash);
555
+ }
556
+ return hash;
557
+}
558
+
525559 void __init ebitmap_cache_init(void)
526560 {
527561 ebitmap_node_cachep = kmem_cache_create("ebitmap_node",