Skip to content

Commit 82bc1ef

Browse files
lostjefflehsiangkao
authored andcommitted
erofs: handle long xattr name prefixes properly
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> Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com> Acked-by: Chao Yu <chao@kernel.org> Link: https://lore.kernel.org/r/20230411093537.127286-1-jefflexu@linux.alibaba.com Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
1 parent 9e38291 commit 82bc1ef

1 file changed

Lines changed: 56 additions & 12 deletions

File tree

fs/erofs/xattr.c

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -297,25 +297,55 @@ struct getxattr_iter {
297297
struct xattr_iter it;
298298

299299
char *buffer;
300-
int buffer_size, index;
300+
int buffer_size, index, infix_len;
301301
struct qstr name;
302302
};
303303

304+
static int erofs_xattr_long_entrymatch(struct getxattr_iter *it,
305+
struct erofs_xattr_entry *entry)
306+
{
307+
struct erofs_sb_info *sbi = EROFS_SB(it->it.sb);
308+
struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes +
309+
(entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK);
310+
311+
if (pf >= sbi->xattr_prefixes + sbi->xattr_prefix_count)
312+
return -ENOATTR;
313+
314+
if (it->index != pf->prefix->base_index ||
315+
it->name.len != entry->e_name_len + pf->infix_len)
316+
return -ENOATTR;
317+
318+
if (memcmp(it->name.name, pf->prefix->infix, pf->infix_len))
319+
return -ENOATTR;
320+
321+
it->infix_len = pf->infix_len;
322+
return 0;
323+
}
324+
304325
static int xattr_entrymatch(struct xattr_iter *_it,
305326
struct erofs_xattr_entry *entry)
306327
{
307328
struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it);
308329

309-
return (it->index != entry->e_name_index ||
310-
it->name.len != entry->e_name_len) ? -ENOATTR : 0;
330+
/* should also match the infix for long name prefixes */
331+
if (entry->e_name_index & EROFS_XATTR_LONG_PREFIX)
332+
return erofs_xattr_long_entrymatch(it, entry);
333+
334+
if (it->index != entry->e_name_index ||
335+
it->name.len != entry->e_name_len)
336+
return -ENOATTR;
337+
it->infix_len = 0;
338+
return 0;
311339
}
312340

313341
static int xattr_namematch(struct xattr_iter *_it,
314342
unsigned int processed, char *buf, unsigned int len)
315343
{
316344
struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it);
317345

318-
return memcmp(buf, it->name.name + processed, len) ? -ENOATTR : 0;
346+
if (memcmp(buf, it->name.name + it->infix_len + processed, len))
347+
return -ENOATTR;
348+
return 0;
319349
}
320350

321351
static int xattr_checkbuffer(struct xattr_iter *_it,
@@ -487,29 +517,43 @@ static int xattr_entrylist(struct xattr_iter *_it,
487517
{
488518
struct listxattr_iter *it =
489519
container_of(_it, struct listxattr_iter, it);
490-
unsigned int prefix_len;
491-
const char *prefix;
492-
493-
const struct xattr_handler *h =
494-
erofs_xattr_handler(entry->e_name_index);
520+
unsigned int base_index = entry->e_name_index;
521+
unsigned int prefix_len, infix_len = 0;
522+
const char *prefix, *infix = NULL;
523+
const struct xattr_handler *h;
524+
525+
if (entry->e_name_index & EROFS_XATTR_LONG_PREFIX) {
526+
struct erofs_sb_info *sbi = EROFS_SB(_it->sb);
527+
struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes +
528+
(entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK);
529+
530+
if (pf >= sbi->xattr_prefixes + sbi->xattr_prefix_count)
531+
return 1;
532+
infix = pf->prefix->infix;
533+
infix_len = pf->infix_len;
534+
base_index = pf->prefix->base_index;
535+
}
495536

537+
h = erofs_xattr_handler(base_index);
496538
if (!h || (h->list && !h->list(it->dentry)))
497539
return 1;
498540

499541
prefix = xattr_prefix(h);
500542
prefix_len = strlen(prefix);
501543

502544
if (!it->buffer) {
503-
it->buffer_ofs += prefix_len + entry->e_name_len + 1;
545+
it->buffer_ofs += prefix_len + infix_len +
546+
entry->e_name_len + 1;
504547
return 1;
505548
}
506549

507-
if (it->buffer_ofs + prefix_len
550+
if (it->buffer_ofs + prefix_len + infix_len +
508551
+ entry->e_name_len + 1 > it->buffer_size)
509552
return -ERANGE;
510553

511554
memcpy(it->buffer + it->buffer_ofs, prefix, prefix_len);
512-
it->buffer_ofs += prefix_len;
555+
memcpy(it->buffer + it->buffer_ofs + prefix_len, infix, infix_len);
556+
it->buffer_ofs += prefix_len + infix_len;
513557
return 0;
514558
}
515559

0 commit comments

Comments
 (0)