Skip to content
This repository was archived by the owner on Jul 16, 2020. It is now read-only.

Commit e8d470a

Browse files
chaseyuppajda
authored andcommitted
f2fs: fix to adapt small inline xattr space in __find_inline_xattr()
With below testcase, we will fail to find existed xattr entry: 1. mkfs.f2fs -O extra_attr -O flexible_inline_xattr /dev/zram0 2. mount -t f2fs -o inline_xattr_size=1 /dev/zram0 /mnt/f2fs/ 3. touch /mnt/f2fs/file 4. setfattr -n "user.name" -v 0 /mnt/f2fs/file 5. getfattr -n "user.name" /mnt/f2fs/file /mnt/f2fs/file: user.name: No such attribute The reason is for inode which has very small inline xattr size, __find_inline_xattr() will fail to traverse any entry due to first entry may not be loaded from xattr node yet, later, we may skip to check entire xattr datas in __find_xattr(), result in such wrong condition. This patch adds condition to check such case to avoid this issue. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 0a8a15f commit e8d470a

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

fs/f2fs/xattr.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,11 @@ static struct f2fs_xattr_entry *__find_inline_xattr(struct inode *inode,
272272
{
273273
struct f2fs_xattr_entry *entry;
274274
unsigned int inline_size = inline_xattr_size(inode);
275+
void *max_addr = base_addr + inline_size;
275276

276277
list_for_each_xattr(entry, base_addr) {
277-
if ((void *)entry + sizeof(__u32) > base_addr + inline_size ||
278-
(void *)XATTR_NEXT_ENTRY(entry) + sizeof(__u32) >
279-
base_addr + inline_size) {
278+
if ((void *)entry + sizeof(__u32) > max_addr ||
279+
(void *)XATTR_NEXT_ENTRY(entry) > max_addr) {
280280
*last_addr = entry;
281281
return NULL;
282282
}
@@ -287,6 +287,13 @@ static struct f2fs_xattr_entry *__find_inline_xattr(struct inode *inode,
287287
if (!memcmp(entry->e_name, name, len))
288288
break;
289289
}
290+
291+
/* inline xattr header or entry across max inline xattr size */
292+
if (IS_XATTR_LAST_ENTRY(entry) &&
293+
(void *)entry + sizeof(__u32) > max_addr) {
294+
*last_addr = entry;
295+
return NULL;
296+
}
290297
return entry;
291298
}
292299

0 commit comments

Comments
 (0)