[PATCH 6/9] SELinux: Replace custom hash with generic lookup3 in policydb

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Siarhei Liakh <siarhei.liakh@xxxxxxxxxxxxxxxxx>

This patch replaces local copy of custom hash function with existing
implementation of lookup3 from the standard Linux library. This change
allows to reduce the amount of custom code with has to be maintained, while
potentially improving overall performance of the hash table in question.

Signed-off-by: Siarhei Liakh <siarhei.liakh@xxxxxxxxxxxxxxxxx>
---
Please CC me directly in all replies.

 security/selinux/ss/policydb.c | 43 +++++++++++++++++++++++++++-------
 1 file changed, 35 insertions(+), 8 deletions(-)

diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index 70ecdc78efbd..0d03036ca20d 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -41,6 +41,10 @@
 #include "mls.h"
 #include "services.h"
 
+#ifdef CONFIG_SECURITY_SELINUX_ADVANCED_HASHING
+#include <linux/jhash.h>
+#endif /* #ifdef CONFIG_SECURITY_SELINUX_ADVANCED_HASHING */
+
 #define _DEBUG_HASHES
 
 #ifdef DEBUG_HASHES
@@ -399,6 +403,27 @@ static int roles_init(struct policydb *p)
 	return rc;
 }
 
+#ifdef CONFIG_SECURITY_SELINUX_ADVANCED_HASHING
+
+static u32 filenametr_hash(struct hashtab *h, const void *k)
+{
+	const struct filename_trans_key *ft = k;
+	unsigned long hash;
+
+	hash = jhash_2words(ft->ttype, ft->tclass, 0);
+	hash = jhash(ft->name, strlen(ft->name), hash);
+	return hash & (h->size - 1);
+}
+
+static u32 rangetr_hash(struct hashtab *h, const void *k)
+{
+	const struct range_trans_key *key = k;
+	return jhash_3words(key->source_type, key->target_type,
+			key->target_class, 0) & (h->size - 1);
+}
+
+#else /* #ifdef CONFIG_SECURITY_SELINUX_ADVANCED_HASHING */
+
 static u32 filenametr_hash(struct hashtab *h, const void *k)
 {
 	const struct filename_trans_key *ft = k;
@@ -414,6 +439,16 @@ static u32 filenametr_hash(struct hashtab *h, const void *k)
 	return hash & (h->size - 1);
 }
 
+static u32 rangetr_hash(struct hashtab *h, const void *k)
+{
+	const struct range_trans *key = k;
+
+	return (key->source_type + (key->target_type << 3) +
+		(key->target_class << 5)) & (h->size - 1);
+}
+
+#endif /* #else #ifdef CONFIG_SECURITY_SELINUX_ADVANCED_HASHING */
+
 static int filenametr_cmp(struct hashtab *h, const void *k1, const void *k2)
 {
 	const struct filename_trans_key *ft1 = k1;
@@ -432,14 +467,6 @@ static int filenametr_cmp(struct hashtab *h, const void *k1, const void *k2)
 
 }
 
-static u32 rangetr_hash(struct hashtab *h, const void *k)
-{
-	const struct range_trans *key = k;
-
-	return (key->source_type + (key->target_type << 3) +
-		(key->target_class << 5)) & (h->size - 1);
-}
-
 static int rangetr_cmp(struct hashtab *h, const void *k1, const void *k2)
 {
 	const struct range_trans *key1 = k1, *key2 = k2;
-- 
2.17.1




[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux