udf: Fix off-by-one error when discarding preallocation
authorJan Kara <jack@suse.cz>
Mon, 23 Jan 2023 13:29:15 +0000 (14:29 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 17 Mar 2023 07:48:50 +0000 (08:48 +0100)
[ Upstream commit f54aa97fb7e5329a373f9df4e5e213ced4fc8759 ]

The condition determining whether the preallocation can be used had
an off-by-one error so we didn't discard preallocation when new
allocation was just following it. This can then confuse code in
inode_getblk().

CC: stable@vger.kernel.org
Fixes: 16d055656814 ("udf: Discard preallocation before extending file with a hole")
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/udf/inode.c

index a151e04856afedaf4d5793a1e29b8d6fb7c9e6fc..594d22458881943e856d19d5f6ff404c9cc68fdf 100644 (file)
@@ -442,7 +442,7 @@ static int udf_get_block(struct inode *inode, sector_t block,
         * Block beyond EOF and prealloc extents? Just discard preallocation
         * as it is not useful and complicates things.
         */
-       if (((loff_t)block) << inode->i_blkbits > iinfo->i_lenExtents)
+       if (((loff_t)block) << inode->i_blkbits >= iinfo->i_lenExtents)
                udf_discard_prealloc(inode);
        udf_clear_extent_cache(inode);
        phys = inode_getblk(inode, block, &err, &new);