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