From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: Jingbo Xu <jefflexu@linux.alibaba.com>,
xiang@kernel.org, chao@kernel.org, huyue2@coolpad.com,
linux-erofs@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 6/7] erofs: handle long xattr name prefixes properly
Date: Tue, 11 Apr 2023 17:40:15 +0800 [thread overview]
Message-ID: <b47b01fd-feb8-5715-ce9b-dfe1d2a019b6@linux.alibaba.com> (raw)
In-Reply-To: <20230411093537.127286-1-jefflexu@linux.alibaba.com>
On 2023/4/11 17:35, Jingbo Xu wrote:
> Make .{list,get}xattr routines adapted to long xattr name prefixes.
> When the bit 7 of erofs_xattr_entry.e_name_index is set, it indicates
> that it refers to a long xattr name prefix.
>
> Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
> ---
> v3: introduce infix_len to struct getxattr_iter, and refactor the
> implementation of xattr_entrymatch(), erofs_xattr_long_entrymatch(), and
> xattr_namematch() accordingly.
>
> The erofs_xattr_long_entrymatch() of v2 version will advance
> it->name.name pointer by pf->infix_len prematurely, as the following
> xattr_namematch() may fail (-ENOATTR) since mismatching. And then
> it->name.name will be compared with the next xattr entry, while
> it->name.name has been mistakenly modified in the previous round. This
> will cause -ENOATTR error on the existing xattr.
Yes, please also help add a new erofs-utils testcase for this.
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Thanks,
Gao Xiang
>
> ---
> fs/erofs/xattr.c | 68 +++++++++++++++++++++++++++++++++++++++---------
> 1 file changed, 56 insertions(+), 12 deletions(-)
>
> diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c
> index 684571e83a2c..a04724c816e5 100644
> --- a/fs/erofs/xattr.c
> +++ b/fs/erofs/xattr.c
> @@ -297,17 +297,45 @@ struct getxattr_iter {
> struct xattr_iter it;
>
> char *buffer;
> - int buffer_size, index;
> + int buffer_size, index, infix_len;
> struct qstr name;
> };
>
> +static int erofs_xattr_long_entrymatch(struct getxattr_iter *it,
> + struct erofs_xattr_entry *entry)
> +{
> + struct erofs_sb_info *sbi = EROFS_SB(it->it.sb);
> + struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes +
> + (entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK);
> +
> + if (pf >= sbi->xattr_prefixes + sbi->xattr_prefix_count)
> + return -ENOATTR;
> +
> + if (it->index != pf->prefix->base_index ||
> + it->name.len != entry->e_name_len + pf->infix_len)
> + return -ENOATTR;
> +
> + if (memcmp(it->name.name, pf->prefix->infix, pf->infix_len))
> + return -ENOATTR;
> +
> + it->infix_len = pf->infix_len;
> + return 0;
> +}
> +
> static int xattr_entrymatch(struct xattr_iter *_it,
> struct erofs_xattr_entry *entry)
> {
> struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it);
>
> - return (it->index != entry->e_name_index ||
> - it->name.len != entry->e_name_len) ? -ENOATTR : 0;
> + /* should also match the infix for long name prefixes */
> + if (entry->e_name_index & EROFS_XATTR_LONG_PREFIX)
> + return erofs_xattr_long_entrymatch(it, entry);
> +
> + if (it->index != entry->e_name_index ||
> + it->name.len != entry->e_name_len)
> + return -ENOATTR;
> + it->infix_len = 0;
> + return 0;
> }
>
> static int xattr_namematch(struct xattr_iter *_it,
> @@ -315,7 +343,9 @@ static int xattr_namematch(struct xattr_iter *_it,
> {
> struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it);
>
> - return memcmp(buf, it->name.name + processed, len) ? -ENOATTR : 0;
> + if (memcmp(buf, it->name.name + it->infix_len + processed, len))
> + return -ENOATTR;
> + return 0;
> }
>
> static int xattr_checkbuffer(struct xattr_iter *_it,
> @@ -487,12 +517,24 @@ static int xattr_entrylist(struct xattr_iter *_it,
> {
> struct listxattr_iter *it =
> container_of(_it, struct listxattr_iter, it);
> - unsigned int prefix_len;
> - const char *prefix;
> -
> - const struct xattr_handler *h =
> - erofs_xattr_handler(entry->e_name_index);
> + unsigned int base_index = entry->e_name_index;
> + unsigned int prefix_len, infix_len = 0;
> + const char *prefix, *infix = NULL;
> + const struct xattr_handler *h;
> +
> + if (entry->e_name_index & EROFS_XATTR_LONG_PREFIX) {
> + struct erofs_sb_info *sbi = EROFS_SB(_it->sb);
> + struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes +
> + (entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK);
> +
> + if (pf >= sbi->xattr_prefixes + sbi->xattr_prefix_count)
> + return 1;
> + infix = pf->prefix->infix;
> + infix_len = pf->infix_len;
> + base_index = pf->prefix->base_index;
> + }
>
> + h = erofs_xattr_handler(base_index);
> if (!h || (h->list && !h->list(it->dentry)))
> return 1;
>
> @@ -500,16 +542,18 @@ static int xattr_entrylist(struct xattr_iter *_it,
> prefix_len = strlen(prefix);
>
> if (!it->buffer) {
> - it->buffer_ofs += prefix_len + entry->e_name_len + 1;
> + it->buffer_ofs += prefix_len + infix_len +
> + entry->e_name_len + 1;
> return 1;
> }
>
> - if (it->buffer_ofs + prefix_len
> + if (it->buffer_ofs + prefix_len + infix_len +
> + entry->e_name_len + 1 > it->buffer_size)
> return -ERANGE;
>
> memcpy(it->buffer + it->buffer_ofs, prefix, prefix_len);
> - it->buffer_ofs += prefix_len;
> + memcpy(it->buffer + it->buffer_ofs + prefix_len, infix, infix_len);
> + it->buffer_ofs += prefix_len + infix_len;
> return 0;
> }
>
next prev parent reply other threads:[~2023-04-11 9:40 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-07 14:17 [PATCH 0/7] erofs: introduce long xattr name prefixes feature Jingbo Xu
2023-04-07 14:17 ` [PATCH 1/7] erofs: keep meta inode into erofs_buf Jingbo Xu
2023-04-07 14:17 ` [PATCH 2/7] erofs: initialize packed inode after root inode is assigned Jingbo Xu
2023-04-09 10:52 ` Gao Xiang
2023-04-10 2:44 ` Yue Hu
2023-04-07 14:17 ` [PATCH 3/7] erofs: move packed inode out of the compression part Jingbo Xu
2023-04-09 10:53 ` Gao Xiang
2023-04-10 2:45 ` Yue Hu
2023-04-07 14:17 ` [PATCH 4/7] erofs: introduce on-disk format for long xattr name prefixes Jingbo Xu
2023-04-10 5:24 ` Gao Xiang
2023-04-07 14:17 ` [PATCH 5/7] erofs: add helpers to load " Jingbo Xu
2023-04-10 5:44 ` Gao Xiang
2023-04-07 14:17 ` [PATCH 6/7] erofs: handle long xattr name prefixes properly Jingbo Xu
2023-04-10 5:53 ` Gao Xiang
2023-04-10 6:39 ` [PATCH v2 " Jingbo Xu
2023-04-10 6:47 ` Gao Xiang
2023-04-11 9:35 ` [PATCH v3 " Jingbo Xu
2023-04-11 9:40 ` Gao Xiang [this message]
2023-04-07 14:17 ` [PATCH 7/7] erofs: enable long extended attribute name prefixes Jingbo Xu
2023-04-07 17:29 ` kernel test robot
2023-04-07 18:22 ` kernel test robot
2023-04-07 22:28 ` [PATCH v2 " Jingbo Xu
2023-04-10 5:54 ` Gao Xiang
2023-04-16 14:24 ` [PATCH 0/7] erofs: introduce long xattr name prefixes feature Chao Yu
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=b47b01fd-feb8-5715-ce9b-dfe1d2a019b6@linux.alibaba.com \
--to=hsiangkao@linux.alibaba.com \
--cc=chao@kernel.org \
--cc=huyue2@coolpad.com \
--cc=jefflexu@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xiang@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®