lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <9B033593-E86D-4B86-97CB-6833BCC340AC@dilger.ca>
Date:   Fri, 10 May 2019 20:42:12 -0600
From:   Andreas Dilger <adilger@...ger.ca>
To:     Chengguang Xu <cgxu519@...il.com>
Cc:     jack@...e.com, linux-ext4@...r.kernel.org
Subject: Re: [PATCH 1/2] ext2: introduce helper for xattr header validation

It seems like this would be more useful if you passed it the header
like ext2_xattr_header_valid(HDR(bh)).

Cheers, Andreas

> On May 10, 2019, at 04:37, Chengguang Xu <cgxu519@...il.com> 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@...il.com>
> ---
> 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..6e0b2b0f333f 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 buffer_head *bh)
> +{
> +    if (HDR(bh)->h_magic != cpu_to_le32(EXT2_XATTR_MAGIC) ||
> +        HDR(bh)->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(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(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(bh)) {
> +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(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.20.1
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