* [bug report] A filesystem abnormal mount issue
@ 2025-07-17 9:11 Zizhi Wo
2025-07-17 9:39 ` Christian Brauner
0 siblings, 1 reply; 5+ messages in thread
From: Zizhi Wo @ 2025-07-17 9:11 UTC (permalink / raw)
To: jack, brauner, axboe, hch
Cc: linux-fsdevel, linux-kernel, wozizhi, yukuai3, yangerkun
Currently, we have the following test scenario:
disk_container=$(
${docker} run...kata-runtime...io.kubernets.docker.type=container...
)
docker_id=$(
${docker} run...kata-runtime...io.kubernets.docker.type=container...
io.katacontainers.disk_share="{"src":"/dev/sdb","dest":"/dev/test"}"...
)
${docker} stop "$disk_container"
${docker} exec "$docker_id" mount /dev/test /tmp -->success!!
When the "disk_container" is started, a series of block devices are
created. During the startup of "docker_id", /dev/test is created using
mknod. After "disk_container" is stopped, the created sda/sdb/sdc disks
are deleted, but mounting /dev/test still succeeds.
The reason is that runc calls unshare, which triggers clone_mnt(),
increasing the "sb->s_active" reference count. As long as the "docker_id"
does not exit, the superblock still has a reference count.
So when mounting, the old superblock is reused in sget_fc(), and the mount
succeeds, even if the actual device no longer exists. The whole process can
be simplified as follows:
mkfs.ext4 -F /dev/sdb
mount /dev/sdb /mnt
mknod /dev/test b 8 16 # [sdb 8:16]
echo 1 > /sys/block/sdb/device/delete
mount /dev/test /mnt1 # -> mount success
The overall change was introduced by: aca740cecbe5 ("fs: open block device
after superblock creation"). Previously, we would open the block device
once. Now, if the old superblock can be reused, the block device won't be
opened again.
Would it be possible to additionally open the block device in read-only
mode in super_s_dev_test() for verification? Or is there any better way to
avoid this issue?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [bug report] A filesystem abnormal mount issue
2025-07-17 9:11 [bug report] A filesystem abnormal mount issue Zizhi Wo
@ 2025-07-17 9:39 ` Christian Brauner
2025-07-17 11:04 ` Christoph Hellwig
2025-07-17 11:48 ` Zizhi Wo
0 siblings, 2 replies; 5+ messages in thread
From: Christian Brauner @ 2025-07-17 9:39 UTC (permalink / raw)
To: Zizhi Wo, hch
Cc: jack, axboe, linux-fsdevel, linux-kernel, yukuai3, yangerkun
On Thu, Jul 17, 2025 at 05:11:50PM +0800, Zizhi Wo wrote:
> Currently, we have the following test scenario:
>
> disk_container=$(
> ${docker} run...kata-runtime...io.kubernets.docker.type=container...
> )
> docker_id=$(
> ${docker} run...kata-runtime...io.kubernets.docker.type=container...
> io.katacontainers.disk_share="{"src":"/dev/sdb","dest":"/dev/test"}"...
> )
>
> ${docker} stop "$disk_container"
> ${docker} exec "$docker_id" mount /dev/test /tmp -->success!!
>
> When the "disk_container" is started, a series of block devices are
> created. During the startup of "docker_id", /dev/test is created using
> mknod. After "disk_container" is stopped, the created sda/sdb/sdc disks
> are deleted, but mounting /dev/test still succeeds.
>
> The reason is that runc calls unshare, which triggers clone_mnt(),
> increasing the "sb->s_active" reference count. As long as the "docker_id"
> does not exit, the superblock still has a reference count.
>
> So when mounting, the old superblock is reused in sget_fc(), and the mount
> succeeds, even if the actual device no longer exists. The whole process can
> be simplified as follows:
>
> mkfs.ext4 -F /dev/sdb
> mount /dev/sdb /mnt
> mknod /dev/test b 8 16 # [sdb 8:16]
> echo 1 > /sys/block/sdb/device/delete
> mount /dev/test /mnt1 # -> mount success
>
> The overall change was introduced by: aca740cecbe5 ("fs: open block device
> after superblock creation"). Previously, we would open the block device
> once. Now, if the old superblock can be reused, the block device won't be
> opened again.
>
> Would it be possible to additionally open the block device in read-only
> mode in super_s_dev_test() for verification? Or is there any better way to
> avoid this issue?
As long as you use the new mount api you should pass
FSCONFIG_CMD_CREATE_EXCL which will refuse to mount if a superblock for
the device already exists. IOW, it ensure that you cannot silently reuse
a superblock.
Other than that I think a blkdev_get_no_open(dev, false) after
lookup_bdev() should sort the issue out. Christoph?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [bug report] A filesystem abnormal mount issue
2025-07-17 9:39 ` Christian Brauner
@ 2025-07-17 11:04 ` Christoph Hellwig
2025-07-17 11:49 ` Zizhi Wo
2025-07-17 11:48 ` Zizhi Wo
1 sibling, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2025-07-17 11:04 UTC (permalink / raw)
To: Christian Brauner
Cc: Zizhi Wo, hch, jack, axboe, linux-fsdevel, linux-kernel, yukuai3,
yangerkun
On Thu, Jul 17, 2025 at 11:39:01AM +0200, Christian Brauner wrote:
> As long as you use the new mount api you should pass
> FSCONFIG_CMD_CREATE_EXCL which will refuse to mount if a superblock for
> the device already exists. IOW, it ensure that you cannot silently reuse
> a superblock.
>
> Other than that I think a blkdev_get_no_open(dev, false) after
> lookup_bdev() should sort the issue out. Christoph?
Or just check for GD_DEAD before the mount proceeds?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [bug report] A filesystem abnormal mount issue
2025-07-17 9:39 ` Christian Brauner
2025-07-17 11:04 ` Christoph Hellwig
@ 2025-07-17 11:48 ` Zizhi Wo
1 sibling, 0 replies; 5+ messages in thread
From: Zizhi Wo @ 2025-07-17 11:48 UTC (permalink / raw)
To: Christian Brauner, hch
Cc: jack, axboe, linux-fsdevel, linux-kernel, yukuai3, yangerkun
在 2025/7/17 17:39, Christian Brauner 写道:
> On Thu, Jul 17, 2025 at 05:11:50PM +0800, Zizhi Wo wrote:
>> Currently, we have the following test scenario:
>>
>> disk_container=$(
>> ${docker} run...kata-runtime...io.kubernets.docker.type=container...
>> )
>> docker_id=$(
>> ${docker} run...kata-runtime...io.kubernets.docker.type=container...
>> io.katacontainers.disk_share="{"src":"/dev/sdb","dest":"/dev/test"}"...
>> )
>>
>> ${docker} stop "$disk_container"
>> ${docker} exec "$docker_id" mount /dev/test /tmp -->success!!
>>
>> When the "disk_container" is started, a series of block devices are
>> created. During the startup of "docker_id", /dev/test is created using
>> mknod. After "disk_container" is stopped, the created sda/sdb/sdc disks
>> are deleted, but mounting /dev/test still succeeds.
>>
>> The reason is that runc calls unshare, which triggers clone_mnt(),
>> increasing the "sb->s_active" reference count. As long as the "docker_id"
>> does not exit, the superblock still has a reference count.
>>
>> So when mounting, the old superblock is reused in sget_fc(), and the mount
>> succeeds, even if the actual device no longer exists. The whole process can
>> be simplified as follows:
>>
>> mkfs.ext4 -F /dev/sdb
>> mount /dev/sdb /mnt
>> mknod /dev/test b 8 16 # [sdb 8:16]
>> echo 1 > /sys/block/sdb/device/delete
>> mount /dev/test /mnt1 # -> mount success
>>
>> The overall change was introduced by: aca740cecbe5 ("fs: open block device
>> after superblock creation"). Previously, we would open the block device
>> once. Now, if the old superblock can be reused, the block device won't be
>> opened again.
>>
>> Would it be possible to additionally open the block device in read-only
>> mode in super_s_dev_test() for verification? Or is there any better way to
>> avoid this issue?
>
> As long as you use the new mount api you should pass
> FSCONFIG_CMD_CREATE_EXCL which will refuse to mount if a superblock for
> the device already exists. IOW, it ensure that you cannot silently reuse
> a superblock.
Yes, it is indeed exclusive.
>
> Other than that I think a blkdev_get_no_open(dev, false) after
> lookup_bdev() should sort the issue out. Christoph?
Oh, I didn't consider it before. blkdev_get_no_open() is sufficient.
Thanks for suggestion!
Thanks,
Zizhi Wo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [bug report] A filesystem abnormal mount issue
2025-07-17 11:04 ` Christoph Hellwig
@ 2025-07-17 11:49 ` Zizhi Wo
0 siblings, 0 replies; 5+ messages in thread
From: Zizhi Wo @ 2025-07-17 11:49 UTC (permalink / raw)
To: Christoph Hellwig, Christian Brauner
Cc: jack, axboe, linux-fsdevel, linux-kernel, yukuai3, yangerkun
在 2025/7/17 19:04, Christoph Hellwig 写道:
> On Thu, Jul 17, 2025 at 11:39:01AM +0200, Christian Brauner wrote:
>> As long as you use the new mount api you should pass
>> FSCONFIG_CMD_CREATE_EXCL which will refuse to mount if a superblock for
>> the device already exists. IOW, it ensure that you cannot silently reuse
>> a superblock.
>>
>> Other than that I think a blkdev_get_no_open(dev, false) after
>> lookup_bdev() should sort the issue out. Christoph?
>
> Or just check for GD_DEAD before the mount proceeds?
This is indeed concise and effective enough. Thank you for your
suggestion.
Thanks,
Zizhi Wo
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-07-17 11:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-17 9:11 [bug report] A filesystem abnormal mount issue Zizhi Wo
2025-07-17 9:39 ` Christian Brauner
2025-07-17 11:04 ` Christoph Hellwig
2025-07-17 11:49 ` Zizhi Wo
2025-07-17 11:48 ` Zizhi Wo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).