xattr.c (47e4937a4a7ca4184fd282791dfee76c6799966a) xattr.c (8d8a09b093d7073465c824f74caf315c073d3875)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2017-2018 HUAWEI, Inc.
4 * http://www.huawei.com/
5 * Created by Gao Xiang <gaoxiang25@huawei.com>
6 */
7#include <linux/security.h>
8#include "xattr.h"

--- 5 unchanged lines hidden (view full) ---

14
15 erofs_blk_t blkaddr;
16 unsigned int ofs;
17};
18
19static inline void xattr_iter_end(struct xattr_iter *it, bool atomic)
20{
21 /* the only user of kunmap() is 'init_inode_xattrs' */
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2017-2018 HUAWEI, Inc.
4 * http://www.huawei.com/
5 * Created by Gao Xiang <gaoxiang25@huawei.com>
6 */
7#include <linux/security.h>
8#include "xattr.h"

--- 5 unchanged lines hidden (view full) ---

14
15 erofs_blk_t blkaddr;
16 unsigned int ofs;
17};
18
19static inline void xattr_iter_end(struct xattr_iter *it, bool atomic)
20{
21 /* the only user of kunmap() is 'init_inode_xattrs' */
22 if (unlikely(!atomic))
22 if (!atomic)
23 kunmap(it->page);
24 else
25 kunmap_atomic(it->kaddr);
26
27 unlock_page(it->page);
28 put_page(it->page);
29}
30

--- 36 unchanged lines hidden (view full) ---

67 * undefined right now (maybe use later with some new sb feature).
68 */
69 if (vi->xattr_isize == sizeof(struct erofs_xattr_ibody_header)) {
70 errln("xattr_isize %d of nid %llu is not supported yet",
71 vi->xattr_isize, vi->nid);
72 ret = -EOPNOTSUPP;
73 goto out_unlock;
74 } else if (vi->xattr_isize < sizeof(struct erofs_xattr_ibody_header)) {
23 kunmap(it->page);
24 else
25 kunmap_atomic(it->kaddr);
26
27 unlock_page(it->page);
28 put_page(it->page);
29}
30

--- 36 unchanged lines hidden (view full) ---

67 * undefined right now (maybe use later with some new sb feature).
68 */
69 if (vi->xattr_isize == sizeof(struct erofs_xattr_ibody_header)) {
70 errln("xattr_isize %d of nid %llu is not supported yet",
71 vi->xattr_isize, vi->nid);
72 ret = -EOPNOTSUPP;
73 goto out_unlock;
74 } else if (vi->xattr_isize < sizeof(struct erofs_xattr_ibody_header)) {
75 if (unlikely(vi->xattr_isize)) {
75 if (vi->xattr_isize) {
76 errln("bogus xattr ibody @ nid %llu", vi->nid);
77 DBG_BUGON(1);
78 ret = -EFSCORRUPTED;
79 goto out_unlock; /* xattr ondisk layout error */
80 }
81 ret = -ENOATTR;
82 goto out_unlock;
83 }

--- 23 unchanged lines hidden (view full) ---

107 ret = -ENOMEM;
108 goto out_unlock;
109 }
110
111 /* let's skip ibody header */
112 it.ofs += sizeof(struct erofs_xattr_ibody_header);
113
114 for (i = 0; i < vi->xattr_shared_count; ++i) {
76 errln("bogus xattr ibody @ nid %llu", vi->nid);
77 DBG_BUGON(1);
78 ret = -EFSCORRUPTED;
79 goto out_unlock; /* xattr ondisk layout error */
80 }
81 ret = -ENOATTR;
82 goto out_unlock;
83 }

--- 23 unchanged lines hidden (view full) ---

