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 D2A99143759; Tue, 14 May 2024 11:31:58 +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=1715686318; cv=none; b=BHVolOoUaOh1ZzejoOl/VBMRF4GqznHE5VqbnaZKLALoXzjnEjVTKvz1+8MZKe8T2F0bOmcPRFuVwUR6W5Hcp59ZIaAHSVZ1uCPhPX+tJqvc66TPNQzdp3XdaiZMKmu43orcczj8hE7wdkManvsBJ+0d1n4vndPCM9Gp2LZXFk4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715686318; c=relaxed/simple; bh=c4XKEWmD7sOXZdE8qxJNZhzEMuKDHk+fUV0DEX67uPE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MnvBuutxzdiaanvqdz/uuE66vyAbS1sU11zyGieok04QE3ArX22Wmd9OYZn6Db2vrcss9BUCqQsf4G7KEdhgOnZ2uGEbsZprwGrvTMPUcXZMoU4j933j5fd9dChHSxWapQAXWR9vrILiMHl5jwL5tBjpxRPBBHLKHp0dnk3pExs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=xSzi17kF; 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="xSzi17kF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F384C2BD10; Tue, 14 May 2024 11:31:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1715686318; bh=c4XKEWmD7sOXZdE8qxJNZhzEMuKDHk+fUV0DEX67uPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xSzi17kFxLC14RKk2SsDcgbc24l4HqRwft6edNa+x/47QIve6AVbfbwqUjW9WqlQ0 8sbYDd+liV1cZL+6QRxAyrp4ZQvUVZSBtOu1ebffEjdnXQAmZUHaC85jUv1VT52QDy Mo3z52H9Qk5fo36zXP4526oXfmBtu33RBEs6OiFQ= 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 6.1 097/236] gfs2: Fix invalid metadata access in punch_hole Date: Tue, 14 May 2024 12:17:39 +0200 Message-ID: <20240514101024.054277627@linuxfoundation.org> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240514101020.320785513@linuxfoundation.org> References: <20240514101020.320785513@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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 e7537fd305dd2..9ad11e5bf14c3 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -1702,7 +1702,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; @@ -1713,7 +1714,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