From: David Laight <david.laight.linux@gmail.com>
To: Qianchang Zhao <pioooooooooip@gmail.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>,
Steve French <smfrench@gmail.com>,
gregkh@linuxfoundation.org, linux-cifs@vger.kernel.org,
linux-kernel@vger.kernel.org,
Zhitong Liu <liuzhitong1993@gmail.com>,
stable@vger.kernel.org
Subject: Re: [PATCH v2] ksmbd: vfs_cache: avoid integer overflow in inode_hash()
Date: Sat, 15 Nov 2025 17:02:53 +0000 [thread overview]
Message-ID: <20251115170253.64ee8828@pumpkin> (raw)
In-Reply-To: <20251115144836.555128-1-pioooooooooip@gmail.com>
On Sat, 15 Nov 2025 23:48:36 +0900
Qianchang Zhao <pioooooooooip@gmail.com> wrote:
> inode_hash() currently mixes a hash value with the super_block pointer
> using an unbounded multiplication:
>
> tmp = (hashval * (unsigned long)sb) ^
> (GOLDEN_RATIO_PRIME + hashval) / L1_CACHE_BYTES;
>
> On 64-bit kernels this multiplication can overflow and wrap in unsigned
> long arithmetic.
The same happens on 32bits.
> While this is not a memory-safety issue, it is an
> unbounded integer operation and weakens the mixing properties of the
> hash.
Are you sure, I'd have thought all the 'carry' operations in the multiply
would make it better.
> Replace the pointer*hash multiply with hash_long() over a mixed value
> (hashval ^ (unsigned long)sb) and keep the existing shift/mask. This
> removes the overflow source and reuses the standard hash helper already
> used in other kernel code.
>
> This is an integer wraparound / robustness issue (CWE-190/CWE-407),
> not a memory-safety bug.
It isn't really an integer wraparound bug either.
The fact that only the low bits of the product are used shouldn't matter
at all.
OTOH it might be worth sifting 'sb' right some bits - quite a few of
its low bits are zero and they end up as zeros in the product.
David
>
> Reported-by: Qianchang Zhao <pioooooooooip@gmail.com>
> Reported-by: Zhitong Liu <liuzhitong1993@gmail.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Qianchang Zhao <pioooooooooip@gmail.com>
> ---
> fs/smb/server/vfs_cache.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/fs/smb/server/vfs_cache.c b/fs/smb/server/vfs_cache.c
> index dfed6fce8..a62ea5aae 100644
> --- a/fs/smb/server/vfs_cache.c
> +++ b/fs/smb/server/vfs_cache.c
> @@ -10,6 +10,7 @@
> #include <linux/vmalloc.h>
> #include <linux/kthread.h>
> #include <linux/freezer.h>
> +#include <linux/hash.h>
>
> #include "glob.h"
> #include "vfs_cache.h"
> @@ -65,12 +66,8 @@ static void fd_limit_close(void)
>
> static unsigned long inode_hash(struct super_block *sb, unsigned long hashval)
> {
> - unsigned long tmp;
> -
> - tmp = (hashval * (unsigned long)sb) ^ (GOLDEN_RATIO_PRIME + hashval) /
> - L1_CACHE_BYTES;
> - tmp = tmp ^ ((tmp ^ GOLDEN_RATIO_PRIME) >> inode_hash_shift);
> - return tmp & inode_hash_mask;
> + unsigned long mixed = hashval ^ (unsigned long)sb;
> + return hash_long(mixed, inode_hash_shift) & inode_hash_mask;
> }
>
> static struct ksmbd_inode *__ksmbd_inode_lookup(struct dentry *de)
prev parent reply other threads:[~2025-11-15 17:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAKYAXd-_S184kK0NUyuCgOTvCvq382c3Fxt=ytes-ekydwGLuQ@mail.gmail.com>
2025-11-15 14:48 ` [PATCH v2] ksmbd: vfs_cache: avoid integer overflow in inode_hash() Qianchang Zhao
2025-11-15 17:02 ` David Laight [this message]
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=20251115170253.64ee8828@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuzhitong1993@gmail.com \
--cc=pioooooooooip@gmail.com \
--cc=smfrench@gmail.com \
--cc=stable@vger.kernel.org \
/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