xattr.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. /*
  2. File: fs/xattr.c
  3. Extended attribute handling.
  4. Copyright (C) 2001 by Andreas Gruenbacher <a.gruenbacher@computer.org>
  5. Copyright (C) 2001 SGI - Silicon Graphics, Inc <linux-xfs@oss.sgi.com>
  6. Copyright (c) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com>
  7. */
  8. #include <linux/fs.h>
  9. #include <linux/slab.h>
  10. #include <linux/file.h>
  11. #include <linux/xattr.h>
  12. #include <linux/mount.h>
  13. #include <linux/namei.h>
  14. #include <linux/security.h>
  15. #include <linux/evm.h>
  16. #include <linux/syscalls.h>
  17. #include <linux/export.h>
  18. #include <linux/fsnotify.h>
  19. #include <linux/audit.h>
  20. #include <asm/uaccess.h>
  21. /*
  22. * Check permissions for extended attribute access. This is a bit complicated
  23. * because different namespaces have very different rules.
  24. */
  25. static int
  26. xattr_permission(struct inode *inode, const char *name, int mask)
  27. {
  28. /*
  29. * We can never set or remove an extended attribute on a read-only
  30. * filesystem or on an immutable / append-only inode.
  31. */
  32. if (mask & MAY_WRITE) {
  33. if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
  34. return -EPERM;
  35. }
  36. /*
  37. * No restriction for security.* and system.* from the VFS. Decision
  38. * on these is left to the underlying filesystem / security module.
  39. */
  40. if (!strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) ||
  41. !strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
  42. return 0;
  43. /*
  44. * The trusted.* namespace can only be accessed by privileged users.
  45. */
  46. if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
  47. if (!capable(CAP_SYS_ADMIN))
  48. return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
  49. return 0;
  50. }
  51. /*
  52. * In the user.* namespace, only regular files and directories can have
  53. * extended attributes. For sticky directories, only the owner and
  54. * privileged users can write attributes.
  55. */
  56. if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
  57. if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode))
  58. return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
  59. if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) &&
  60. (mask & MAY_WRITE) && !inode_owner_or_capable(inode))
  61. return -EPERM;
  62. }
  63. return inode_permission(inode, mask);
  64. }
  65. /**
  66. * __vfs_setxattr_noperm - perform setxattr operation without performing
  67. * permission checks.
  68. *
  69. * @dentry - object to perform setxattr on
  70. * @name - xattr name to set
  71. * @value - value to set @name to
  72. * @size - size of @value
  73. * @flags - flags to pass into filesystem operations
  74. *
  75. * returns the result of the internal setxattr or setsecurity operations.
  76. *
  77. * This function requires the caller to lock the inode's i_mutex before it
  78. * is executed. It also assumes that the caller will make the appropriate
  79. * permission checks.
  80. */
  81. int __vfs_setxattr_noperm(struct dentry *dentry, const char *name,
  82. const void *value, size_t size, int flags)
  83. {
  84. struct inode *inode = dentry->d_inode;
  85. int error = -EOPNOTSUPP;
  86. int issec = !strncmp(name, XATTR_SECURITY_PREFIX,
  87. XATTR_SECURITY_PREFIX_LEN);
  88. if (issec)
  89. inode->i_flags &= ~S_NOSEC;
  90. if (inode->i_op->setxattr) {
  91. error = inode->i_op->setxattr(dentry, name, value, size, flags);
  92. if (!error) {
  93. fsnotify_xattr(dentry);
  94. security_inode_post_setxattr(dentry, name, value,
  95. size, flags);
  96. }
  97. } else if (issec) {
  98. const char *suffix = name + XATTR_SECURITY_PREFIX_LEN;
  99. error = security_inode_setsecurity(inode, suffix, value,
  100. size, flags);
  101. if (!error)
  102. fsnotify_xattr(dentry);
  103. }
  104. return error;
  105. }
  106. int
  107. vfs_setxattr(struct dentry *dentry, const char *name, const void *value,
  108. size_t size, int flags)
  109. {
  110. struct inode *inode = dentry->d_inode;
  111. int error;
  112. error = xattr_permission(inode, name, MAY_WRITE);
  113. if (error)
  114. return error;
  115. mutex_lock(&inode->i_mutex);
  116. error = security_inode_setxattr(dentry, name, value, size, flags);
  117. if (error)
  118. goto out;
  119. error = __vfs_setxattr_noperm(dentry, name, value, size, flags);
  120. out:
  121. mutex_unlock(&inode->i_mutex);
  122. return error;
  123. }
  124. EXPORT_SYMBOL_GPL(vfs_setxattr);
  125. ssize_t
  126. xattr_getsecurity(struct inode *inode, const char *name, void *value,
  127. size_t size)
  128. {
  129. void *buffer = NULL;
  130. ssize_t len;
  131. if (!value || !size) {
  132. len = security_inode_getsecurity(inode, name, &buffer, false);
  133. goto out_noalloc;
  134. }
  135. len = security_inode_getsecurity(inode, name, &buffer, true);
  136. if (len < 0)
  137. return len;
  138. if (size < len) {
  139. len = -ERANGE;
  140. goto out;
  141. }
  142. memcpy(value, buffer, len);
  143. out:
  144. security_release_secctx(buffer, len);
  145. out_noalloc:
  146. return len;
  147. }
  148. EXPORT_SYMBOL_GPL(xattr_getsecurity);
  149. /*
  150. * vfs_getxattr_alloc - allocate memory, if necessary, before calling getxattr
  151. *
  152. * Allocate memory, if not already allocated, or re-allocate correct size,
  153. * before retrieving the extended attribute.
  154. *
  155. * Returns the result of alloc, if failed, or the getxattr operation.
  156. */
  157. ssize_t
  158. vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
  159. size_t xattr_size, gfp_t flags)
  160. {
  161. struct inode *inode = dentry->d_inode;
  162. char *value = *xattr_value;
  163. int error;
  164. error = xattr_permission(inode, name, MAY_READ);
  165. if (error)
  166. return error;
  167. if (!inode->i_op->getxattr)
  168. return -EOPNOTSUPP;
  169. error = inode->i_op->getxattr(dentry, name, NULL, 0);
  170. if (error < 0)
  171. return error;
  172. if (!value || (error > xattr_size)) {
  173. value = krealloc(*xattr_value, error + 1, flags);
  174. if (!value)
  175. return -ENOMEM;
  176. memset(value, 0, error + 1);
  177. }
  178. error = inode->i_op->getxattr(dentry, name, value, error);
  179. *xattr_value = value;
  180. return error;
  181. }
  182. /* Compare an extended attribute value with the given value */
  183. int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
  184. const char *value, size_t size, gfp_t flags)
  185. {
  186. char *xattr_value = NULL;
  187. int rc;
  188. rc = vfs_getxattr_alloc(dentry, xattr_name, &xattr_value, 0, flags);
  189. if (rc < 0)
  190. return rc;
  191. if ((rc != size) || (memcmp(xattr_value, value, rc) != 0))
  192. rc = -EINVAL;
  193. else
  194. rc = 0;
  195. kfree(xattr_value);
  196. return rc;
  197. }
  198. ssize_t
  199. vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
  200. {
  201. struct inode *inode = dentry->d_inode;
  202. int error;
  203. error = xattr_permission(inode, name, MAY_READ);
  204. if (error)
  205. return error;
  206. error = security_inode_getxattr(dentry, name);
  207. if (error)
  208. return error;
  209. if (!strncmp(name, XATTR_SECURITY_PREFIX,
  210. XATTR_SECURITY_PREFIX_LEN)) {
  211. const char *suffix = name + XATTR_SECURITY_PREFIX_LEN;
  212. int ret = xattr_getsecurity(inode, suffix, value, size);
  213. /*
  214. * Only overwrite the return value if a security module
  215. * is actually active.
  216. */
  217. if (ret == -EOPNOTSUPP)
  218. goto nolsm;
  219. return ret;
  220. }
  221. nolsm:
  222. if (inode->i_op->getxattr)
  223. error = inode->i_op->getxattr(dentry, name, value, size);
  224. else
  225. error = -EOPNOTSUPP;
  226. return error;
  227. }
  228. EXPORT_SYMBOL_GPL(vfs_getxattr);
  229. ssize_t
  230. vfs_listxattr(struct dentry *d, char *list, size_t size)
  231. {
  232. ssize_t error;
  233. error = security_inode_listxattr(d);
  234. if (error)
  235. return error;
  236. error = -EOPNOTSUPP;
  237. if (d->d_inode->i_op->listxattr) {
  238. error = d->d_inode->i_op->listxattr(d, list, size);
  239. } else {
  240. error = security_inode_listsecurity(d->d_inode, list, size);
  241. if (size && error > size)
  242. error = -ERANGE;
  243. }
  244. return error;
  245. }
  246. EXPORT_SYMBOL_GPL(vfs_listxattr);
  247. int
  248. vfs_removexattr(struct dentry *dentry, const char *name)
  249. {
  250. struct inode *inode = dentry->d_inode;
  251. int error;
  252. if (!inode->i_op->removexattr)
  253. return -EOPNOTSUPP;
  254. error = xattr_permission(inode, name, MAY_WRITE);
  255. if (error)
  256. return error;
  257. error = security_inode_removexattr(dentry, name);
  258. if (error)
  259. return error;
  260. mutex_lock(&inode->i_mutex);
  261. error = inode->i_op->removexattr(dentry, name);
  262. mutex_unlock(&inode->i_mutex);
  263. if (!error) {
  264. fsnotify_xattr(dentry);
  265. evm_inode_post_removexattr(dentry, name);
  266. }
  267. return error;
  268. }
  269. EXPORT_SYMBOL_GPL(vfs_removexattr);
  270. /*
  271. * Extended attribute SET operations
  272. */
  273. static long
  274. setxattr(struct dentry *d, const char __user *name, const void __user *value,
  275. size_t size, int flags)
  276. {
  277. int error;
  278. void *kvalue = NULL;
  279. char kname[XATTR_NAME_MAX + 1];
  280. if (flags & ~(XATTR_CREATE|XATTR_REPLACE))
  281. return -EINVAL;
  282. error = strncpy_from_user(kname, name, sizeof(kname));
  283. if (error == 0 || error == sizeof(kname))
  284. error = -ERANGE;
  285. if (error < 0)
  286. return error;
  287. if (size) {
  288. if (size > XATTR_SIZE_MAX)
  289. return -E2BIG;
  290. kvalue = memdup_user(value, size);
  291. if (IS_ERR(kvalue))
  292. return PTR_ERR(kvalue);
  293. }
  294. error = vfs_setxattr(d, kname, kvalue, size, flags);
  295. kfree(kvalue);
  296. return error;
  297. }
  298. SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
  299. const char __user *, name, const void __user *, value,
  300. size_t, size, int, flags)
  301. {
  302. struct path path;
  303. int error;
  304. error = user_path(pathname, &path);
  305. if (error)
  306. return error;
  307. error = mnt_want_write(path.mnt);
  308. if (!error) {
  309. error = setxattr(path.dentry, name, value, size, flags);
  310. mnt_drop_write(path.mnt);
  311. }
  312. path_put(&path);
  313. return error;
  314. }
  315. SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
  316. const char __user *, name, const void __user *, value,
  317. size_t, size, int, flags)
  318. {
  319. struct path path;
  320. int error;
  321. error = user_lpath(pathname, &path);
  322. if (error)
  323. return error;
  324. error = mnt_want_write(path.mnt);
  325. if (!error) {
  326. error = setxattr(path.dentry, name, value, size, flags);
  327. mnt_drop_write(path.mnt);
  328. }
  329. path_put(&path);
  330. return error;
  331. }
  332. SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
  333. const void __user *,value, size_t, size, int, flags)
  334. {
  335. struct file *f;
  336. struct dentry *dentry;
  337. int error = -EBADF;
  338. f = fget(fd);
  339. if (!f)
  340. return error;
  341. dentry = f->f_path.dentry;
  342. audit_inode(NULL, dentry);
  343. error = mnt_want_write_file(f);
  344. if (!error) {
  345. error = setxattr(dentry, name, value, size, flags);
  346. mnt_drop_write_file(f);
  347. }
  348. fput(f);
  349. return error;
  350. }
  351. /*
  352. * Extended attribute GET operations
  353. */
  354. static ssize_t
  355. getxattr(struct dentry *d, const char __user *name, void __user *value,
  356. size_t size)
  357. {
  358. ssize_t error;
  359. void *kvalue = NULL;
  360. char kname[XATTR_NAME_MAX + 1];
  361. error = strncpy_from_user(kname, name, sizeof(kname));
  362. if (error == 0 || error == sizeof(kname))
  363. error = -ERANGE;
  364. if (error < 0)
  365. return error;
  366. if (size) {
  367. if (size > XATTR_SIZE_MAX)
  368. size = XATTR_SIZE_MAX;
  369. kvalue = kzalloc(size, GFP_KERNEL);
  370. if (!kvalue)
  371. return -ENOMEM;
  372. }
  373. error = vfs_getxattr(d, kname, kvalue, size);
  374. if (error > 0) {
  375. if (size && copy_to_user(value, kvalue, error))
  376. error = -EFAULT;
  377. } else if (error == -ERANGE && size >= XATTR_SIZE_MAX) {
  378. /* The file system tried to returned a value bigger
  379. than XATTR_SIZE_MAX bytes. Not possible. */
  380. error = -E2BIG;
  381. }
  382. kfree(kvalue);
  383. return error;
  384. }
  385. SYSCALL_DEFINE4(getxattr, const char __user *, pathname,
  386. const char __user *, name, void __user *, value, size_t, size)
  387. {
  388. struct path path;
  389. ssize_t error;
  390. error = user_path(pathname, &path);
  391. if (error)
  392. return error;
  393. error = getxattr(path.dentry, name, value, size);
  394. path_put(&path);
  395. return error;
  396. }
  397. SYSCALL_DEFINE4(lgetxattr, const char __user *, pathname,
  398. const char __user *, name, void __user *, value, size_t, size)
  399. {
  400. struct path path;
  401. ssize_t error;
  402. error = user_lpath(pathname, &path);
  403. if (error)
  404. return error;
  405. error = getxattr(path.dentry, name, value, size);
  406. path_put(&path);
  407. return error;
  408. }
  409. SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name,
  410. void __user *, value, size_t, size)
  411. {
  412. struct file *f;
  413. ssize_t error = -EBADF;
  414. f = fget(fd);
  415. if (!f)
  416. return error;
  417. audit_inode(NULL, f->f_path.dentry);
  418. error = getxattr(f->f_path.dentry, name, value, size);
  419. fput(f);
  420. return error;
  421. }
  422. /*
  423. * Extended attribute LIST operations
  424. */
  425. static ssize_t
  426. listxattr(struct dentry *d, char __user *list, size_t size)
  427. {
  428. ssize_t error;
  429. char *klist = NULL;
  430. if (size) {
  431. if (size > XATTR_LIST_MAX)
  432. size = XATTR_LIST_MAX;
  433. klist = kmalloc(size, GFP_KERNEL);
  434. if (!klist)
  435. return -ENOMEM;
  436. }
  437. error = vfs_listxattr(d, klist, size);
  438. if (error > 0) {
  439. if (size && copy_to_user(list, klist, error))
  440. error = -EFAULT;
  441. } else if (error == -ERANGE && size >= XATTR_LIST_MAX) {
  442. /* The file system tried to returned a list bigger
  443. than XATTR_LIST_MAX bytes. Not possible. */
  444. error = -E2BIG;
  445. }
  446. kfree(klist);
  447. return error;
  448. }
  449. SYSCALL_DEFINE3(listxattr, const char __user *, pathname, char __user *, list,
  450. size_t, size)
  451. {
  452. struct path path;
  453. ssize_t error;
  454. error = user_path(pathname, &path);
  455. if (error)
  456. return error;
  457. error = listxattr(path.dentry, list, size);
  458. path_put(&path);
  459. return error;
  460. }
  461. SYSCALL_DEFINE3(llistxattr, const char __user *, pathname, char __user *, list,
  462. size_t, size)
  463. {
  464. struct path path;
  465. ssize_t error;
  466. error = user_lpath(pathname, &path);
  467. if (error)
  468. return error;
  469. error = listxattr(path.dentry, list, size);
  470. path_put(&path);
  471. return error;
  472. }
  473. SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
  474. {
  475. struct file *f;
  476. ssize_t error = -EBADF;
  477. f = fget(fd);
  478. if (!f)
  479. return error;
  480. audit_inode(NULL, f->f_path.dentry);
  481. error = listxattr(f->f_path.dentry, list, size);
  482. fput(f);
  483. return error;
  484. }
  485. /*
  486. * Extended attribute REMOVE operations
  487. */
  488. static long
  489. removexattr(struct dentry *d, const char __user *name)
  490. {
  491. int error;
  492. char kname[XATTR_NAME_MAX + 1];
  493. error = strncpy_from_user(kname, name, sizeof(kname));
  494. if (error == 0 || error == sizeof(kname))
  495. error = -ERANGE;
  496. if (error < 0)
  497. return error;
  498. return vfs_removexattr(d, kname);
  499. }
  500. SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
  501. const char __user *, name)
  502. {
  503. struct path path;
  504. int error;
  505. error = user_path(pathname, &path);
  506. if (error)
  507. return error;
  508. error = mnt_want_write(path.mnt);
  509. if (!error) {
  510. error = removexattr(path.dentry, name);
  511. mnt_drop_write(path.mnt);
  512. }
  513. path_put(&path);
  514. return error;
  515. }
  516. SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
  517. const char __user *, name)
  518. {
  519. struct path path;
  520. int error;
  521. error = user_lpath(pathname, &path);
  522. if (error)
  523. return error;
  524. error = mnt_want_write(path.mnt);
  525. if (!error) {
  526. error = removexattr(path.dentry, name);
  527. mnt_drop_write(path.mnt);
  528. }
  529. path_put(&path);
  530. return error;
  531. }
  532. SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
  533. {
  534. struct file *f;
  535. struct dentry *dentry;
  536. int error = -EBADF;
  537. f = fget(fd);
  538. if (!f)
  539. return error;
  540. dentry = f->f_path.dentry;
  541. audit_inode(NULL, dentry);
  542. error = mnt_want_write_file(f);
  543. if (!error) {
  544. error = removexattr(dentry, name);
  545. mnt_drop_write_file(f);
  546. }
  547. fput(f);
  548. return error;
  549. }
  550. static const char *
  551. strcmp_prefix(const char *a, const char *a_prefix)
  552. {
  553. while (*a_prefix && *a == *a_prefix) {
  554. a++;
  555. a_prefix++;
  556. }
  557. return *a_prefix ? NULL : a;
  558. }
  559. /*
  560. * In order to implement different sets of xattr operations for each xattr
  561. * prefix with the generic xattr API, a filesystem should create a
  562. * null-terminated array of struct xattr_handler (one for each prefix) and
  563. * hang a pointer to it off of the s_xattr field of the superblock.
  564. *
  565. * The generic_fooxattr() functions will use this list to dispatch xattr
  566. * operations to the correct xattr_handler.
  567. */
  568. #define for_each_xattr_handler(handlers, handler) \
  569. for ((handler) = *(handlers)++; \
  570. (handler) != NULL; \
  571. (handler) = *(handlers)++)
  572. /*
  573. * Find the xattr_handler with the matching prefix.
  574. */
  575. static const struct xattr_handler *
  576. xattr_resolve_name(const struct xattr_handler **handlers, const char **name)
  577. {
  578. const struct xattr_handler *handler;
  579. if (!*name)
  580. return NULL;
  581. for_each_xattr_handler(handlers, handler) {
  582. const char *n = strcmp_prefix(*name, handler->prefix);
  583. if (n) {
  584. *name = n;
  585. break;
  586. }
  587. }
  588. return handler;
  589. }
  590. /*
  591. * Find the handler for the prefix and dispatch its get() operation.
  592. */
  593. ssize_t
  594. generic_getxattr(struct dentry *dentry, const char *name, void *buffer, size_t size)
  595. {
  596. const struct xattr_handler *handler;
  597. handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name);
  598. if (!handler)
  599. return -EOPNOTSUPP;
  600. return handler->get(dentry, name, buffer, size, handler->flags);
  601. }
  602. /*
  603. * Combine the results of the list() operation from every xattr_handler in the
  604. * list.
  605. */
  606. ssize_t
  607. generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
  608. {
  609. const struct xattr_handler *handler, **handlers = dentry->d_sb->s_xattr;
  610. unsigned int size = 0;
  611. if (!buffer) {
  612. for_each_xattr_handler(handlers, handler) {
  613. size += handler->list(dentry, NULL, 0, NULL, 0,
  614. handler->flags);
  615. }
  616. } else {
  617. char *buf = buffer;
  618. for_each_xattr_handler(handlers, handler) {
  619. size = handler->list(dentry, buf, buffer_size,
  620. NULL, 0, handler->flags);
  621. if (size > buffer_size)
  622. return -ERANGE;
  623. buf += size;
  624. buffer_size -= size;
  625. }
  626. size = buf - buffer;
  627. }
  628. return size;
  629. }
  630. /*
  631. * Find the handler for the prefix and dispatch its set() operation.
  632. */
  633. int
  634. generic_setxattr(struct dentry *dentry, const char *name, const void *value, size_t size, int flags)
  635. {
  636. const struct xattr_handler *handler;
  637. if (size == 0)
  638. value = ""; /* empty EA, do not remove */
  639. handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name);
  640. if (!handler)
  641. return -EOPNOTSUPP;
  642. return handler->set(dentry, name, value, size, flags, handler->flags);
  643. }
  644. /*
  645. * Find the handler for the prefix and dispatch its set() operation to remove
  646. * any associated extended attribute.
  647. */
  648. int
  649. generic_removexattr(struct dentry *dentry, const char *name)
  650. {
  651. const struct xattr_handler *handler;
  652. handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name);
  653. if (!handler)
  654. return -EOPNOTSUPP;
  655. return handler->set(dentry, name, NULL, 0,
  656. XATTR_REPLACE, handler->flags);
  657. }
  658. EXPORT_SYMBOL(generic_getxattr);
  659. EXPORT_SYMBOL(generic_listxattr);
  660. EXPORT_SYMBOL(generic_setxattr);
  661. EXPORT_SYMBOL(generic_removexattr);