mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: zhoumin <teczm@foxmail.com>
To: hirofumi@mail.parknet.co.jp
Cc: linux-kernel@vger.kernel.org, teczm@foxmail.com
Subject: Re: [PATCH] vfat: fix uninitialized i_pos error
Date: Wed, 20 Aug 2025 00:17:12 +0800	[thread overview]
Message-ID: <tencent_93CE617328A1683191A7418BCCE87AFE500A@qq.com> (raw)
In-Reply-To: <87o6sbz5kd.fsf@mail.parknet.co.jp>

Hi OGAWA-san,

Thank you for your review and feedback.

>> The i_pos field remains uninitialized when fat_fs_error_ratelimit() reports
>> error, e.g.,
>>
>> 	[ 1642.703550] FAT-fs (loop0): error, fat_get_cluster: invalid
>> 	cluster chain (i_pos 0)
>>
>> Since i_pos is assigned in fat_attach after fat_fill_inode, the error
>> message lacks useful debug info.
>>
>> Path:
>> vfat_lookup
>> 	fat_build_inode
>> 		fat_fill_inode
>> 			fat_calc_dir_size
>>           			fat_get_cluster /* report error */
>>       	fat_attach  /* i_pos assigned here */

> No. It is initialized as 0, and it must be unavailable outside
> between fat_attach and fat_detach.

I see that it was initialized to 0. What I meant is that when
fat_fs_error_ratelimit uses i_pos for debugging output, it doesn't get the
correct value.

> IOW, this is introducing the race.
I'm not quite clear about the race condition you mentioned here. Could you
give an example to explain it?

Actually, the modification I initially considered was as follows. I'm not
sure if this approach carries any risks. If it's acceptable, I'm ready to
submit a new version.

Thank you.


diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index 3852bb66358c..837b1ad361ca 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -605,13 +605,14 @@ struct inode *fat_build_inode(struct super_block *sb,
        }
        inode->i_ino = iunique(sb, MSDOS_ROOT_INO);
        inode_set_iversion(inode, 1);
+       fat_attach(inode, i_pos);
        err = fat_fill_inode(inode, de);
        if (err) {
                iput(inode);
+               fat_detach(inode);
                inode = ERR_PTR(err);
                goto out;
-       }
-       fat_attach(inode, i_pos);
+       }
        insert_inode_hash(inode);
 out:
        fat_unlock_build_inode(MSDOS_SB(sb));

Best regards,
zhoumin


  reply	other threads:[~2025-08-19 16:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-19 15:00 zhoumin
2025-08-19 15:36 ` OGAWA Hirofumi
2025-08-19 16:17   ` zhoumin [this message]
2025-08-19 16:57     ` OGAWA Hirofumi
2025-08-19 17:28       ` zhoumin

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=tencent_93CE617328A1683191A7418BCCE87AFE500A@qq.com \
    --to=teczm@foxmail.com \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®