xattr_trusted.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include "reiserfs.h"
  3. #include <linux/capability.h>
  4. #include <linux/errno.h>
  5. #include <linux/fs.h>
  6. #include <linux/pagemap.h>
  7. #include <linux/xattr.h>
  8. #include "xattr.h"
  9. #include <linux/uaccess.h>
  10. static int
  11. trusted_get(const struct xattr_handler *handler, struct dentry *unused,
  12. struct inode *inode, const char *name, void *buffer, size_t size)
  13. {
  14. if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
  15. return -EPERM;
  16. return reiserfs_xattr_get(inode, xattr_full_name(handler, name),
  17. buffer, size);
  18. }
  19. static int
  20. trusted_set(const struct xattr_handler *handler,
  21. struct user_namespace *mnt_userns, struct dentry *unused,
  22. struct inode *inode, const char *name, const void *buffer,
  23. size_t size, int flags)
  24. {
  25. if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
  26. return -EPERM;
  27. return reiserfs_xattr_set(inode,
  28. xattr_full_name(handler, name),
  29. buffer, size, flags);
  30. }
  31. static bool trusted_list(struct dentry *dentry)
  32. {
  33. return capable(CAP_SYS_ADMIN) && !IS_PRIVATE(d_inode(dentry));
  34. }
  35. const struct xattr_handler reiserfs_xattr_trusted_handler = {
  36. .prefix = XATTR_TRUSTED_PREFIX,
  37. .get = trusted_get,
  38. .set = trusted_set,
  39. .list = trusted_list,
  40. };