Date: Sat, 17 Feb 2018 16:38:25 +0100 From: Mariusz Zaborski <oshogbo@freebsd.org> To: Mateusz Guzik <mjguzik@gmail.com> Cc: freebsd-hackers@freebsd.org Subject: Re: Where KASASERT fd < fdp->fd_nfiles should be? Message-ID: <20180217153825.GB61118@x-wing> In-Reply-To: <CAGudoHHikxaGiB4NvADDGubkXuHLR8rOys2hUvcOd%2BZ0K22=Tw@mail.gmail.com> References: <20180217150224.GA61118@x-wing> <CAGudoHHikxaGiB4NvADDGubkXuHLR8rOys2hUvcOd%2BZ0K22=Tw@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--6sX45UoQRIJXqkqR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Feb 17, 2018 at 04:23:40PM +0100, Mateusz Guzik wrote: > On Sat, Feb 17, 2018 at 04:02:24PM +0100, Mariusz Zaborski wrote: > > > > KASSERT(fd >=3D 0 && fd < fdp->fd_nfiles, > > ("%s: invalid fd=3D%d", __func__, fd)); > > > > > > 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_nfiles. > > 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 mo= ve > it to > > the fget_locked()/fdget_locked() functions? > > >=20 > While the assertion arguably can be removed, it is most definitely > valid. >=20 > fd_nfiles signifies the size of the table, while fd_lastfile the highest > used slot. By definition it must fit the table. >=20 > The code sample is used on fork where the existing table is duplicated. > Allocation of the new table is performed with locks dropped, which means > the old one can grow in the meantime. The while loop ensures the new > table will have the right size no matter what. So maybe we should go in more general approach and move this KASSERT to the fget_locked and 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 --6sX45UoQRIJXqkqR Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEkD1x0xkJXVVY1Gwf38KEGuLGxWQFAlqITG0ACgkQ38KEGuLG xWRtrQ/+IsfQ4Z3+6tVzIsPzRAlRh6h6dxydBcZn0EsgJDLt+m2IJ/7aKflltWTv FhC8uf01sY/32f7lBODHDGYcToUS3gxmS/QRNkm4kV86fzXVmz8q2/nsPVajFJZa Wz0zoBfOIsf/4/BReG89w2kQE9qMXI5fy2H2t/3CWs6MjO38KaEVK7KGhZJtfvjM eROaJdz6qJeD1lbxvE2jeMWT1HU6pysttoV8ra1MUUJpGs5vVUT1sWD16O3YVSRK KdtmGIATIjzRHCiaMZoXr1ul1vrKOjV/O8kaF01lptneKkOJ6H7l5t6CSestUfFG KupLQYhvsUhGXXU+BoPDmIao4tUbwxIjHtR5BRM60lqUFeQr47Rflnyz2u67fQXz YzeVIr6zXKCzwALmYbPS6CBr/SM9rToUobjQlN+RLNG9qZ5LMAqm7uB9BfXT0gpU TkgQFvVCRHrrtGt0v3asCJvBCgLVTC4CxzAR1SBfJwv0VOamb5yiaEZ+AF6A2/Fu psgZUEgnfbsvfj6QWXHMvYO9j3xebCmEFL+xXUc65RyKmeKhXrLy3iVDU6Npsqma gI7grNnxisVfs/WdR2+3GH85Aoh8dH1ARehq6PXGqfcX/rHlpeiQNvkZpp/TkxJf 10HjrYpoh5jB7fKOpVELMc+BV6ptSh7qeMl1LtJZal/ECvyNsfU= =LrUW -----END PGP SIGNATURE----- --6sX45UoQRIJXqkqR--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20180217153825.GB61118>