[2/3] btrfs-progs: lowmem: check symlinks with append/immutable flags
diff mbox

Message ID 20180514102922.8840-3-suy.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Su Yue May 14, 2018, 10:29 a.m. UTC
Symlinks should never have append/immutable flags.
While checking inodes, if found a symlink with append/immutable
flags, report and record the fatal error.

This is for lowmem mode.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Nikolay Borisov May 14, 2018, 11:17 a.m. UTC | #1
On 14.05.2018 13:29, Su Yue wrote:
> Symlinks should never have append/immutable flags.
> While checking inodes, if found a symlink with append/immutable
> flags, report and record the fatal error.
> 
> This is for lowmem mode.
> 
> Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
> ---
>  check/mode-lowmem.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
> index 9890180d1d3c..61c4e7f23d47 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 (mode & BTRFS_FT_SYMLINK &&
> +	    (flags & (BTRFS_INODE_IMMUTABLE | BTRFS_INODE_APPEND))) {
> +		err = FATAL_ERROR;
> +		error(
> +"symlinks shall never be with immutable/append, root %llu inode item [%llu] flags %llu may be corrupted",

How about: 

"symlinks must never have immutable/append flags set, root %llu ino %llu flag %llu may be corrupted". 

I think printing the ino number should suffice, no need for the "fancy" [] around the inode number. 
> +		      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);
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Qu Wenruo May 14, 2018, 11:27 a.m. UTC | #2
On 2018年05月14日 18:29, Su Yue wrote:
> Symlinks should never have append/immutable flags.
> While checking inodes, if found a symlink with append/immutable
> flags, report and record the fatal error.
> 
> This is for lowmem mode.
> 
> Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
> ---
>  check/mode-lowmem.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
> index 9890180d1d3c..61c4e7f23d47 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 (mode & BTRFS_FT_SYMLINK &&
> +	    (flags & (BTRFS_INODE_IMMUTABLE | BTRFS_INODE_APPEND))) {
> +		err = FATAL_ERROR;

Where is the FATAL_ERROR defined?
I can't find it anyway on v4.16 branch.

And I assume that FATAL_ERROR is defined to abort check, if so, in that
case the corruption is not that serious, just some unexpected behavior,
not a fatal error.

If not, just ignore this comment.

Thanks,
Qu

> +		error(
> +"symlinks shall never be with immutable/append, 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);
>
Damenly Su May 14, 2018, 12:04 p.m. UTC | #3
Indeed better. Will do it in V2.

Thanks,
Su

On Mon, May 14, 2018 at 7:19 PM Nikolay Borisov <nborisov@suse.com> wrote:



> On 14.05.2018 13:29, Su Yue wrote:
> > Symlinks should never have append/immutable flags.
> > While checking inodes, if found a symlink with append/immutable
> > flags, report and record the fatal error.
> >
> > This is for lowmem mode.
> >
> > Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
> > ---
> >  check/mode-lowmem.c | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> >
> > diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
> > index 9890180d1d3c..61c4e7f23d47 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 (mode & BTRFS_FT_SYMLINK &&
> > +         (flags & (BTRFS_INODE_IMMUTABLE | BTRFS_INODE_APPEND))) {
> > +             err = FATAL_ERROR;
> > +             error(
> > +"symlinks shall never be with immutable/append, root %llu inode item
[%llu] flags %llu may be corrupted",

> How about:

> "symlinks must never have immutable/append flags set, root %llu ino %llu
flag %llu may be corrupted".

> I think printing the ino number should suffice, no need for the "fancy"
[] around the inode number.
> > +                   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);
> >
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 9890180d1d3c..61c4e7f23d47 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 (mode & BTRFS_FT_SYMLINK &&
+	    (flags & (BTRFS_INODE_IMMUTABLE | BTRFS_INODE_APPEND))) {
+		err = FATAL_ERROR;
+		error(
+"symlinks shall never be with immutable/append, 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);