Re: broken hash use in fs/cifs/dfs_cache.c

Aurélien Aptel
2021-03-22T18:39:10Z

Al Viro <viro@zeniv.linux.org.uk> writes:
> Either the key comparison or the hash function is wrong here. *IF* something
> external guarantees the full match, we don't need strcasecmp() - strcmp()
> would work. Otherwise, the hash function needs to be changed.

I think here we need to make the hash case-insensitive.

Perhaps calling jhash() with lower-cased bytes like so (pseudo-code):

static inline unsigned int cache_entry_hash(const void *data, int size)
{
unsigned int h = 0;
u32 c;
u8 *s = data;

while (s < data+size) {
int len = decode_char(s, &c);
if (!len)
break;
c = tolower(c);
s += len;
h = jhash(&c, sizeof(c), h);
}

return h % CACHE_HTABLE_SIZE;
}

Cheers,
--
Aurélien Aptel / SUSE Labs Samba Team
GPG: 1839 CB5F 9F5B FB9B AA97 8C99 03C8 A49B 521B D5D3
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg, DE
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 247165 (AG München)