From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5750A3D0D1; Tue, 14 May 2024 11:54:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715687673; cv=none; b=OzJyqCiBycd6mBg6a1wS1LDu6ZyXhW6/mRTdjgTYnZGBKWFhtaPrDelbWT5NSjhw44txCJc5F+zZsr2HSfwS/qRClbOunA6SdS9kJBEKSJL5VCnH9Ea7VE/1w32z9IKvXcsTwwZ9lrRa/qwhPHi7p8KGFmER+lXWVSOhctsdSKk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715687673; c=relaxed/simple; bh=R5Lc/Yvk0Vy4BlAGKMl1H4e9ycacRFWxKE5tTqxCt1g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P9U7g735YNOMjU3w+7iNBKcjA2OtnguW6yBlLniMUIs6UO5C88sxLcjVzfce1ZsxpjV6fvrSYUP37+zgtiko6vAUQwMG0aS4wsGzpvVLArqAxxRrJgzg/hD/gVG372iEwuQ2sU8Ob9KoU2vZT7CleJd6kSXgR/z1dA8d3FMlL2s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Hd053gLR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Hd053gLR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2CF3C2BD10; Tue, 14 May 2024 11:54:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1715687673; bh=R5Lc/Yvk0Vy4BlAGKMl1H4e9ycacRFWxKE5tTqxCt1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hd053gLR685mCMC8llbsSTPn/CZPMmZea8wVxbZhyLW68LrQXIQ6YHUN/dODxgYMm Eav19lSs/z6Vkjd1fs8v9eHSW7FBVg0IUJHtpbCnsHSMVy5XkAHctqD/FnFYJ6xspo XYMwPxvXw6dsQcw5cx3srE1WRFpKn4F3doktiBaE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Andrew Price , Andreas Gruenbacher , Sasha Levin Subject: [PATCH 5.15 065/168] gfs2: Fix invalid metadata access in punch_hole Date: Tue, 14 May 2024 12:19:23 +0200 Message-ID: <20240514101009.152040040@linuxfoundation.org> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240514101006.678521560@linuxfoundation.org> References: <20240514101006.678521560@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrew Price [ Upstream commit c95346ac918c5badf51b9a7ac58a26d3bd5bb224 ] In punch_hole(), when the offset lies in the final block for a given height, there is no hole to punch, but the maximum size check fails to detect that. Consequently, punch_hole() will try to punch a hole beyond the end of the metadata and fail. Fix the maximum size check. Signed-off-by: Andrew Price Signed-off-by: Andreas Gruenbacher Signed-off-by: Sasha Levin --- fs/gfs2/bmap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 0ec1eaf338338..d2011c3c33fc2 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -1704,7 +1704,8 @@ static int punch_hole(struct gfs2_inode *ip, u64 offset, u64 length) struct buffer_head *dibh, *bh; struct gfs2_holder rd_gh; unsigned int bsize_shift = sdp->sd_sb.sb_bsize_shift; - u64 lblock = (offset + (1 << bsize_shift) - 1) >> bsize_shift; + unsigned int bsize = 1 << bsize_shift; + u64 lblock = (offset + bsize - 1) >> bsize_shift; __u16 start_list[GFS2_MAX_META_HEIGHT]; __u16 __end_list[GFS2_MAX_META_HEIGHT], *end_list = NULL; unsigned int start_aligned, end_aligned; @@ -1715,7 +1716,7 @@ static int punch_hole(struct gfs2_inode *ip, u64 offset, u64 length) u64 prev_bnr = 0; __be64 *start, *end; - if (offset >= maxsize) { + if (offset + bsize - 1 >= maxsize) { /* * The starting point lies beyond the allocated meta-data; * there are no blocks do deallocate. -- 2.43.0