erofs-utils: mkfs: limit total shared xattrs of a single inode
authorGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 20 Sep 2023 19:02:20 +0000 (03:02 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 20 Sep 2023 19:05:34 +0000 (03:05 +0800)
Don't output more than 255 shared xattrs for a single inode due to the
EROFS on-disk format limitation.

Fixes: 116ac0a254fc ("erofs-utils: introduce shared xattr support")
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230920190220.1837650-1-hsiangkao@linux.alibaba.com
lib/xattr.c

index 790547c9ee9d2803d17977c137ca5fed4fcfbd8d..6c8ebf4a61816bc937b65e3a32346bdb41692db0 100644 (file)
@@ -665,6 +665,7 @@ int erofs_prepare_xattr_ibody(struct erofs_inode *inode)
        int ret;
        struct inode_xattr_node *node;
        struct list_head *ixattrs = &inode->i_xattrs;
+       unsigned int h_shared_count;
 
        if (list_empty(ixattrs)) {
                inode->xattr_isize = 0;
@@ -672,11 +673,13 @@ int erofs_prepare_xattr_ibody(struct erofs_inode *inode)
        }
 
        /* get xattr ibody size */
+       h_shared_count = 0;
        ret = sizeof(struct erofs_xattr_ibody_header);
        list_for_each_entry(node, ixattrs, list) {
                struct xattr_item *item = node->item;
 
-               if (item->shared_xattr_id >= 0) {
+               if (item->shared_xattr_id >= 0 && h_shared_count < UCHAR_MAX) {
+                       ++h_shared_count;
                        ret += sizeof(__le32);
                        continue;
                }
@@ -980,7 +983,8 @@ char *erofs_export_xattr_ibody(struct erofs_inode *inode)
                list_del(&node->list);
 
                /* move inline xattrs to the onstack list */
-               if (item->shared_xattr_id < 0) {
+               if (item->shared_xattr_id < 0 ||
+                   header->h_shared_count >= UCHAR_MAX) {
                        list_add(&node->list, &ilst);
                        continue;
                }