From 42f7017ee690eae3f0caee5bcce9d30885794a19 Mon Sep 17 00:00:00 2001 From: Su Yue Date: Tue, 15 May 2018 09:33:23 +0800 Subject: [PATCH] btrfs-progs: check: lowmem: check symlinks with append/immutable flags Define new error bit INODE_FLAGS_ERROR to represents invalid inode flags error. Symlinks should never have append/immutable flags set. While checking inodes, if found a symlink with append/immutable flags, report and record the inode flags error. This is for lowmem mode. Issue: #133 Signed-off-by: Su Yue Reviewed-by: Qu Wenruo Signed-off-by: David Sterba --- check/mode-lowmem.c | 10 ++++++++++ check/mode-lowmem.h | 1 + 2 files changed, 11 insertions(+) diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c index 989306f0..66da4531 100644 --- a/check/mode-lowmem.c +++ b/check/mode-lowmem.c @@ -2274,6 +2274,7 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path) struct btrfs_key last_key; u64 inode_id; u32 mode; + u64 flags; u64 nlink; u64 nbytes; u64 isize; @@ -2307,10 +2308,19 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path) isize = btrfs_inode_size(node, ii); nbytes = btrfs_inode_nbytes(node, ii); mode = btrfs_inode_mode(node, ii); + flags = btrfs_inode_flags(node, ii); dir = imode_to_type(mode) == BTRFS_FT_DIR; nlink = btrfs_inode_nlink(node, ii); nodatasum = btrfs_inode_flags(node, ii) & BTRFS_INODE_NODATASUM; + if (S_ISLNK(mode) && + flags & (BTRFS_INODE_IMMUTABLE | BTRFS_INODE_APPEND)) { + err |= INODE_FLAGS_ERROR; + error( +"symlinks must never have immutable/append flags set, root %llu inode item %llu flags %llu may be corrupted", + root->objectid, inode_id, flags); + } + while (1) { btrfs_item_key_to_cpu(path->nodes[0], &last_key, path->slots[0]); ret = btrfs_next_item(root, path); diff --git a/check/mode-lowmem.h b/check/mode-lowmem.h index e7ba62e2..91f7b6b1 100644 --- a/check/mode-lowmem.h +++ b/check/mode-lowmem.h @@ -44,6 +44,7 @@ #define DIR_COUNT_AGAIN (1<<20) /* DIR isize should be recalculated */ #define BG_ACCOUNTING_ERROR (1<<21) /* Block group accounting error */ #define FATAL_ERROR (1<<22) /* Fatal bit for errno */ +#define INODE_FLAGS_ERROR (1<<23) /* Invalid inode flags */ /* * Error bit for low memory mode check.