From: Chuck Lever III <chuck.lever@oracle.com>
To: Neil Brown <neilb@suse.de>
Cc: Linux NFS Mailing List <linux-nfs@vger.kernel.org>
Subject: Re: [PATCH v2 7/9] NFSD: Use rhashtable for managing nfs4_file objects
Date: Tue, 11 Oct 2022 12:56:09 +0000 [thread overview]
Message-ID: <EB08B095-BF02-4B5E-8CD2-12B0201328D2@oracle.com> (raw)
In-Reply-To: <166544739751.14457.9018300177489236723@noble.neil.brown.name>
> On Oct 10, 2022, at 8:16 PM, NeilBrown <neilb@suse.de> wrote:
>
> On Fri, 07 Oct 2022, Chuck Lever wrote:
>>
>> -static unsigned int file_hashval(struct svc_fh *fh)
>> +/*
>> + * The returned hash value is based solely on the address of an in-code
>> + * inode, a pointer to a slab-allocated object. The entropy in such a
>> + * pointer is concentrated in its middle bits.
>
> I think you need more justification than that for throwing away some of
> the entropy, even if you don't think it is much.
We might have that justification:
https://lore.kernel.org/linux-nfs/YrUFbLJ5uVbWtZbf@ZenIV/
Actually I believe we are not discarding /any/ entropy in
this function. The bits we discard are invariant.
And, note that this is exactly the same situation we just merged
in the filecache overhaul, and is a common trope amongst other
hash tables that base their function on the inode's address.
> Presumably you think hashing 32 bits is faster than hashing 64 bits.
> Maybe it is, but is it worth it?
>
> rhashtable depends heavily on having a strong hash function. In
> particular if any bucket ends up with more than 16 elements it will
> choose a new seed and rehash. If you deliberately remove some bits that
> it might have been used to spread those 16 out, then you are asking for
> trouble.
>
> We know that two different file handles can refer to the same inode
> ("rarely"), and you deliberately place them in the same hash bucket.
> So if an attacker arranges to access 17 files with the same inode but
> different file handles, then the hashtable will be continuously
> rehashed.
>
> The preferred approach when you require things to share a hash chain is
> to use an rhl table.
Again, this is the same situation for the filecache. Do you
believe it is worth reworking that? I'm guessing "yes".
> This allows multiple instances with the same key.
> You would then key the rhl-table with the inode, and search a
> linked-list to find the entry with the desired file handle. This would
> be no worse in search time than the current code for aliased inodes, but
> less susceptible to attack.
>
>> +/**
>> + * nfs4_file_obj_cmpfn - Match a cache item against search criteria
>> + * @arg: search criteria
>> + * @ptr: cache item to check
>> + *
>> + * Return values:
>> + * %0 - Item matches search criteria
>> + * %1 - Item does not match search criteria
>
> I *much* prefer %-ESRCH for "does not match search criteria". It is
> self-documenting. Any non-zero value will do.
Noted, but returning 1 appears to be the typical arrangement for
existing obj_cmpfn methods in most other areas.
--
Chuck Lever
next prev parent reply other threads:[~2022-10-11 12:56 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-06 16:20 [PATCH v2 0/9] A course adjustment, maybe Chuck Lever
2022-10-06 16:20 ` [PATCH v2 1/9] nfsd: fix nfsd_file_unhash_and_dispose Chuck Lever
2022-10-06 16:20 ` [PATCH v2 2/9] nfsd: rework hashtable handling in nfsd_do_file_acquire Chuck Lever
2022-10-06 16:20 ` [PATCH v2 3/9] NFSD: Pass the target nfsd_file to nfsd_commit() Chuck Lever
2022-10-06 16:20 ` [PATCH v2 4/9] NFSD: Revert "NFSD: NFSv4 CLOSE should release an nfsd_file immediately" Chuck Lever
2022-10-06 16:20 ` [PATCH v2 5/9] NFSD: Add an NFSD_FILE_GC flag to enable nfsd_file garbage collection Chuck Lever
2022-10-10 23:50 ` NeilBrown
2022-10-11 13:03 ` Chuck Lever III
2022-10-06 16:20 ` [PATCH v2 6/9] NFSD: Use const pointers as parameters to fh_ helpers Chuck Lever
2022-10-06 16:20 ` [PATCH v2 7/9] NFSD: Use rhashtable for managing nfs4_file objects Chuck Lever
2022-10-11 0:16 ` NeilBrown
2022-10-11 12:56 ` Chuck Lever III [this message]
2022-10-11 23:37 ` NeilBrown
2022-10-12 15:01 ` Chuck Lever III
2022-10-12 21:18 ` NeilBrown
2022-10-13 14:19 ` Chuck Lever III
2022-10-13 22:14 ` NeilBrown
2022-10-14 12:48 ` Chuck Lever III
2022-10-12 6:45 ` NeilBrown
2022-10-06 16:20 ` [PATCH v2 8/9] NFSD: Clean up nfs4_preprocess_stateid_op() call sites Chuck Lever
2022-10-06 16:21 ` [PATCH v2 9/9] NFSD: Trace delegation revocations Chuck Lever
2022-10-07 13:19 ` [PATCH v2 0/9] A course adjustment, maybe Jeff Layton
2022-10-07 14:19 ` Chuck Lever III
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=EB08B095-BF02-4B5E-8CD2-12B0201328D2@oracle.com \
--to=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=neilb@suse.de \
/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