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.
This commit is contained in:
Mateusz Guzik 2023-09-02 14:27:33 +00:00
parent 2ad756a6bb
commit 32988c1499

View File

@ -2597,10 +2597,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;
@ -2616,7 +2616,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;
@ -2762,7 +2762,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);