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 7FC2C22EF3; Tue, 14 May 2024 10:32:05 +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=1715682725; cv=none; b=JGd/RrPUJzjvpI+VfCFj3VzKFkEsykoew11Ub6u9Tflwr+y5JHjzhVL+7u8aKhX0j107kGEZX3G2z036OuUXkxLQt23AVYM+onYtP74s9421NDYRuu9MAO6DdC902idVKfTOUajK30j936MoEvkTtE75zqux+rMWER9aJUK6HP0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715682725; c=relaxed/simple; bh=3WFhLHWJBMYC5rm7YDQq/eVB1GCv/GztDDMsZBIQl+Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ia0zU9+v5HhAmCSKk96XsJTYZ2fKcHcFo91RGWCGvT2nzlCkyfmhf87RLVvPAWsVUHvEMM9DqooC/Vr/xxS9wvGDJzBr2wOm5Z6v9ilO8cu9635cQc9cVmq8YbWoqS4Rku9NANCcG+u1NDx6DHMXcekxAkd718Vmn6K2srKWfLg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hdFWgBXY; 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="hdFWgBXY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A93B6C2BD10; Tue, 14 May 2024 10:32:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1715682725; bh=3WFhLHWJBMYC5rm7YDQq/eVB1GCv/GztDDMsZBIQl+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hdFWgBXYOrEOxx5U8OC/rnlp7hXViWdpfed+E4XLCE75AJueYbW/A9VigVhJYV9R6 oswNZf+L1bj21euPtd5okl2IYn1Iju2EgFtrsN4T/MHM62ARt54clQxuwSoMcqD3wF YIuDmu8kSRaaGKOXI/QhFwHWsoP45wWh2CTah6sc= 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.8 103/336] gfs2: Fix invalid metadata access in punch_hole Date: Tue, 14 May 2024 12:15:07 +0200 Message-ID: <20240514101042.495643707@linuxfoundation.org> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240514101038.595152603@linuxfoundation.org> References: <20240514101038.595152603@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.8-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 d9ccfd27e4f11..643175498d1c3 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -1718,7 +1718,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; @@ -1729,7 +1730,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 metadata; * there are no blocks to deallocate. -- 2.43.0