Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/cddl/osnet/dist/uts/common/fs/zfs fix the handling ...



details:   https://anonhg.NetBSD.org/src/rev/11c4c0bcf6c8
branches:  trunk
changeset: 972013:11c4c0bcf6c8
user:      chs <chs%NetBSD.org@localhost>
date:      Wed May 13 05:52:54 2020 +0000

description:
fix the handling in putpage of the page containing EOF.

diffstat:

 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c |  22 +++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)

diffs (34 lines):

diff -r c7250a774d1e -r 11c4c0bcf6c8 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
--- a/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c    Wed May 13 05:37:16 2020 +0000
+++ b/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c    Wed May 13 05:52:54 2020 +0000
@@ -6066,9 +6066,29 @@
                goto out_unbusy;
        }
 
+       /*
+        * Calculate the length and assert that no whole pages are past EOF.
+        * This check is equivalent to "off + len <= round_page(zp->z_size)",
+        * with gyrations to avoid signed integer overflow.
+        */
+
        off = pp[0]->offset;
        len = count * PAGESIZE;
-       KASSERT(off + len <= round_page(zp->z_size));
+       KASSERT(off <= zp->z_size);
+       KASSERT(len <= round_page(zp->z_size));
+       KASSERT(off <= round_page(zp->z_size) - len);
+
+       /*
+        * If EOF is within the last page, reduce len to avoid writing past
+        * the file size in the ZFS buffer.  Assert that
+        * "off + len <= zp->z_size", again avoiding signed integer overflow.
+        */
+
+       if (len > zp->z_size - off) {
+               len = zp->z_size - off;
+       }
+       KASSERT(len <= zp->z_size);
+       KASSERT(off <= zp->z_size - len);
 
        if (zfs_owner_overquota(zfsvfs, zp, B_FALSE) ||
            zfs_owner_overquota(zfsvfs, zp, B_TRUE)) {



Home | Main Index | Thread Index | Old Index