!58 Fix xattr max value len bug
Some checks failed
CI / build (android, clang, aarch64-linux-android32) (push) Has been cancelled
CI / build (linux-clang, clang) (push) Has been cancelled
CI / build (linux-gcc, gcc) (push) Has been cancelled
CI / build (linux-mingw64-gcc, gcc, -D__USE_MINGW_ANSI_STDIO, x86_64-w64-mingw32) (push) Has been cancelled
CI / build (linux-powerpc64-gcc, gcc, powerpc64-linux-gnu) (push) Has been cancelled
CI / build (macos, clang, macos-latest) (push) Has been cancelled
CI / build (x86, linux-x86-gcc, gcc) (push) Has been cancelled

Merge pull request !58 from nieben/xattr_max_value_len_bug
This commit is contained in:
openharmony_ci 2024-10-08 11:57:56 +00:00 committed by Gitee
commit 92cf264610
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 15 additions and 8 deletions

View File

@ -832,7 +832,7 @@ check_next:
le16_to_cpu(node_blk->i.i_inline_xattr_size);
if (!inline_size ||
inline_size > MAX_INLINE_XATTR_SIZE) {
inline_size > MAX_INLINE_XATTR_SIZE(&node_blk->i)) {
ASSERT_MSG("[0x%x] wrong inline_xattr_size:%u",
nid, inline_size);
if (c.fix_on) {

View File

@ -151,7 +151,7 @@ int f2fs_setxattr(struct f2fs_sb_info *sbi, nid_t ino, int index, const char *na
len = strlen(name);
if (len > F2FS_NAME_LEN || size > MAX_VALUE_LEN)
if (len > F2FS_NAME_LEN)
return -ERANGE;
if (ino < 3)
@ -166,6 +166,12 @@ int f2fs_setxattr(struct f2fs_sb_info *sbi, nid_t ino, int index, const char *na
ret = dev_read_block(inode, ni.blk_addr);
ASSERT(ret >= 0);
if (size > MAX_VALUE_LEN(&inode->i)) {
MSG(0, "Size %d exceeds max value len %d.\n", size, MAX_VALUE_LEN(&inode->i));
free(inode);
return -ERANGE;
}
base_addr = read_all_xattrs(sbi, inode);
ASSERT(base_addr);

View File

@ -135,13 +135,14 @@ static inline int f2fs_acl_count(int size)
#define MIN_OFFSET XATTR_ALIGN(F2FS_BLKSIZE - \
sizeof(struct node_footer) - sizeof(__u32))
#define MAX_VALUE_LEN (MIN_OFFSET - \
#define MAX_XATTR_BLOCK_SIZE (F2FS_BLKSIZE - sizeof(struct node_footer))
#define MAX_XATTR_SIZE(inode) (XATTR_ALIGN((MAX_INLINE_XATTR_SIZE(inode)) + \
(MAX_XATTR_BLOCK_SIZE)))
#define MAX_VALUE_LEN(inode) (MAX_XATTR_SIZE(inode) - \
sizeof(struct f2fs_xattr_header) - \
sizeof(struct f2fs_xattr_entry))
#define MAX_INLINE_XATTR_SIZE \
(DEF_ADDRS_PER_INODE - \
F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \
DEF_INLINE_RESERVED_SIZE - \
MIN_INLINE_DENTRY_SIZE / sizeof(__le32))
#define MAX_INLINE_XATTR_SIZE(inode) (inline_xattr_size(inode))
#endif