Date: Sat, 17 Feb 2018 16:02:24 +0100 From: Mariusz Zaborski <oshogbo@FreeBSD.org> To: freebsd-hackers@freebsd.org Subject: Where KASASERT fd < fdp->fd_nfiles should be? Message-ID: <20180217150224.GA61118@x-wing>
next in thread | raw e-mail | index | archive | help
--lrZ03NoBR/3+SXJZ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Some time ago mjg@ had an idea to cleanup use of the fget_locked function in
the sys_capability. I implemented most of it and pjd@ accepted almost all
changes (with one suggestion with I didn't figure out what to do with it).
In my patch I remove one KASSERT from the cap_ioctl_check:
int
cap_ioctl_check(struct filedesc *fdp, int fd, u_long cmd)
{
u_long *cmds;
ssize_t ncmds;
long i;
FILEDESC_LOCK_ASSERT(fdp);
KASSERT(fd >=3D 0 && fd < fdp->fd_nfiles,
("%s: invalid fd=3D%d", __func__, fd));
ncmds =3D fdp->fd_ofiles[fd].fde_nioctls;
if (ncmds =3D=3D -1)
return (0);
cmds =3D fdp->fd_ofiles[fd].fde_ioctls;
for (i =3D 0; i < ncmds; i++) {
if (cmds[i] =3D=3D cmd)
return (0);
}
return (ENOTCAPABLE);
}
My question and problem is do we need this KASSERT?
The fdget_locked checks if the fd is not larger then fd_lastfile.
But the code from fdinit suggest that fd_lastfile can be larger then fd_nfi=
les.
pjd@ suggested that it can go over size of the table fd_ofiles array:
while (fdp->fd_lastfile >=3D newfdp->fd_nfiles) {
FILEDESC_SUNLOCK(fdp);
fdgrowtable(newfdp, fdp->fd_lastfile + 1);
FILEDESC_SLOCK(fdp);
}
So the question is do we need this assertion here or maybe should we move i=
t to
the fget_locked()/fdget_locked() functions?
Thanks,
--=20
Mariusz Zaborski
oshogbo//vx | http://oshogbo.vexillium.org
FreeBSD commiter | https://freebsd.org
Software developer | http://wheelsystems.com
If it's not broken, let's fix it till it is!!1
--lrZ03NoBR/3+SXJZ
Content-Type: application/pgp-signature; name="signature.asc"
-----BEGIN PGP SIGNATURE-----
iQIzBAEBCAAdFiEEkD1x0xkJXVVY1Gwf38KEGuLGxWQFAlqIQ/oACgkQ38KEGuLG
xWTwaA/9Hu63Q3Q/iQhWicJNBOgXxsrhTfEoTAGybhNfq2FwH5QsHGHu7sIHZj2M
dxCe//FzTdu03JIY9QunCblcXLEqdJhwwlkE8lHvj+WSEHqUMcertfGIc61MYhzw
p7QHJMAL6mCmWNrFi8kan02C8KisyIBmjONksRGY1faxEQpaFJGj0PkupNJbn2FE
xs9psn/JZEm3gnF09l6Uh+mosJ2kKuIfFZO7AcvdAMv9roHsvpQMznw1DckytJ/b
u78/nidSVHlDjXr6aYr8tw6o/8XU7ukcxwDC+JwoXmREldQvphpotO68myFRXTUR
PMSaHy81L9QTXv3I4I6i0pnjfBB4hz+7ptJsIfG4DRUh8vwb+8/4ffFIW3rrcYiZ
pTVacUsNksGYp5xfHO/NZtu1262IgKJ8Lruj93NUYXOET2vsCdDILJLc/jyMvykf
Bqxjg9ISJZ0nktF4ENRcXpof6991UKM65rMAgRNlgQ5O+LAFgsmpGc9XT7zXmIdB
x/f1BHrlY/HnmsakxMZHqy74oTIUfJ5gwIDuzCGwUXbHyxDnUrdVkLfba3cDc9Mx
238WGfTtSaXwJ++wrzwmP/P2lvcCiWX6rqH93gorygmdjgysIAq6u+vliXzDc4pk
BZJ+c9AIhiiG8wb8Wmf+DmI73VF/J3ee8pK5p1346FuLqUMxFzs=
=MYn4
-----END PGP SIGNATURE-----
--lrZ03NoBR/3+SXJZ--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20180217150224.GA61118>
