Convert runtime param checks to KASSERTs for fo_fspacectl

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D35880
This commit is contained in:
Ka Ho Ng 2022-07-23 15:14:45 -04:00
parent 151abc80cd
commit 8c9aa94b42
2 changed files with 10 additions and 8 deletions

View File

@ -1990,16 +1990,16 @@ shm_fspacectl(struct file *fp, int cmd, off_t *offset, off_t *length, int flags,
off_t off, len;
int error;
/* This assumes that the caller already checked for overflow. */
KASSERT(cmd == SPACECTL_DEALLOC, ("shm_fspacectl: Invalid cmd"));
KASSERT((flags & ~SPACECTL_F_SUPPORTED) == 0,
("shm_fspacectl: non-zero flags"));
KASSERT(*offset >= 0 && *length > 0 && *length <= OFF_MAX - *offset,
("shm_fspacectl: offset/length overflow or underflow"));
error = EINVAL;
shmfd = fp->f_data;
off = *offset;
len = *length;
if (cmd != SPACECTL_DEALLOC || off < 0 || len <= 0 ||
len > OFF_MAX - off || flags != 0)
return (EINVAL);
rl_cookie = rangelock_wlock(&shmfd->shm_rl, off, off + len,
&shmfd->shm_mtx);
switch (cmd) {

View File

@ -3607,11 +3607,13 @@ vn_fspacectl(struct file *fp, int cmd, off_t *offset, off_t *length, int flags,
struct vnode *vp;
int ioflag;
KASSERT(cmd == SPACECTL_DEALLOC, ("vn_fspacectl: Invalid cmd"));
KASSERT((flags & ~SPACECTL_F_SUPPORTED) == 0,
("vn_fspacectl: non-zero flags"));
KASSERT(*offset >= 0 && *length > 0 && *length <= OFF_MAX - *offset,
("vn_fspacectl: offset/length overflow or underflow"));
vp = fp->f_vnode;
if (cmd != SPACECTL_DEALLOC || *offset < 0 || *length <= 0 ||
*length > OFF_MAX - *offset || flags != 0)
return (EINVAL);
if (vp->v_type != VREG)
return (ENODEV);