Linux EXT4 FS development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xing Ma" <maxing.lan@bytedance.com>, linux-ext4@vger.kernel.org
Cc: tytso@mit.edu
Subject: Re: [PATCH 2/2] ext4: track truncated block range in ext4_truncate() for fast commit
Date: Mon, 30 Nov 2026 17:09:54 +0000	[thread overview]
Message-ID: <sashiko-outbox-241665@kernel.org> (raw)
In-Reply-To: <20261130163929.14058-3-maxing.lan@bytedance.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] ext4: NULL pointer dereference in ext4_truncate() on failed
  journal restart
- [Medium] ext4: ext4_truncate() skips ext4_fc_track_range() for
  indirect inodes
--

commit 80834a510a624cb3f489ed5a5d96c25207ac7e1e
Author: Xing Ma <maxing.lan@bytedance.com>

ext4: track truncated block range in ext4_truncate() for fast commit

This commit calls ext4_fc_track_range() in ext4_truncate() after
releasing i_data_sem so fast commit records the truncated logical block
range when ext4_truncate_down() was bypassed or ran in an earlier
transaction.

> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 07a62d8569d31..9edb29ca2e1b7 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -5605,6 +5605,14 @@ int ext4_truncate(struct inode *inode)
>  		ext4_ind_truncate(handle, inode);
>  
>  	up_write(&ei->i_data_sem);
> +	if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) {

[Severity: Medium]
Should ext4_fc_track_range() be called unconditionally here, as in
ext4_truncate_down()?

ext4_fc_track_inode() is called unconditionally earlier in
ext4_truncate(), which resets ei->i_fc_lblk_len to 0 in a new
transaction, and ext4_ind_truncate() removes the truncated tail from the
extent status tree and can also restart the journal handle.  When an
indirect-mapped inode is truncated without calling ext4_fc_track_range(),
ei->i_fc_lblk_len stays 0, so ext4_fc_snapshot_inode_data() returns 0
with no ranges instead of hitting an extent status tree miss (-EAGAIN)
and falling back to a full commit.  Fast commit then writes an
EXT4_FC_TAG_INODE record for the indirect-mapped inode, causing
ext4_fc_replay_inode() -> ext4_ext_clear_bb() to fail journal recovery
with -EFSCORRUPTED.

> +		ext4_lblk_t start_lblk;
> +
> +		start_lblk = inode->i_size > 0 ?
> +			(inode->i_size - 1) >> inode->i_blkbits : 0;
> +		ext4_fc_track_range(handle, inode, start_lblk,
> +				    EXT_MAX_BLOCKS - 1);
> +	}
>  	if (err)
>  		goto out_stop;

[Severity: High]
Can calling ext4_fc_track_range() before checking err cause a NULL
pointer dereference on handle->h_transaction?

If ext4_ext_truncate() -> ext4_ext_remove_space() runs out of handle
credits and calls jbd2__journal_restart() after the journal has aborted,
stop_this_handle() sets handle->h_transaction = NULL before
start_this_handle() fails with -EROFS.  Calling ext4_fc_track_range() on
that error path reaches ext4_fc_track_template(), which dereferences
handle->h_transaction->t_tid before the if (err) check jumps to out_stop.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130163929.14058-1-maxing.lan@bytedance.com?part=2

  reply	other threads:[~2026-11-30 17:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 16:39 [PATCH 0/2] ext4: fix fast commit orphan inode replay and truncate range tracking Xing Ma
2026-11-30 16:39 ` [PATCH 1/2] ext4: fall back to full commit for unlinked or orphan inodes in fast commit Xing Ma
2026-11-30 16:39 ` [PATCH 2/2] ext4: track truncated block range in ext4_truncate() for " Xing Ma
2026-11-30 17:09   ` sashiko-bot [this message]
2026-11-30 17:10 ` [PATCH 0/2] ext4: fix fast commit orphan inode replay and truncate range tracking sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-241665@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=maxing.lan@bytedance.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox