public inbox for linux-cifs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Aurélien Aptel" <aaptel@suse.com>
To: Al Viro <viro@zeniv.linux.org.uk>, linux-cifs@vger.kernel.org
Cc: Paulo Alcantara <palcantara@suse.de>,
	Steve French <stfrench@microsoft.com>,
	linux-fsdevel@vger.kernel.org
Subject: Re: broken hash use in fs/cifs/dfs_cache.c
Date: Mon, 22 Mar 2021 19:38:15 +0100	[thread overview]
Message-ID: <87o8fbqbjc.fsf@suse.com> (raw)
In-Reply-To: <YFjYbftTAJdO+LNg@zeniv-ca.linux.org.uk>

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)


  parent reply	other threads:[~2021-03-22 18:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22 17:48 broken hash use in fs/cifs/dfs_cache.c Al Viro
2021-03-22 18:23 ` Paulo Alcantara
2021-03-22 18:38 ` Aurélien Aptel [this message]
2021-03-22 20:23   ` Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o8fbqbjc.fsf@suse.com \
    --to=aaptel@suse.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=palcantara@suse.de \
    --cc=stfrench@microsoft.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox