summaryrefslogtreecommitdiff
path: root/security/selinux/ss/mls.h
diff options
context:
space:
mode:
authorOndrej Mosnacek <omosnace@redhat.com>2020-04-17 11:11:56 +0300
committerPaul Moore <paul@paul-moore.com>2020-04-17 23:04:34 +0300
commit50077289804c9bd4e6cfd5b3a10d4da0487f7e42 (patch)
treed0eec42d8fa215c2a80419f934159286d5d025d5 /security/selinux/ss/mls.h
parente67b2ec9f6171895e774f6543626913960e019df (diff)
downloadlinux-50077289804c9bd4e6cfd5b3a10d4da0487f7e42.tar.xz
selinux: hash context structure directly
Always hashing the string representation is inefficient. Just hash the contents of the structure directly (using jhash). If the context is invalid (str & len are set), then hash the string as before, otherwise hash the structured data. Since the context hashing function is now faster (about 10 times), this patch decreases the overhead of security_transition_sid(), which is called from many hooks. The jhash function seemed as a good choice, since it is used as the default hashing algorithm in rhashtable. Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com> Reviewed-by: Jeff Vander Stoep <jeffv@google.com> Tested-by: Jeff Vander Stoep <jeffv@google.com> [PM: fixed some spelling errors in the comments pointed out by JVS] Signed-off-by: Paul Moore <paul@paul-moore.com>
Diffstat (limited to 'security/selinux/ss/mls.h')
-rw-r--r--security/selinux/ss/mls.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/security/selinux/ss/mls.h b/security/selinux/ss/mls.h
index 7954b1e60b64..15cacde0ff61 100644
--- a/security/selinux/ss/mls.h
+++ b/security/selinux/ss/mls.h
@@ -22,7 +22,10 @@
#ifndef _SS_MLS_H_
#define _SS_MLS_H_
+#include <linux/jhash.h>
+
#include "context.h"
+#include "ebitmap.h"
#include "policydb.h"
int mls_compute_context_len(struct policydb *p, struct context *context);
@@ -101,5 +104,13 @@ static inline int mls_import_netlbl_cat(struct policydb *p,
}
#endif
+static inline u32 mls_range_hash(const struct mls_range *r, u32 hash)
+{
+ hash = jhash_2words(r->level[0].sens, r->level[1].sens, hash);
+ hash = ebitmap_hash(&r->level[0].cat, hash);
+ hash = ebitmap_hash(&r->level[1].cat, hash);
+ return hash;
+}
+
#endif /* _SS_MLS_H */