Date: Thu, 19 Apr 2018 02:47:22 +0000 (UTC) From: "Pedro F. Giffuni" <pfg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r332749 - in stable/11/sys: fs/ext2fs ufs/ufs Message-ID: <201804190247.w3J2lMj4076987@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pfg Date: Thu Apr 19 02:47:21 2018 New Revision: 332749 URL: https://svnweb.freebsd.org/changeset/base/332749 Log: MFC r328957: {ext2|ufs}_readdir: Avoid setting negative ncookies. ncookies cannot be negative or the allocator will fail. This should only happen if a caller is very broken but we can still try to survive the event. We should probably also verify for uio_resid > MAXPHYS but in that case it is not clear that just clipping the ncookies value is an adequate response. Modified: stable/11/sys/fs/ext2fs/ext2_lookup.c stable/11/sys/ufs/ufs/ufs_vnops.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/fs/ext2fs/ext2_lookup.c ============================================================================== --- stable/11/sys/fs/ext2fs/ext2_lookup.c Thu Apr 19 01:15:19 2018 (r332748) +++ stable/11/sys/fs/ext2fs/ext2_lookup.c Thu Apr 19 02:47:21 2018 (r332749) @@ -150,7 +150,10 @@ ext2_readdir(struct vop_readdir_args *ap) return (EINVAL); ip = VTOI(vp); if (ap->a_ncookies != NULL) { - ncookies = uio->uio_resid; + if (uio->uio_resid < 0) + ncookies = 0; + else + ncookies = uio->uio_resid; if (uio->uio_offset >= ip->i_size) ncookies = 0; else if (ip->i_size - uio->uio_offset < ncookies) Modified: stable/11/sys/ufs/ufs/ufs_vnops.c ============================================================================== --- stable/11/sys/ufs/ufs/ufs_vnops.c Thu Apr 19 01:15:19 2018 (r332748) +++ stable/11/sys/ufs/ufs/ufs_vnops.c Thu Apr 19 02:47:21 2018 (r332749) @@ -2177,7 +2177,10 @@ ufs_readdir(ap) if (ip->i_effnlink == 0) return (0); if (ap->a_ncookies != NULL) { - ncookies = uio->uio_resid; + if (uio->uio_resid < 0) + ncookies = 0; + else + ncookies = uio->uio_resid; if (uio->uio_offset >= ip->i_size) ncookies = 0; else if (ip->i_size - uio->uio_offset < ncookies)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201804190247.w3J2lMj4076987>