From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej2-f43.google.com (mail-ej2-f43.google.com [74.125.228.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0976844237A for ; Mon, 28 Sep 2026 07:39:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790581162; cv=none; b=PzqRSZAVyXFCpHM34H+hh1cUpI4Rs5jRpIMRFk333ZgpdLKucUx+fE0QeCX1y3SttM2mAuZ2hmT/QkEuQ4+xstkNZSs2r3wqqyJxcOJYW8YylpVmTuRTAsPTqyuKzN04ydPVonCgoA55D9zfguUkPxdsMtW7G88IZ3Kupwjrp0w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790581162; c=relaxed/simple; bh=Ee1O85EU6mL4A+k6BaSrrjPcrUn1HmO7/SaFHlvVrt8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Fd9CAHmFotHHFFB51jn9dMBQi95svaY75sY58+0X5hf89lj86IBds3aaWxvP2C9hbAsn/3PQtYYUtAs9wRpqZP9PX2YjVdqgVnM2gi6oKLlrw+w8HDXvRxGWLt9iclbTRQlMeAUWEFedkIj1G9ahjfxgZWZfVGja+8etRCuyIKA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=g74e64mX; arc=none smtp.client-ip=74.125.228.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="g74e64mX" Received: by mail-ej2-f43.google.com with SMTP id a640c23a62f3a-c2afcb5c60aso15002966b.2 for ; Mon, 28 Sep 2026 00:39:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1790581158; x=1791185958; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=poKTzHIbdYPKoKWNDbZeL46WSq1iGtUDaGIwgKIDsjM=; b=g74e64mX4uhdKFr8mPvdikyHDNWIvDfR7MG+MvcfrrJWyPOzOqXXpX/ghFLXZZDIFo 825xMWRyo8pOUD/mGhnXeJOBoarOnpu16zFtYIvbrKiyOBpww2/M5wf7XAnNbsXTlGTM vUu9DhE792ZILfhbTytipeCUJA8evPo3olQ3x8sA+HuJonvNbFgHhg9UBQECaiNP6b2N +qrDkRdsEA7o5iSL7cSefZrpi641V2fEdoRttQjoRCg2QpCQeFQI2WKqV4cfTLxxmHYA anGkv3a6+/J6E6/CuVokROCWl8TitMzaaxLo06WPwT4LuaxbrOez9s1MpTfw2X+R8zVy YENQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790581158; x=1791185958; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=poKTzHIbdYPKoKWNDbZeL46WSq1iGtUDaGIwgKIDsjM=; b=UiBtA3DrSyqn398XDy1otBXTKYpq9mlDvDcoZzdXodHmoKCZ+Fop8SvLJYrhnR1STa 0mcgPK0jIkTfw+0ETA4abh4wNPURAAvnsGmctRHuCY/FLTLVbO/dabtsJoyOOkGIKyk/ 0BpIsJ7eV3/5qteIYd6w/oiPTS4naN18zRCTB1XIYbV1L1Y796jO2QhQgu0Ds5fSuiSV BRjaXjWXqmYtsdpZx6SJkQA0SsgKgXD1EQGLHoAR22hXkmezJJUu0X/BcCOmCafHFbtm /R9FJrnB13PcdPxdW/AgNPPqLVnLd00EpLbItF8sVPtIzEtMPHE6UwqEx0Qc+EltB2p6 3qQA== X-Forwarded-Encrypted: i=1; AKwUvByz6ygSSRTEXNsiw1p+HFvqoSRIfewj1sSMHqlCrtaYWFb+Cb3RKGk1kcGgTVw22ghoRFG6xcwgljMbugA=@vger.kernel.org X-Gm-Message-State: AFuF++lT+kbJOFro/rQTNGxmDyngI/CtCzbJURgxGrONKvmcNzLgCaqB lE0Yl8Ajr7o9tughuvw1P8vPxUnWqd9dHl96E9mFKWuKNJ5J1Fesfr+OIx+DRgeansk= X-Gm-Gg: AYBFou0n9QmUciGZDfpgQfVHOUuPD0nqXE5o0lfv851m0bWSvQzNEpeOFggm74QkGVS bK5ljbIa8wYwKbY0WJHHIK1hAi8//HOnWKQyI1j0A+shaBPGLFgjPVsmaNKC8CGb+cfV7Xi8l+U Pu0ccftFklm1sLgOq9tl+MOV4JQr0UK+GfBs4ikfs2QKJaITj2RZEIc4qBjxkBXP/F4lyr+FlHH 6+SMXaV9IKIffwGiXmIt0rm2nwFrJ4ZV+XcyMUjIDP+lQnZKsJwZpxmlRRjEPDipdNZtI39O9rs qLIleyNmXaxFp8HsFK6RK1Hvm0ZYGQMMhaP8UoEHlaGwYAw9/+NqtcYmxxNI2c6QmDJDqw003Ga +nACxZ7CuDz3xS1hgML+GylrxXqWDWFjb3aoKnO6BxbK2z5fxSFk0P1xpdbNhY8EJcJVTndlIZ5 BvBI1wbeB/4cde3j1Q3+xQuRVhYyl2By6/C1sUWkYozn9jRVG1sOVvESpCaSiyeeFn+EcS X-Received: by 2002:a17:907:9719:b0:c2d:e6a7:81d5 with SMTP id a640c23a62f3a-c2de6a7d020mr58347466b.1.1790581158165; Mon, 28 Sep 2026 00:39:18 -0700 (PDT) Received: from localhost ([202.127.77.110]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-87fea19030bsm3742545b3a.11.2026.09.28.00.39.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2026 00:39:17 -0700 (PDT) Date: Mon, 28 Sep 2026 15:39:14 +0800 From: Heming Zhao To: Joseph Qi , yaojiale02@163.com Cc: Andrew Morton , Mark Fasheh , Joel Becker , ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ocfs2: validate extent list in filecheck repair Message-ID: References: <20260926131848.3379842-1-yaojiale02@163.com> <744a70bd-5455-421f-a37d-1c0a63f54b60@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <744a70bd-5455-421f-a37d-1c0a63f54b60@linux.alibaba.com> On Mon, Sep 28, 2026 at 09:33:12AM +0800, Joseph Qi wrote: > > > On 9/26/26 9:18 PM, Jiale Yao wrote: > > ocfs2_filecheck_validate_inode_block() does not validate the embedded > > extent list, while ocfs2_filecheck_repair_inode_block() only clamps > > l_next_free_rec to l_count. The normal inode read path requires l_count > > to be non-zero, limits it to the number of extent records that fit in the > > inode, and requires l_next_free_rec not to exceed l_count. > > > > Without the same checks, filecheck can report SUCCESS while leaving an > > invalid extent list on disk. A later read through the normal inode > > validation path rejects the inode and makes the filesystem read-only. > > > > Add a shared helper for the filecheck paths to check these invariants. > > The filecheck validator now rejects all three cases. The repair path > > still clamps l_next_free_rec, but refuses to repair zero or oversized > > l_count values. > > > > Fixes: d56a8f32e4c6 ("ocfs2: check/fix inode block for online file check") > > I'd like make this as a new ability rather than a bug fix. Agree In my experience, users run online file checks only when inode data is corrupted, or when fsck/debugfs has already reported an inode issue prior to the check. The Fixes tag should only be used for the patch that fixes the unintended panic and read-only issue introduced by commit d56a8f32e4c6. - Heming > > > Signed-off-by: Jiale Yao > > --- > > fs/ocfs2/inode.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 71 insertions(+) > > > > diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c > > index 180107a11046..57168ed02915 100644 > > --- a/fs/ocfs2/inode.c > > +++ b/fs/ocfs2/inode.c > > @@ -249,6 +249,41 @@ static int ocfs2_dinode_has_extents(struct ocfs2_dinode *di) > > return 1; > > } > > > > +enum ocfs2_extent_list_status { > > + OCFS2_EXTENT_LIST_OK, > > + OCFS2_EXTENT_LIST_ZERO_COUNT, > > + OCFS2_EXTENT_LIST_OVERSIZED, > > + OCFS2_EXTENT_LIST_BAD_NEXT_FREE, > > +}; > > + > > +static enum ocfs2_extent_list_status > > +ocfs2_check_extent_list(struct super_block *sb, struct ocfs2_dinode *di) > > +{ > > + struct ocfs2_extent_list *el = &di->id2.i_list; > > + u16 count; > > + u16 next_free; > > + > > + if (!ocfs2_dinode_has_extents(di)) > > + return OCFS2_EXTENT_LIST_OK; > > + > > + count = le16_to_cpu(el->l_count); > > + next_free = le16_to_cpu(el->l_next_free_rec); > > + if (count == 0) > > + return OCFS2_EXTENT_LIST_ZERO_COUNT; > > + /* > > + * The exact capacity depends on i_xattr_inline_size, another > > + * unvalidated on-disk field. Inline xattrs only shrink the > > + * list, so the no-xattr maximum is a safe upper bound that a > > + * valid l_count never exceeds. > > + */ > > + if (count > ocfs2_extent_recs_per_inode(sb)) > > + return OCFS2_EXTENT_LIST_OVERSIZED; > > + if (next_free > count) > > + return OCFS2_EXTENT_LIST_BAD_NEXT_FREE; > > + > > + return OCFS2_EXTENT_LIST_OK; > > +} > > This seems a duplicated check in ocfs2_validate_inode_block(). > So I sugguest just extract the helper from it instead of duplicating > a new one. > > BTW, seems we don't have to introduce enum ocfs2_extent_list_status, > to make the checks simple. > > Thanks, > Joseph > > > + > > /* > > * here's how inodes get read from disk: > > * iget5_locked -> find_actor -> OCFS2_FIND_ACTOR > > @@ -1835,6 +1870,33 @@ static int ocfs2_filecheck_validate_inode_block(struct super_block *sb, > > goto bail; > > } > > > > + switch (ocfs2_check_extent_list(sb, di)) { > > + case OCFS2_EXTENT_LIST_OK: > > + break; > > + case OCFS2_EXTENT_LIST_ZERO_COUNT: > > + mlog(ML_ERROR, > > + "Filecheck: invalid dinode #%llu: extent list l_count is zero\n", > > + (unsigned long long)bh->b_blocknr); > > + rc = -OCFS2_FILECHECK_ERR_INVALIDINO; > > + goto bail; > > + case OCFS2_EXTENT_LIST_OVERSIZED: > > + mlog(ML_ERROR, > > + "Filecheck: invalid dinode #%llu: extent list l_count %u exceeds max %u\n", > > + (unsigned long long)bh->b_blocknr, > > + le16_to_cpu(di->id2.i_list.l_count), > > + ocfs2_extent_recs_per_inode(sb)); > > + rc = -OCFS2_FILECHECK_ERR_INVALIDINO; > > + goto bail; > > + case OCFS2_EXTENT_LIST_BAD_NEXT_FREE: > > + mlog(ML_ERROR, > > + "Filecheck: invalid dinode #%llu: extent list l_next_free_rec %u exceeds l_count %u\n", > > + (unsigned long long)bh->b_blocknr, > > + le16_to_cpu(di->id2.i_list.l_next_free_rec), > > + le16_to_cpu(di->id2.i_list.l_count)); > > + rc = -OCFS2_FILECHECK_ERR_INVALIDINO; > > + goto bail; > > + } > > + > > if (ocfs2_dinode_has_size_without_clusters(sb, di)) { > > if (S_ISDIR(le16_to_cpu(di->i_mode))) > > mlog(ML_ERROR, > > @@ -1893,6 +1955,15 @@ static int ocfs2_filecheck_repair_inode_block(struct super_block *sb, > > return -OCFS2_FILECHECK_ERR_VALIDFLAG; > > } > > > > + switch (ocfs2_check_extent_list(sb, di)) { > > + case OCFS2_EXTENT_LIST_OK: > > + case OCFS2_EXTENT_LIST_BAD_NEXT_FREE: > > + break; > > + case OCFS2_EXTENT_LIST_ZERO_COUNT: > > + case OCFS2_EXTENT_LIST_OVERSIZED: > > + return -OCFS2_FILECHECK_ERR_INVALIDINO; > > + } > > + > > if (le64_to_cpu(di->i_blkno) != bh->b_blocknr) { > > di->i_blkno = cpu_to_le64(bh->b_blocknr); > > changed = 1; >