107 ret = -ENOMEM;
108 goto out_unlock;
109 }
110
111 /* let's skip ibody header */
112 it.ofs += sizeof(struct erofs_xattr_ibody_header);
113
114 for (i = 0; i < vi->xattr_shared_count; ++i) {
115 if (unlikely(it.ofs >= EROFS_BLKSIZ)) {
115 if (it.ofs >= EROFS_BLKSIZ) {
116 /* cannot be unaligned */
117 DBG_BUGON(it.ofs != EROFS_BLKSIZ);
118 xattr_iter_end(&it, atomic_map);
119
120 it.page = erofs_get_meta_page(sb, ++it.blkaddr,
121 S_ISDIR(inode->i_mode));
122 if (IS_ERR(it.page)) {
123 kfree(vi->xattr_shared_xattrs);

--- 60 unchanged lines hidden (view full) ---

184static int inline_xattr_iter_begin(struct xattr_iter *it,
185 struct inode *inode)
186{
187 struct erofs_vnode *const vi = EROFS_V(inode);
188 struct erofs_sb_info *const sbi = EROFS_SB(inode->i_sb);
189 unsigned int xattr_header_sz, inline_xattr_ofs;
190
191 xattr_header_sz = inlinexattr_header_size(inode);
116 /* cannot be unaligned */
117 DBG_BUGON(it.ofs != EROFS_BLKSIZ);
118 xattr_iter_end(&it, atomic_map);
119
120 it.page = erofs_get_meta_page(sb, ++it.blkaddr,
121 S_ISDIR(inode->i_mode));
122 if (IS_ERR(it.page)) {
123 kfree(vi->xattr_shared_xattrs);

--- 60 unchanged lines hidden (view full) ---

184static int inline_xattr_iter_begin(struct xattr_iter *it,
185 struct inode *inode)
186{
187 struct erofs_vnode *const vi = EROFS_V(inode);
188 struct erofs_sb_info *const sbi = EROFS_SB(inode->i_sb);
189 unsigned int xattr_header_sz, inline_xattr_ofs;
190
191 xattr_header_sz = inlinexattr_header_size(inode);
192 if (unlikely(xattr_header_sz >= vi->xattr_isize)) {
192 if (xattr_header_sz >= vi->xattr_isize) {
193 DBG_BUGON(xattr_header_sz > vi->xattr_isize);
194 return -ENOATTR;
195 }
196
197 inline_xattr_ofs = vi->inode_isize + xattr_header_sz;
198
199 it->blkaddr = erofs_blknr(iloc(sbi, vi->nid) + inline_xattr_ofs);
200 it->ofs = erofs_blkoff(iloc(sbi, vi->nid) + inline_xattr_ofs);

--- 28 unchanged lines hidden (view full) ---

229 * since we do EROFS_XATTR_ALIGN
230 * therefore entry should be in the page
231 */
232 entry = *(struct erofs_xattr_entry *)(it->kaddr + it->ofs);
233 if (tlimit) {
234 unsigned int entry_sz = EROFS_XATTR_ENTRY_SIZE(&entry);
235
236 /* xattr on-disk corruption: xattr entry beyond xattr_isize */
193 DBG_BUGON(xattr_header_sz > vi->xattr_isize);
194 return -ENOATTR;
195 }
196
197 inline_xattr_ofs = vi->inode_isize + xattr_header_sz;
198
199 it->blkaddr = erofs_blknr(iloc(sbi, vi->nid) + inline_xattr_ofs);
200 it->ofs = erofs_blkoff(iloc(sbi, vi->nid) + inline_xattr_ofs);

--- 28 unchanged lines hidden (view full) ---

229 * since we do EROFS_XATTR_ALIGN
230 * therefore entry should be in the page
231 */
232 entry = *(struct erofs_xattr_entry *)(it->kaddr + it->ofs);
233 if (tlimit) {
234 unsigned int entry_sz = EROFS_XATTR_ENTRY_SIZE(&entry);
235
236 /* xattr on-disk corruption: xattr entry beyond xattr_isize */
237 if (unlikely(*tlimit < entry_sz)) {
237 if (*tlimit < entry_sz) {
238 DBG_BUGON(1);
239 return -EFSCORRUPTED;
240 }
241 *tlimit -= entry_sz;
242 }
243
244 it->ofs += sizeof(struct erofs_xattr_entry);
245 value_sz = le16_to_cpu(entry.e_value_size);

--- 185 unchanged lines hidden (view full) ---

431
432int erofs_getxattr(struct inode *inode, int index,
433 const char *name,
434 void *buffer, size_t buffer_size)
435{
436 int ret;
437 struct getxattr_iter it;
438
238 DBG_BUGON(1);
239 return -EFSCORRUPTED;
240 }
241 *tlimit -= entry_sz;
242 }
243
244 it->ofs += sizeof(struct erofs_xattr_entry);
245 value_sz = le16_to_cpu(entry.e_value_size);

--- 185 unchanged lines hidden (view full) ---

431
432int erofs_getxattr(struct inode *inode, int index,
433 const char *name,
434 void *buffer, size_t buffer_size)
435{
436 int ret;
437 struct getxattr_iter it;
438
439 if (unlikely(!name))
439 if (!name)
440 return -EINVAL;
441
442 ret = init_inode_xattrs(inode);
443 if (ret)
444 return ret;
445
446 it.index = index;
447

--- 256 unchanged lines hidden ---
440 return -EINVAL;
441
442 ret = init_inode_xattrs(inode);
443 if (ret)
444 return ret;
445
446 it.index = index;
447

--- 256 unchanged lines hidden ---