+12
-6
fs/erofs/super.c
+12
-6
fs/erofs/super.c
···
644
644
* fs contexts (including its own) due to self-controlled RO
645
645
* accesses/contexts and no side-effect changes that need to
646
646
* context save & restore so it can reuse the current thread
647
-
* context. However, it still needs to bump `s_stack_depth` to
648
-
* avoid kernel stack overflow from nested filesystems.
647
+
* context.
648
+
* However, we still need to prevent kernel stack overflow due
649
+
* to filesystem nesting: just ensure that s_stack_depth is 0
650
+
* to disallow mounting EROFS on stacked filesystems.
651
+
* Note: s_stack_depth is not incremented here for now, since
652
+
* EROFS is the only fs supporting file-backed mounts for now.
653
+
* It MUST change if another fs plans to support them, which
654
+
* may also require adjusting FILESYSTEM_MAX_STACK_DEPTH.
649
655
*/
650
656
if (erofs_is_fileio_mode(sbi)) {
651
-
sb->s_stack_depth =
652
-
file_inode(sbi->dif0.file)->i_sb->s_stack_depth + 1;
653
-
if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
654
-
erofs_err(sb, "maximum fs stacking depth exceeded");
657
+
inode = file_inode(sbi->dif0.file);
658
+
if ((inode->i_sb->s_op == &erofs_sops && !sb->s_bdev) ||
659
+
inode->i_sb->s_stack_depth) {
660
+
erofs_err(sb, "file-backed mounts cannot be applied to stacked fses");
655
661
return -ENOTBLK;
656
662
}
657
663
}