All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Dilger <adilger@dilger.ca>
To: Chengguang Xu <cgxu519@zoho.com.cn>
Cc: Jan Kara <jack@suse.com>, linux-ext4 <linux-ext4@vger.kernel.org>
Subject: Re: [PATCH v2 1/2] ext2: introduce helper for xattr header validation
Date: Tue, 14 May 2019 09:32:10 -0600	[thread overview]
Message-ID: <3F06FAEE-E534-42A0-A927-A07259070D6A@dilger.ca> (raw)
In-Reply-To: <20190513224042.23377-1-cgxu519@zoho.com.cn>

[-- Attachment #1: Type: text/plain, Size: 3359 bytes --]

On May 13, 2019, at 4:40 PM, Chengguang Xu <cgxu519@zoho.com.cn> wrote:
> 
> Introduce helper function ext2_xattr_header_valid()
> for xattr header validation and clean up the header
> check ralated code.
> 
> Signed-off-by: Chengguang Xu <cgxu519@zoho.com.cn>

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> ---
> v1->v2:
> - Pass xattr header to ext2_xattr_header_valid().
> - Change signed-off mail address.
> 
> fs/ext2/xattr.c | 31 ++++++++++++++++++++-----------
> 1 file changed, 20 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
> index 1e33e0ac8cf1..db27260d6a5b 100644
> --- a/fs/ext2/xattr.c
> +++ b/fs/ext2/xattr.c
> @@ -134,6 +134,16 @@ ext2_xattr_handler(int name_index)
> 	return handler;
> }
> 
> +static bool
> +ext2_xattr_header_valid(struct ext2_xattr_header *header)
> +{
> +	if (header->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
> +	    header->h_blocks != cpu_to_le32(1))
> +		return false;
> +
> +	return true;
> +}
> +
> /*
>  * ext2_xattr_get()
>  *
> @@ -176,9 +186,9 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
> 	ea_bdebug(bh, "b_count=%d, refcount=%d",
> 		atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
> 	end = bh->b_data + bh->b_size;
> -	if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
> -	    HDR(bh)->h_blocks != cpu_to_le32(1)) {
> -bad_block:	ext2_error(inode->i_sb, "ext2_xattr_get",
> +	if (!ext2_xattr_header_valid(HDR(bh))) {
> +bad_block:
> +		ext2_error(inode->i_sb, "ext2_xattr_get",
> 			"inode %ld: bad block %d", inode->i_ino,
> 			EXT2_I(inode)->i_file_acl);
> 		error = -EIO;
> @@ -266,9 +276,9 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
> 	ea_bdebug(bh, "b_count=%d, refcount=%d",
> 		atomic_read(&(bh->b_count)), le32_to_cpu(HDR(bh)->h_refcount));
> 	end = bh->b_data + bh->b_size;
> -	if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
> -	    HDR(bh)->h_blocks != cpu_to_le32(1)) {
> -bad_block:	ext2_error(inode->i_sb, "ext2_xattr_list",
> +	if (!ext2_xattr_header_valid(HDR(bh))) {
> +bad_block:
> +		ext2_error(inode->i_sb, "ext2_xattr_list",
> 			"inode %ld: bad block %d", inode->i_ino,
> 			EXT2_I(inode)->i_file_acl);
> 		error = -EIO;
> @@ -406,9 +416,9 @@ ext2_xattr_set(struct inode *inode, int name_index, const char *name,
> 			le32_to_cpu(HDR(bh)->h_refcount));
> 		header = HDR(bh);
> 		end = bh->b_data + bh->b_size;
> -		if (header->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
> -		    header->h_blocks != cpu_to_le32(1)) {
> -bad_block:		ext2_error(sb, "ext2_xattr_set",
> +		if (!ext2_xattr_header_valid(header)) {
> +bad_block:
> +			ext2_error(sb, "ext2_xattr_set",
> 				"inode %ld: bad block %d", inode->i_ino,
> 				   EXT2_I(inode)->i_file_acl);
> 			error = -EIO;
> @@ -784,8 +794,7 @@ ext2_xattr_delete_inode(struct inode *inode)
> 		goto cleanup;
> 	}
> 	ea_bdebug(bh, "b_count=%d", atomic_read(&(bh->b_count)));
> -	if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
> -	    HDR(bh)->h_blocks != cpu_to_le32(1)) {
> +	if (!ext2_xattr_header_valid(HDR(bh))) {
> 		ext2_error(inode->i_sb, "ext2_xattr_delete_inode",
> 			"inode %ld: bad block %d", inode->i_ino,
> 			EXT2_I(inode)->i_file_acl);
> --
> 2.17.2
> 
> 


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

  parent reply	other threads:[~2019-05-14 15:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-13 22:40 [PATCH v2 1/2] ext2: introduce helper for xattr header validation Chengguang Xu
2019-05-13 22:40 ` [PATCH v2 2/2] ext2: introduce helper for xattr entry validation Chengguang Xu
2019-05-14 15:32   ` Andreas Dilger
2019-05-14 15:37     ` Alexey Lyashkov
2019-05-15 13:58   ` Jan Kara
2019-05-14 15:32 ` Andreas Dilger [this message]
2019-05-15 10:55   ` [PATCH v2 1/2] ext2: introduce helper for xattr header validation Jan Kara

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=3F06FAEE-E534-42A0-A927-A07259070D6A@dilger.ca \
    --to=adilger@dilger.ca \
    --cc=cgxu519@zoho.com.cn \
    --cc=jack@suse.com \
    --cc=linux-ext4@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.