Merge tag 'selinux-pr-20200601' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / security / selinux / ss / ebitmap.c
index c8c3663111e273d05d7ab05e1aa5f57222f6c4b8..14bedc95c6dcf0c14261a3ea5c2351510f4158ca 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/errno.h>
+#include <linux/jhash.h>
 #include <net/netlabel.h>
 #include "ebitmap.h"
 #include "policydb.h"
@@ -542,6 +543,19 @@ int ebitmap_write(struct ebitmap *e, void *fp)
        return 0;
 }
 
+u32 ebitmap_hash(const struct ebitmap *e, u32 hash)
+{
+       struct ebitmap_node *node;
+
+       /* need to change hash even if ebitmap is empty */
+       hash = jhash_1word(e->highbit, hash);
+       for (node = e->node; node; node = node->next) {
+               hash = jhash_1word(node->startbit, hash);
+               hash = jhash(node->maps, sizeof(node->maps), hash);
+       }
+       return hash;
+}
+
 void __init ebitmap_cache_init(void)
 {
        ebitmap_node_cachep = kmem_cache_create("ebitmap_node",