]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/f2fs-fix-to-adapt-small-inline-xattr-space-in-__find.patch
Linux 4.14.111
[thirdparty/kernel/stable-queue.git] / queue-4.19 / f2fs-fix-to-adapt-small-inline-xattr-space-in-__find.patch
1 From 0d596546dffb95665dd98256ec05eefb91bd2f51 Mon Sep 17 00:00:00 2001
2 From: Chao Yu <yuchao0@huawei.com>
3 Date: Tue, 5 Mar 2019 19:32:26 +0800
4 Subject: f2fs: fix to adapt small inline xattr space in __find_inline_xattr()
5
6 [ Upstream commit 2c28aba8b2e2a51749fa66e01b68e1cd5b53e022 ]
7
8 With below testcase, we will fail to find existed xattr entry:
9
10 1. mkfs.f2fs -O extra_attr -O flexible_inline_xattr /dev/zram0
11 2. mount -t f2fs -o inline_xattr_size=1 /dev/zram0 /mnt/f2fs/
12 3. touch /mnt/f2fs/file
13 4. setfattr -n "user.name" -v 0 /mnt/f2fs/file
14 5. getfattr -n "user.name" /mnt/f2fs/file
15
16 /mnt/f2fs/file: user.name: No such attribute
17
18 The reason is for inode which has very small inline xattr size,
19 __find_inline_xattr() will fail to traverse any entry due to first
20 entry may not be loaded from xattr node yet, later, we may skip to
21 check entire xattr datas in __find_xattr(), result in such wrong
22 condition.
23
24 This patch adds condition to check such case to avoid this issue.
25
26 Signed-off-by: Chao Yu <yuchao0@huawei.com>
27 Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
28 Signed-off-by: Sasha Levin <sashal@kernel.org>
29 ---
30 fs/f2fs/xattr.c | 13 ++++++++++---
31 1 file changed, 10 insertions(+), 3 deletions(-)
32
33 diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c
34 index 087e53a2d96c..409a637f7a92 100644
35 --- a/fs/f2fs/xattr.c
36 +++ b/fs/f2fs/xattr.c
37 @@ -227,11 +227,11 @@ static struct f2fs_xattr_entry *__find_inline_xattr(struct inode *inode,
38 {
39 struct f2fs_xattr_entry *entry;
40 unsigned int inline_size = inline_xattr_size(inode);
41 + void *max_addr = base_addr + inline_size;
42
43 list_for_each_xattr(entry, base_addr) {
44 - if ((void *)entry + sizeof(__u32) > base_addr + inline_size ||
45 - (void *)XATTR_NEXT_ENTRY(entry) + sizeof(__u32) >
46 - base_addr + inline_size) {
47 + if ((void *)entry + sizeof(__u32) > max_addr ||
48 + (void *)XATTR_NEXT_ENTRY(entry) > max_addr) {
49 *last_addr = entry;
50 return NULL;
51 }
52 @@ -242,6 +242,13 @@ static struct f2fs_xattr_entry *__find_inline_xattr(struct inode *inode,
53 if (!memcmp(entry->e_name, name, len))
54 break;
55 }
56 +
57 + /* inline xattr header or entry across max inline xattr size */
58 + if (IS_XATTR_LAST_ENTRY(entry) &&
59 + (void *)entry + sizeof(__u32) > max_addr) {
60 + *last_addr = entry;
61 + return NULL;
62 + }
63 return entry;
64 }
65
66 --
67 2.19.1
68