Bug 218309
Summary: | BUG REPORT: ubifs: inconsistent filesystem if powercut in selinux or encryption scenario | ||
---|---|---|---|
Product: | File System | Reporter: | Zhihao Cheng (chengzhihao1) |
Component: | Other | Assignee: | fs_other |
Status: | NEW --- | ||
Severity: | normal | ||
Priority: | P3 | ||
Hardware: | All | ||
OS: | Linux | ||
Kernel Version: | Subsystem: | ||
Regression: | No | Bisected commit-id: | |
Attachments: |
diff
test.sh partially fix patch powercut test case |
Description
Zhihao Cheng
2023-12-25 12:57:51 UTC
There are two paths creating xattrs before creating a new file: ubifs_create PATH 1: ubifs_new_inode -> fscrypt_set_context -> ubifs_crypt_set_context -> ubifs_xattr_set -> create_xattr -> ubifs_jnl_update // inode and xattrs are written on disk PATH 2: ubifs_init_security -> security_inode_init_security -> init_xattrs -> ubifs_xattr_set -> create_xattr -> ubifs_jnl_update // inode and xattrs are written on disk power cut !!! ubifs_jnl_update // write inode and dentry on disk Inode and xattrs are found on disk after mounting, there is no dentry corresponds to the inode, dbg_check_filesystem will report inconsistent filesystem! This problem is hard to be fixed, because UBIFS does't support an atomic operation for ubifs_create if selinux or encryption is enabled. The atomic op only works in ubifs_jnl_update for now. Created attachment 305653 [details]
diff
Created attachment 305654 [details]
test.sh
Reproducer:
CONFIG_FS_ENCRYPTION=y
1. Apply diff and compile kernel
2. ./test.sh && dmesg
[ 281.381740] UBIFS error (ubi0:0 pid 7995): dbg_check_filesystem [ubifs]: inode 66 nlink is 1, but calculated nlink is 0
[ 281.383330] UBIFS (ubi0:0): dump of the inode 66 sitting in LEB 12:4360
[ 281.383334] magic 0x6101831
[ 281.383784] crc 0xf4acb4b7
[ 281.384300] node_type 0 (inode node)
[ 281.384839] group_type 2 (last of node group)
[ 281.385353] sqnum 18
[ 281.385720] len 160
[ 281.386148] key (66, inode)
[ 281.386611] creat_sqnum 14
[ 281.387030] size 0
[ 281.387399] nlink 1
[ 281.387816] atime 1703508734.0
[ 281.388303] mtime 1703508734.0
[ 281.388813] ctime 1703508734.0
[ 281.389302] uid 0
[ 281.389668] gid 0
[ 281.390076] mode 33188
[ 281.390483] flags 0x41
[ 281.390917] xattr_cnt 1
[ 281.391295] xattr_size 272
[ 281.391682] xattr_names 1
[ 281.392088] compr_type 0x3
[ 281.392476] data len 0
[ 281.392878] UBIFS error (ubi0:0 pid 7995): dbg_check_filesystem [ubifs]: file-system check failed with error -22
Created attachment 306055 [details]
partially fix patch
cannot fix following case:
P1 P2
ubifs_create
ubifs_init_security
ubifs_xattr_set
ubifs_jnl_update
sync
>> powercut! <<
ubifs_jnl_update
Created attachment 306099 [details]
powercut test case
(In reply to Zhihao Cheng from comment #5) > Created attachment 306099 [details] > powercut test case Based on the framework [1] [1] https://patchwork.ozlabs.org/project/linux-mtd/patch/20231228013639.2827205-2-chengzhihao1@huawei.com/ |