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 2/2] ext2: introduce helper for xattr entry validation
Date: Tue, 14 May 2019 09:32:55 -0600	[thread overview]
Message-ID: <3D6EA2A3-CC61-4243-982F-E53305EA0231@dilger.ca> (raw)
In-Reply-To: <20190513224042.23377-2-cgxu519@zoho.com.cn>

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

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

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

> ---
> v1->v2:
> - Pass end offset instead of inode to ext2_xattr_entry_valid()
> - Change signed-off mail address.
> 
> fs/ext2/xattr.c | 21 +++++++++++++++++----
> 1 file changed, 17 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
> index db27260d6a5b..d11c83529514 100644
> --- a/fs/ext2/xattr.c
> +++ b/fs/ext2/xattr.c
> @@ -144,6 +144,20 @@ ext2_xattr_header_valid(struct ext2_xattr_header *header)
> 	return true;
> }
> 
> +static bool
> +ext2_xattr_entry_valid(struct ext2_xattr_entry *entry, size_t size,
> +		       size_t end_offs)
> +{
> +	if (entry->e_value_block != 0)
> +		return false;
> +
> +	if (size > end_offs ||
> +	    le16_to_cpu(entry->e_value_offs) + size > end_offs)
> +		return false;
> +
> +	return true;
> +}
> +
> /*
>  * ext2_xattr_get()
>  *
> @@ -217,8 +231,7 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
> 	if (entry->e_value_block != 0)
> 		goto bad_block;
> 	size = le32_to_cpu(entry->e_value_size);
> -	if (size > inode->i_sb->s_blocksize ||
> -	    le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
> +	if (!ext2_xattr_entry_valid(entry, size, inode->i_sb->s_blocksize))
> 		goto bad_block;
> 
> 	if (ext2_xattr_cache_insert(ea_block_cache, bh))
> @@ -483,8 +496,8 @@ ext2_xattr_set(struct inode *inode, int name_index, const char *name,
> 		if (!here->e_value_block && here->e_value_size) {
> 			size_t size = le32_to_cpu(here->e_value_size);
> 
> -			if (le16_to_cpu(here->e_value_offs) + size >
> -			    sb->s_blocksize || size > sb->s_blocksize)
> +			if (!ext2_xattr_entry_valid(here, size,
> +			    inode->i_sb->s_blocksize))
> 				goto bad_block;
> 			free += EXT2_XATTR_SIZE(size);
> 		}
> --
> 2.17.2
> 
> 


Cheers, Andreas






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

  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 [this message]
2019-05-14 15:37     ` Alexey Lyashkov
2019-05-15 13:58   ` Jan Kara
2019-05-14 15:32 ` [PATCH v2 1/2] ext2: introduce helper for xattr header validation Andreas Dilger
2019-05-15 10:55   ` 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=3D6EA2A3-CC61-4243-982F-E53305EA0231@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.