From: Nikolay Borisov <nborisov@suse.com>
To: Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Cc: Thorsten Hirsch <t.hirsch@web.de>
Subject: Re: [PATCH 1/7] btrfs-progs: check/lowmem: Add inode mode check
Date: Mon, 25 Mar 2019 17:40:59 +0200 [thread overview]
Message-ID: <7034c58e-686f-4ded-2d87-565ded42e316@suse.com> (raw)
In-Reply-To: <20190325082253.19583-2-wqu@suse.com>
On 25.03.19 г. 10:22 ч., Qu Wenruo wrote:
> There is one report about invalid free space cache inode mode.
> Normally free space cache inode should have mode 100600 (regular file,
> no uid/gid/sticky bit, rw------ bit).
>
> But in that report, we have free space cache inode mode as 0.
>
> So at least btrfs check should report invalid inode mode.
>
> This patch will at least make btrfs check lowmem mode to detect this
> problem.
>
> Please note that, this check only applies to inodes in fs/subvol trees.
> It doesn't apply to free space cache inodes.
>
> Reported-by: Thorsten Hirsch <t.hirsch@web.de>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
> ---
> check/mode-common.h | 24 ++++++++++++++++++++++++
> check/mode-lowmem.c | 5 +++++
> check/mode-lowmem.h | 1 +
> 3 files changed, 30 insertions(+)
>
> diff --git a/check/mode-common.h b/check/mode-common.h
> index 1fb3cda7d89d..4c88365abbcc 100644
> --- a/check/mode-common.h
> +++ b/check/mode-common.h
> @@ -126,4 +126,28 @@ int delete_corrupted_dir_item(struct btrfs_trans_handle *trans,
> struct btrfs_key *di_key, char *namebuf,
> u32 namelen);
>
> +/*
> + * Check if the inode mode @imode is valid
> + *
> + * This check focuses on S_FTMT bits and unused bits.
> + * Sticky/setuid/setgid and regular owner/group/other bits won't cause
> + * any problem.
> + */
> +static inline bool is_valid_imode(u32 imode)
> +{
> + if (imode & ~(S_IFMT | 07777))
> + return false;
> +
> + /*
> + * S_IFMT is not bitmap, nor pure numbering sequence. Need per valid
> + * number check.
> + */
> + imode &= S_IFMT;
> + if (imode != S_IFDIR && imode != S_IFCHR && imode != S_IFBLK &&
> + imode != S_IFREG && imode != S_IFIFO && imode != S_IFLNK &&
> + imode != S_IFSOCK)
> + return false;
> + return true;
> +}
> +
> #endif
> diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
> index fc6228a05a1b..1553a4a5d2c1 100644
> --- a/check/mode-lowmem.c
> +++ b/check/mode-lowmem.c
> @@ -2452,6 +2452,11 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path)
> nlink = btrfs_inode_nlink(node, ii);
> nodatasum = btrfs_inode_flags(node, ii) & BTRFS_INODE_NODATASUM;
>
> + if (!is_valid_imode(mode)) {
> + error("invalid imode mode bits: 0%o", mode);
> + err |= INODE_MODE_ERROR;
> + }
> +
> if (S_ISLNK(mode) &&
> flags & (BTRFS_INODE_IMMUTABLE | BTRFS_INODE_APPEND)) {
> err |= INODE_FLAGS_ERROR;
> diff --git a/check/mode-lowmem.h b/check/mode-lowmem.h
> index 46b9b191ce24..e0ab30b770d5 100644
> --- a/check/mode-lowmem.h
> +++ b/check/mode-lowmem.h
> @@ -46,6 +46,7 @@
> #define FATAL_ERROR (1<<22) /* Fatal bit for errno */
> #define INODE_FLAGS_ERROR (1<<23) /* Invalid inode flags */
> #define DIR_ITEM_HASH_MISMATCH (1<<24) /* Dir item hash mismatch */
> +#define INODE_MODE_ERROR (1<<25) /* Bad inode mode */
>
> /*
> * Error bit for low memory mode check.
>
next prev parent reply other threads:[~2019-03-25 15:41 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-25 8:22 [PATCH 0/7] btrfs: check: Check and repair invalid free space cahce inode mode Qu Wenruo
2019-03-25 8:22 ` [PATCH 1/7] btrfs-progs: check/lowmem: Add inode mode check Qu Wenruo
2019-03-25 15:40 ` Nikolay Borisov [this message]
2019-03-25 8:22 ` [PATCH 2/7] btrfs-progs: check/original: " Qu Wenruo
2019-03-25 15:43 ` Nikolay Borisov
2019-03-25 22:59 ` Qu Wenruo
2019-03-25 8:22 ` [PATCH 3/7] btrfs-progs: check/lowmem: Repair invalid inode mode in root tree Qu Wenruo
2019-03-29 9:36 ` Nikolay Borisov
2019-03-29 11:00 ` Qu Wenruo
2019-03-25 8:22 ` [PATCH 4/7] btrfs-progs: check/original: " Qu Wenruo
2019-03-25 8:22 ` [PATCH 5/7] btrfs: check/lowmem: Check and repair free space cache inode mode Qu Wenruo
2019-03-25 14:36 ` Su Yue
2019-03-25 14:39 ` Qu Wenruo
2019-03-29 9:40 ` Nikolay Borisov
2019-03-29 11:02 ` Qu Wenruo
2019-03-29 11:47 ` Nikolay Borisov
2019-03-25 8:22 ` [PATCH 6/7] btrfs: check/original: Check and repair free space cache inode item Qu Wenruo
2019-03-25 8:22 ` [PATCH 7/7] btrfs: tests/fsck: Add test image for free space cache mode repair Qu Wenruo
2019-03-29 12:05 ` Nikolay Borisov
2019-03-29 12:08 ` Qu Wenruo
2019-04-01 5:52 ` Qu Wenruo
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=7034c58e-686f-4ded-2d87-565ded42e316@suse.com \
--to=nborisov@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=t.hirsch@web.de \
--cc=wqu@suse.com \
/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;
as well as URLs for NNTP newsgroup(s).