aboutsummaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorStephen Hemminger <shemminger@vyatta.com>2009-10-27 22:24:46 -0400
committerJames Morris <jmorris@namei.org>2009-10-28 20:17:33 -0400
commit024e1a49411a1a7363e65db48edf1b09e9ee68ad (patch)
tree628fb392d0230f2e46753c04dded209ef27124d1 /security
parentd6ba452128178091dab7a04d54f7e66fdc32fb39 (diff)
tomoyo: improve hash bucket dispersion
When examining the network device name hash, it was discovered that the low order bits of full_name_hash() are not very well dispersed across the possible values. When used by filesystem code, this is handled by folding with the function hash_long(). The only other non-filesystem usage of full_name_hash() at this time appears to be in TOMOYO. This patch should fix that. I do not use TOMOYO at this time, so this patch is build tested only. Signed-off-by: Stephen Hemminger <shemminger@vyatta.com> Acked-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'security')
-rw-r--r--security/tomoyo/realpath.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/security/tomoyo/realpath.c b/security/tomoyo/realpath.c
index 5f2e3326337..917f564cdab 100644
--- a/security/tomoyo/realpath.c
+++ b/security/tomoyo/realpath.c
@@ -13,6 +13,8 @@
13#include <linux/mount.h> 13#include <linux/mount.h>
14#include <linux/mnt_namespace.h> 14#include <linux/mnt_namespace.h>
15#include <linux/fs_struct.h> 15#include <linux/fs_struct.h>
16#include <linux/hash.h>
17
16#include "common.h" 18#include "common.h"
17#include "realpath.h" 19#include "realpath.h"
18 20
@@ -263,7 +265,8 @@ static unsigned int tomoyo_quota_for_savename;
263 * table. Frequency of appending strings is very low. So we don't need 265 * table. Frequency of appending strings is very low. So we don't need
264 * large (e.g. 64k) hash size. 256 will be sufficient. 266 * large (e.g. 64k) hash size. 256 will be sufficient.
265 */ 267 */
266#define TOMOYO_MAX_HASH 256 268#define TOMOYO_HASH_BITS 8
269#define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS)
267 270
268/* 271/*
269 * tomoyo_name_entry is a structure which is used for linking 272 * tomoyo_name_entry is a structure which is used for linking
@@ -315,6 +318,7 @@ const struct tomoyo_path_info *tomoyo_save_name(const char *name)
315 struct tomoyo_free_memory_block_list *fmb; 318 struct tomoyo_free_memory_block_list *fmb;
316 int len; 319 int len;
317 char *cp; 320 char *cp;
321 struct list_head *head;
318 322
319 if (!name) 323 if (!name)
320 return NULL; 324 return NULL;
@@ -325,9 +329,10 @@ const struct tomoyo_path_info *tomoyo_save_name(const char *name)
325 return NULL; 329 return NULL;
326 } 330 }
327 hash = full_name_hash((const unsigned char *) name, len - 1); 331 hash = full_name_hash((const unsigned char *) name, len - 1);
332 head = &tomoyo_name_list[hash_long(hash, TOMOYO_HASH_BITS)];
333
328 mutex_lock(&lock); 334 mutex_lock(&lock);
329 list_for_each_entry(ptr, &tomoyo_name_list[hash % TOMOYO_MAX_HASH], 335 list_for_each_entry(ptr, head, list) {
330 list) {
331 if (hash == ptr->entry.hash && !strcmp(name, ptr->entry.name)) 336 if (hash == ptr->entry.hash && !strcmp(name, ptr->entry.name))
332 goto out; 337 goto out;
333 } 338 }
@@ -365,7 +370,7 @@ const struct tomoyo_path_info *tomoyo_save_name(const char *name)
365 tomoyo_fill_path_info(&ptr->entry); 370 tomoyo_fill_path_info(&ptr->entry);
366 fmb->ptr += len; 371 fmb->ptr += len;
367 fmb->len -= len; 372 fmb->len -= len;
368 list_add_tail(&ptr->list, &tomoyo_name_list[hash % TOMOYO_MAX_HASH]); 373 list_add_tail(&ptr->list, head);
369 if (fmb->len == 0) { 374 if (fmb->len == 0) {
370 list_del(&fmb->list); 375 list_del(&fmb->list);
371 kfree(fmb); 376 kfree(fmb);