aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/f2fs/xattr.c36
-rw-r--r--fs/f2fs/xattr.h2
2 files changed, 29 insertions, 9 deletions
diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c
index 848a785abe25..e791741d193b 100644
--- a/fs/f2fs/xattr.c
+++ b/fs/f2fs/xattr.c
@@ -202,12 +202,17 @@ static inline const struct xattr_handler *f2fs_xattr_handler(int index)
202 return handler; 202 return handler;
203} 203}
204 204
205static struct f2fs_xattr_entry *__find_xattr(void *base_addr, int index, 205static struct f2fs_xattr_entry *__find_xattr(void *base_addr,
206 size_t len, const char *name) 206 void *last_base_addr, int index,
207 size_t len, const char *name)
207{ 208{
208 struct f2fs_xattr_entry *entry; 209 struct f2fs_xattr_entry *entry;
209 210
210 list_for_each_xattr(entry, base_addr) { 211 list_for_each_xattr(entry, base_addr) {
212 if ((void *)(entry) + sizeof(__u32) > last_base_addr ||
213 (void *)XATTR_NEXT_ENTRY(entry) > last_base_addr)
214 return NULL;
215
211 if (entry->e_name_index != index) 216 if (entry->e_name_index != index)
212 continue; 217 continue;
213 if (entry->e_name_len != len) 218 if (entry->e_name_len != len)
@@ -297,20 +302,22 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
297 const char *name, struct f2fs_xattr_entry **xe, 302 const char *name, struct f2fs_xattr_entry **xe,
298 void **base_addr, int *base_size) 303 void **base_addr, int *base_size)
299{ 304{
300 void *cur_addr, *txattr_addr, *last_addr = NULL; 305 void *cur_addr, *txattr_addr, *last_txattr_addr;
306 void *last_addr = NULL;
301 nid_t xnid = F2FS_I(inode)->i_xattr_nid; 307 nid_t xnid = F2FS_I(inode)->i_xattr_nid;
302 unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;
303 unsigned int inline_size = inline_xattr_size(inode); 308 unsigned int inline_size = inline_xattr_size(inode);
304 int err = 0; 309 int err = 0;
305 310
306 if (!size && !inline_size) 311 if (!xnid && !inline_size)
307 return -ENODATA; 312 return -ENODATA;
308 313
309 *base_size = inline_size + size + XATTR_PADDING_SIZE; 314 *base_size = XATTR_SIZE(xnid, inode) + XATTR_PADDING_SIZE;
310 txattr_addr = f2fs_kzalloc(F2FS_I_SB(inode), *base_size, GFP_NOFS); 315 txattr_addr = f2fs_kzalloc(F2FS_I_SB(inode), *base_size, GFP_NOFS);
311 if (!txattr_addr) 316 if (!txattr_addr)
312 return -ENOMEM; 317 return -ENOMEM;
313 318
319 last_txattr_addr = (void *)txattr_addr + XATTR_SIZE(xnid, inode);
320
314 /* read from inline xattr */ 321 /* read from inline xattr */
315 if (inline_size) { 322 if (inline_size) {
316 err = read_inline_xattr(inode, ipage, txattr_addr); 323 err = read_inline_xattr(inode, ipage, txattr_addr);
@@ -337,7 +344,11 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
337 else 344 else
338 cur_addr = txattr_addr; 345 cur_addr = txattr_addr;
339 346
340 *xe = __find_xattr(cur_addr, index, len, name); 347 *xe = __find_xattr(cur_addr, last_txattr_addr, index, len, name);
348 if (!*xe) {
349 err = -EFAULT;
350 goto out;
351 }
341check: 352check:
342 if (IS_XATTR_LAST_ENTRY(*xe)) { 353 if (IS_XATTR_LAST_ENTRY(*xe)) {
343 err = -ENODATA; 354 err = -ENODATA;
@@ -581,7 +592,8 @@ static int __f2fs_setxattr(struct inode *inode, int index,
581 struct page *ipage, int flags) 592 struct page *ipage, int flags)
582{ 593{
583 struct f2fs_xattr_entry *here, *last; 594 struct f2fs_xattr_entry *here, *last;
584 void *base_addr; 595 void *base_addr, *last_base_addr;
596 nid_t xnid = F2FS_I(inode)->i_xattr_nid;
585 int found, newsize; 597 int found, newsize;
586 size_t len; 598 size_t len;
587 __u32 new_hsize; 599 __u32 new_hsize;
@@ -605,8 +617,14 @@ static int __f2fs_setxattr(struct inode *inode, int index,
605 if (error) 617 if (error)
606 return error; 618 return error;
607 619
620 last_base_addr = (void *)base_addr + XATTR_SIZE(xnid, inode);
621
608 /* find entry with wanted name. */ 622 /* find entry with wanted name. */
609 here = __find_xattr(base_addr, index, len, name); 623 here = __find_xattr(base_addr, last_base_addr, index, len, name);
624 if (!here) {
625 error = -EFAULT;
626 goto exit;
627 }
610 628
611 found = IS_XATTR_LAST_ENTRY(here) ? 0 : 1; 629 found = IS_XATTR_LAST_ENTRY(here) ? 0 : 1;
612 630
diff --git a/fs/f2fs/xattr.h b/fs/f2fs/xattr.h
index 9172ee082ca8..a90920e2f949 100644
--- a/fs/f2fs/xattr.h
+++ b/fs/f2fs/xattr.h
@@ -71,6 +71,8 @@ struct f2fs_xattr_entry {
71 entry = XATTR_NEXT_ENTRY(entry)) 71 entry = XATTR_NEXT_ENTRY(entry))
72#define VALID_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer)) 72#define VALID_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer))
73#define XATTR_PADDING_SIZE (sizeof(__u32)) 73#define XATTR_PADDING_SIZE (sizeof(__u32))
74#define XATTR_SIZE(x,i) (((x) ? VALID_XATTR_BLOCK_SIZE : 0) + \
75 (inline_xattr_size(i)))
74#define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + \ 76#define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + \
75 VALID_XATTR_BLOCK_SIZE) 77 VALID_XATTR_BLOCK_SIZE)
76 78