Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp897198pxb; Tue, 1 Feb 2022 12:42:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJw437oe9mPR1Cr6qLGwF9uZKSQXNrLQeQ5Vv8CQ+gdSQjqNRsMGbJ0Jjtpqu0eIyTINljsg X-Received: by 2002:a05:6a00:1891:: with SMTP id x17mr26800606pfh.73.1643748121044; Tue, 01 Feb 2022 12:42:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643748121; cv=none; d=google.com; s=arc-20160816; b=ON1WYouBnHU8HjOOriTmJf83TBlO4XoSomuM41wDgpQR0WiKgxigcoKBYhiCSWosCZ iv4KVpMbuES/p82EXE+Ofa0asV4l2TsTOAkJVQYSp9ucG33tavU8hmaAGpNrp1upRQgi z/DxvgRl7FGjCJslH0JDvuhq/V+ADlNjgAKtqf52JP/R1x4zw6TJE1+eB8/5gsxUYU8V OJVgckCsJMrTJObEvEOlgw72eOM6pmltiOmD2j6JdxDfEUygQieb4l4JfrlG+D5dtyys K9Mq1nEKiIwwPjebN2VwcXcDMldlmWe7Q8Hk/qRH8p0kXzIKC9Xe7Fs/dpIvAW9YeB9G mVWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hzj8OtjaHAKx1NBUesa1KhmUxfrFA80XTWFu10bdNys=; b=pG0aKKf5Qchi/C5vWUwaPGjGuC5SrQzLVldERe8cErGHU1jBWyun8+1Z5F534AHiOD 6hKhrbyuyXO5cK7xk/91lVaeW2npqZoB8V0i1UGeD1ThWqbXiKcNVXiOsHWxoKMVqDKc wguuKPEesWfwk0+Cy44ZcPY8z0XoyIubb22IxpQgWVBUStumqJnNPlai9b2KLQa1Fy+I Q+oe9BATlARncdNAUKH4sJNWWglb48VdyQlmvdV3VUStuFVXM19dLWnf7rVnMwHdwV2K 85GbBh7w10XgcOiavP83J/8SAN0s5wPpcljI1P/G4F/5FTMwxoSnz3lZ7/OdDkRJtQNb W5CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=l8tHupMj; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bm10si21206299pgb.326.2022.02.01.12.41.45; Tue, 01 Feb 2022 12:42:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=l8tHupMj; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378025AbiAaPRc (ORCPT + 99 others); Mon, 31 Jan 2022 10:17:32 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:26406 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240373AbiAaPRZ (ORCPT ); Mon, 31 Jan 2022 10:17:25 -0500 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20VEur1u010872; Mon, 31 Jan 2022 15:17:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=hzj8OtjaHAKx1NBUesa1KhmUxfrFA80XTWFu10bdNys=; b=l8tHupMjW7z+WGncufxjtUmECUOZ5hQv2yRX6I2b3s31KfFztTlQJM7wrUU2Fntx0135 /EnU+C6v/szXIjAOMCfAt1YtMsoQ6/kInCsuqCQcpy/MddEACE3MlaAaTq7FJkTbsrKc FDO5SVKcqF12EtrPxP5ErlN/PjubhMNh9mfEOkDAhbr0PbPKgXkgWdjrbHrz5nbAcXi0 j4rHBXsn2CKWaxNyspJkcLYDRjPBsBZXtEP1ksTPHRsz7WKzJsmlrlsASIDanfjJKjcR 3tRMd274eSYAVrdOpYl2khtvqaFBIm3PgCfcQkoj3Dg3Wdm0oButKOv3FX0dF1ZqpDzQ iA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3dxhm3s4fh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 31 Jan 2022 15:17:21 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 20VEVjp1026662; Mon, 31 Jan 2022 15:17:21 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 3dxhm3s4eh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 31 Jan 2022 15:17:21 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 20VFCL8h004535; Mon, 31 Jan 2022 15:17:19 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma06ams.nl.ibm.com with ESMTP id 3dvvuj4wrn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 31 Jan 2022 15:17:18 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 20VFHGm646465374 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 Jan 2022 15:17:16 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4C7A04C059; Mon, 31 Jan 2022 15:17:16 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D3EE64C05C; Mon, 31 Jan 2022 15:17:15 +0000 (GMT) Received: from localhost (unknown [9.43.5.245]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 31 Jan 2022 15:17:15 +0000 (GMT) From: Ritesh Harjani To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, "Theodore Ts'o" , Jan Kara , Harshad Shirwadkar , Ritesh Harjani Subject: [RFC 6/6] ext4: Add extra check in ext4_mb_mark_bb() to prevent against possible corruption Date: Mon, 31 Jan 2022 20:46:55 +0530 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: isukeKH1Qu1x8SrxLPQ8yJYltflnbAZW X-Proofpoint-GUID: 7UNt2fYuUgAYGvtKEeB320kit2nBQrQB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-31_06,2022-01-31_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 suspectscore=0 phishscore=0 mlxscore=0 bulkscore=0 clxscore=1015 impostorscore=0 mlxlogscore=627 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2201310099 Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org This patch adds an extra checks in ext4_mb_mark_bb() function to make sure we mark & report error if we were to mark/clear any of the critical FS metadata specific bitmaps (&bail out) to prevent from any accidental corruption. Signed-off-by: Ritesh Harjani --- fs/ext4/mballoc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 5f20e355d08c..c94888534caa 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -3920,6 +3920,13 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block, len -= overflow; } + if (!ext4_group_block_valid(sb, group, block, len)) { + ext4_error(sb, "Marking blocks in system zone - " + "Block = %llu, len = %d", block, len); + bitmap_bh = NULL; + goto out_err; + } + clen = EXT4_NUM_B2C(sbi, len); bitmap_bh = ext4_read_block_bitmap(sb, group); -- 2.31.1