erofs: delimit inode_share cache key components
PATCH 1/1 erofs: delimit inode_share cache key components
From: Chengyu Zhu <[email protected]>
The selected fingerprint xattr is treated as opaque and accepts any positive length up to the filesystem block size. Appending the domain ID directly to such a value leaves no boundary between the two key components if a different fingerprint length is used.
Change the key encoding as follows:
fingerprint || domain_id -> domain_id || '\0' || fingerprint
Since a mount option string cannot contain NUL, this makes the in-memory tuple unambiguous without constraining fingerprint contents or changing the on-disk format.
--- fs/erofs/xattr.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/erofs/xattr.c +6 -3
@@ -621,6 +621,7 @@ int erofs_xattr_fill_inode_fingerprint(struct erofs_inode_fingerprint *fp,struct erofs_sb_info *sbi =EROFS_SB (inode->i_sb);struct erofs_xattr_prefix_item *prefix;const char *infix; +size_t domainlen;int valuelen, base_index;if (!test_opt (&sbi->opt,INODE_SHARE ))
@@ -633,17 +634,19 @@ int erofs_xattr_fill_inode_fingerprint(struct erofs_inode_fingerprint *fp, valuelen =erofs_getxattr (inode, base_index, infix,NULL ,0 );if (valuelen <=0 || valuelen > (1 << sbi->blkszbits))return -EFSCORRUPTED ; - fp->size = valuelen + (domain_id ?strlen (domain_id) :0 ); + domain_id = domain_id ?:"" ; + domainlen =strlen (domain_id); + fp->size = domainlen +1 + valuelen; fp->opaque =kmalloc (fp->size,GFP_KERNEL );if (!fp->opaque)return -ENOMEM ; +memcpy (fp->opaque, domain_id, domainlen +1 );if (valuelen !=erofs_getxattr (inode, base_index, infix, - fp->opaque, valuelen)) { + fp->opaque + domainlen +1 , valuelen)) {kfree (fp->opaque); fp->opaque =NULL ;return -EFSCORRUPTED ; } -memcpy (fp->opaque + valuelen, domain_id, fp->size - valuelen); return 0; }#endif
Signature · 1 line
2.51.0
Gao Xiang
maintainerHi Chengyu,
Quoted 9 lines · On Mon, Sep 07, 2026 at 03:24:40PM +0800, ChengyuZhu6 wrote:
From: Chengyu Zhu <[email protected]>
The selected fingerprint xattr is treated as opaque and accepts any positive length up to the filesystem block size. Appending the domain ID directly to such a value leaves no boundary between the two key components if a different fingerprint length is used.
Change the key encoding as follows:
Quoted 7 lines
fingerprint || domain_id -> domain_id || '\0' || fingerprintSince a mount option string cannot contain NUL, this makes the in-memory tuple unambiguous without constraining fingerprint contents or changing the on-disk format.
Signed-off-by Chengyu Zhu <[email protected]>
Subject: erofs: delimit inode_share key components
Previously, inode_share keys are encoded as follows:
fingerprint || domain_id
It would be better to have a separator between fingerprint and domain_id so that fingerprint won't be parsed as part of a domain_id.
Change the key encoding as follows:
domain_id || '\0' || fingerprint
Since domain_id is a NIL-terminated string, this makes the in-memory key indices unambiguous.
Quoted 27 lines
--- fs/erofs/xattr.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)fs/erofs/xattr.c +4
-1@@ -621,6 +621,7 @@ int erofs_xattr_fill_inode_fingerprint(struct erofs_inode_fingerprint *fp,struct erofs_sb_info *sbi =EROFS_SB (inode->i_sb);struct erofs_xattr_prefix_item *prefix;const char *infix; +size_t domainlen;int valuelen, base_index;if (!test_opt (&sbi->opt,INODE_SHARE ))@@ -633,17 +634,19 @@ int erofs_xattr_fill_inode_fingerprint(struct erofs_inode_fingerprint *fp, valuelen =erofs_getxattr (inode, base_index, infix,NULL ,0 );if (valuelen <=0 || valuelen > (1 << sbi->blkszbits))return -EFSCORRUPTED ; - fp->size = valuelen + (domain_id ?strlen (domain_id) :0 ); + domain_id = domain_id ?:"" ; + domainlen =strlen (domain_id); + fp->size = domainlen +1 + valuelen; fp->opaque =kmalloc (fp->size,GFP_KERNEL );if (!fp->opaque)return -ENOMEM ;
fs/erofs/xattr.c int erofs_xattr_fill_inode_fingerprint(struct erofs_inode_fingerprint *fp, · line 650
Quoted 10 lines
fs/erofs/xattr.c +2
-2+memcpy (fp->opaque, domain_id, domainlen +1 );if (valuelen !=erofs_getxattr (inode, base_index, infix, - fp->opaque, valuelen)) { + fp->opaque + domainlen +1 , valuelen)) {kfree (fp->opaque); fp->opaque =NULL ;return -EFSCORRUPTED ; } -memcpy (fp->opaque + valuelen, domain_id, fp->size - valuelen);return 0 ;
Can you apply the following diff? domain_id cannot be NULL so it was a redundant check:
fs/erofs/xattr.c +1 -3
@@ -620,9 +620,8 @@ int erofs_xattr_fill_inode_fingerprint(struct erofs_inode_fingerprint *fp, {struct erofs_sb_info *sbi =EROFS_SB (inode->i_sb);struct erofs_xattr_prefix_item *prefix; +int domainlen, valuelen, base_index;const char *infix; -size_t domainlen; -int valuelen, base_index;if (!test_opt (&sbi->opt,INODE_SHARE ))return -EOPNOTSUPP ;
@@ -634,7 +633,6 @@ int erofs_xattr_fill_inode_fingerprint(struct erofs_inode_fingerprint *fp, valuelen =erofs_getxattr (inode, base_index, infix,NULL ,0 );if (valuelen <=0 || valuelen > (1 << sbi->blkszbits))return -EFSCORRUPTED ; - domain_id = domain_id ?:"" ; domainlen =strlen (domain_id); fp->size = domainlen +1 + valuelen; fp->opaque =kmalloc (fp->size,GFP_KERNEL );
Quoted 4 lines
fs/erofs/xattr.c +0
-0}#endif Signature · 1 line
2.51.0
PATCH v2 1/1 erofs: delimit inode_share cache key components
In reply to ChengyuZhu6From: Chengyu Zhu <[email protected]>
Previously, inode_share keys were encoded as follows:
fingerprint || domain_id
It would be better to have a separator between the fingerprint and domain ID so that the fingerprint won't be parsed as part of a domain ID.
Change the key encoding as follows:
domain_id || '\0' || fingerprint
Since domain_id is a NUL-terminated string, this makes the in-memory key indices unambiguous.
---
Changes since v1:
- Use int for domainlen and drop the redundant NULL domain_id handling.
fs/erofs/xattr.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/erofs/xattr.c +5 -4
@@ -620,7 +620,7 @@ int erofs_xattr_fill_inode_fingerprint(struct erofs_inode_fingerprint *fp, {struct erofs_sb_info *sbi =EROFS_SB (inode->i_sb);struct erofs_xattr_prefix_item *prefix; +int domainlen, valuelen, base_index;const char *infix; -int valuelen, base_index;if (!test_opt (&sbi->opt,INODE_SHARE ))
@@ -633,17 +633,18 @@ int erofs_xattr_fill_inode_fingerprint(struct erofs_inode_fingerprint *fp, valuelen =erofs_getxattr (inode, base_index, infix,NULL ,0 );if (valuelen <=0 || valuelen > (1 << sbi->blkszbits))return -EFSCORRUPTED ; - fp->size = valuelen + (domain_id ?strlen (domain_id) :0 ); + domainlen =strlen (domain_id); + fp->size = domainlen +1 + valuelen; fp->opaque =kmalloc (fp->size,GFP_KERNEL );if (!fp->opaque)return -ENOMEM ; +memcpy (fp->opaque, domain_id, domainlen +1 );if (valuelen !=erofs_getxattr (inode, base_index, infix, - fp->opaque, valuelen)) { + fp->opaque + domainlen +1 , valuelen)) {kfree (fp->opaque); fp->opaque =NULL ;return -EFSCORRUPTED ; } -memcpy (fp->opaque + valuelen, domain_id, fp->size - valuelen); return 0; }#endif
Signature · 1 line
2.51.0
Quoted 9 lines · On Mon, Sep 07, 2026 at 04:33:19PM +0800, ChengyuZhu6 wrote:
From: Chengyu Zhu <[email protected]>
Previously,
inode_sharekeys were encoded as follows:fingerprint || domain_idIt would be better to have a separator between the fingerprint and domain ID so that the fingerprint won't be parsed as part of a domain ID.
Quoted 8 lines
Change the key encoding as follows:
domain_id || '\0' || fingerprintSince
domain_idis a NUL-terminated string, this makes the in-memory key indices unambiguous.Signed-off-by Chengyu Zhu <[email protected]>
Thanks,
Gao Xiang