Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E9BAC678D4 for ; Thu, 2 Mar 2023 15:36:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230007AbjCBPgs (ORCPT ); Thu, 2 Mar 2023 10:36:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229877AbjCBPgj (ORCPT ); Thu, 2 Mar 2023 10:36:39 -0500 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA4D037545 for ; Thu, 2 Mar 2023 07:36:28 -0800 (PST) Received: by mail-lf1-x133.google.com with SMTP id t11so22676985lfr.1 for ; Thu, 02 Mar 2023 07:36:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1677771387; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tU1uRAhzsVoBdXD+RtSgjM2zLnzd5LFyExq7JwMSefY=; b=QkQLjOi8GvNhoAnYX+Jj2O5035sBaO3DVCqKuI/pUDUkZDES2L5FtLuLMh63HkVxYj NRKMWgDUQev3birx1DTgJU6DwmBeWl5eyayh6RyPZg8xsATSQeb4W8WT4WPSMFEb0kQM U5a4eC0ESRI7ep0FMYTBjb5gPus4COkoUh55yeysdynHfyXkO88XDa+PKUdipr9XneI4 scqMRSTfUD++K/CWy23E58hyegWlTDXm6I0yXr7cv9FeNaalKE4RlCZTpUfyWxYELWql A6FhaLyZYrfz2m/5clI4iUqtdDITEU23VX4aNZ1xA/j/a+x2UOJLFObjk7np3Tt8A+Ap jnWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677771387; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tU1uRAhzsVoBdXD+RtSgjM2zLnzd5LFyExq7JwMSefY=; b=0zFcAQg7e7moa8g/VlBhHXMws09fi8fTh/iggiGrQ4qGQU1uiJWe3r1P2/odxThkWH SY5vesT8qgl/tp23jvXhy4Sespf7X5rCYyhOtENkE2tYaCzKSlBW5roO20B27KCa2IEQ ZMhocVkWjsg89lZ/XxRJuNa3Wzld0zyufzsCb7KbuUf9ifWehadQgTZQq6c1nMcEBiun 7xSu8ptf6KkPXfBv/UjPICr+1VMHc61SovCgMEbrvJoXg4zc+DehGOjNIYxnPPnajTAj Xwo0wwiu63HMv0pyeCW16CqB/wQrmX0uloaz08rwY1npvGHie1jmSbIGXI1jDiqZ47Sk Nm6Q== X-Gm-Message-State: AO0yUKXL6Ja4CcUhKTcMSwJwUBkHz7sEWDpXdwpEd9ExmtFoC+voYj0A FArh4ZKZIM/24xG8/UqnO8pUjg== X-Google-Smtp-Source: AK7set8sJTLO9CCSsJJRosOnAY+i38CiUycGIL2zq/K7T87fr0OtVM/49TCqf1Lz0ZaxySlQA4biaA== X-Received: by 2002:ac2:46f6:0:b0:4dd:cbf3:e981 with SMTP id q22-20020ac246f6000000b004ddcbf3e981mr2764196lfo.28.1677771387030; Thu, 02 Mar 2023 07:36:27 -0800 (PST) Received: from ta1.c.googlers.com.com (61.215.228.35.bc.googleusercontent.com. [35.228.215.61]) by smtp.gmail.com with ESMTPSA id p17-20020a05651238d100b004db2978e330sm2170509lft.258.2023.03.02.07.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 07:36:26 -0800 (PST) From: Tudor Ambarus To: stable@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, joneslee@google.com, Ritesh Harjani , Jan Kara , Tudor Ambarus Subject: [PATCH][for stable 5.{15, 10} 3/4] ext4: add strict range checks while freeing blocks Date: Thu, 2 Mar 2023 15:36:09 +0000 Message-Id: <20230302153610.1204653-4-tudor.ambarus@linaro.org> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog In-Reply-To: <20230302153610.1204653-1-tudor.ambarus@linaro.org> References: <20230302153610.1204653-1-tudor.ambarus@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ritesh Harjani [ Upstream commit a00b482b82fb098956a5bed22bd7873e56f152f1 ] Currently ext4_mb_clear_bb() & ext4_group_add_blocks() only checks whether the given block ranges (which is to be freed) belongs to any FS metadata blocks or not, of the block's respective block group. But to detect any FS error early, it is better to add more strict checkings in those functions which checks whether the given blocks belongs to any critical FS metadata or not within system-zone. Suggested-by: Jan Kara Signed-off-by: Ritesh Harjani Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/ddd9143d064774e32d6364a99667817c6e8bfdc0.1644992610.git.riteshh@linux.ibm.com Signed-off-by: Theodore Ts'o Signed-off-by: Tudor Ambarus --- fs/ext4/mballoc.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 4418d011a654..7b4359862a60 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -5946,13 +5946,7 @@ static void ext4_mb_clear_bb(handle_t *handle, struct inode *inode, goto error_return; } - if (in_range(ext4_block_bitmap(sb, gdp), block, count) || - in_range(ext4_inode_bitmap(sb, gdp), block, count) || - in_range(block, ext4_inode_table(sb, gdp), - sbi->s_itb_per_group) || - in_range(block + count - 1, ext4_inode_table(sb, gdp), - sbi->s_itb_per_group)) { - + if (!ext4_inode_block_valid(inode, block, count)) { ext4_error(sb, "Freeing blocks in system zone - " "Block = %llu, count = %lu", block, count); /* err = 0. ext4_std_error should be a no op */ @@ -6023,7 +6017,7 @@ static void ext4_mb_clear_bb(handle_t *handle, struct inode *inode, NULL); if (err && err != -EOPNOTSUPP) ext4_msg(sb, KERN_WARNING, "discard request in" - " group:%d block:%d count:%lu failed" + " group:%u block:%d count:%lu failed" " with %d", block_group, bit, count, err); } else @@ -6236,11 +6230,7 @@ int ext4_group_add_blocks(handle_t *handle, struct super_block *sb, goto error_return; } - if (in_range(ext4_block_bitmap(sb, desc), block, count) || - in_range(ext4_inode_bitmap(sb, desc), block, count) || - in_range(block, ext4_inode_table(sb, desc), sbi->s_itb_per_group) || - in_range(block + count - 1, ext4_inode_table(sb, desc), - sbi->s_itb_per_group)) { + if (!ext4_sb_block_valid(sb, NULL, block, count)) { ext4_error(sb, "Adding blocks in system zones - " "Block = %llu, count = %lu", block, count); -- 2.40.0.rc0.216.gc4246ad0f0-goog