git: 8d5b00a5713d - stable/13 - vfs cache: fix a hang when bumping vnode limit too high
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 04 Oct 2023 12:09:00 UTC
The branch stable/13 has been updated by mjg:
URL: https://cgit.FreeBSD.org/src/commit/?id=8d5b00a5713d91c18fa726fe832fb4df3751b419
commit 8d5b00a5713d91c18fa726fe832fb4df3751b419
Author: Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2023-09-02 14:27:33 +0000
Commit: Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2023-10-04 12:05:58 +0000
vfs cache: fix a hang when bumping vnode limit too high
Overflow in cache_changesize would make the value flip to 0 and stay
there as 0 << 1 does not do anything.
Note callers limit the outcome to something below u_int.
Also note there entire vnode handling thing both in vfs layer as a whole
and this file can't decide whether to long, u_long or u_int.
(cherry picked from commit 32988c1499f8698b41e15ed40a46d271e757bba3)
---
sys/kern/vfs_cache.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c
index 62698cdb2141..151d0d2ac8a1 100644
--- a/sys/kern/vfs_cache.c
+++ b/sys/kern/vfs_cache.c
@@ -2601,10 +2601,10 @@ cache_enter_time_flags(struct vnode *dvp, struct vnode *vp, struct componentname
cache_enter_time(dvp, vp, cnp, tsp, dtsp);
}
-static u_int
-cache_roundup_2(u_int val)
+static u_long
+cache_roundup_2(u_long val)
{
- u_int res;
+ u_long res;
for (res = 1; res <= val; res <<= 1)
continue;
@@ -2620,7 +2620,7 @@ nchinittbl(u_long elements, u_long *hashmask)
hashsize = cache_roundup_2(elements) / 2;
- hashtbl = malloc((u_long)hashsize * sizeof(*hashtbl), M_VFSCACHE, M_WAITOK);
+ hashtbl = malloc(hashsize * sizeof(*hashtbl), M_VFSCACHE, M_WAITOK);
for (i = 0; i < hashsize; i++)
CK_SLIST_INIT(&hashtbl[i]);
*hashmask = hashsize - 1;
@@ -2766,7 +2766,7 @@ cache_changesize(u_long newmaxvnodes)
struct namecache *ncp;
uint32_t hash;
u_long newncsize;
- int i;
+ u_long i;
newncsize = newmaxvnodes * ncsizefactor;
newmaxvnodes = cache_roundup_2(newmaxvnodes * 2);