Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * linux/fs/hfsplus/xattr_trusted.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Vyacheslav Dubeyko <slava@dubeyko.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  * Handler for storing security labels as extended attributes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/nls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "hfsplus_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static int hfsplus_security_getxattr(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 				     struct dentry *unused, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 				     const char *name, void *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 				     size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 	return hfsplus_getxattr(inode, name, buffer, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 				XATTR_SECURITY_PREFIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 				XATTR_SECURITY_PREFIX_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static int hfsplus_security_setxattr(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 				     struct dentry *unused, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 				     const char *name, const void *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 				     size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	return hfsplus_setxattr(inode, name, buffer, size, flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 				XATTR_SECURITY_PREFIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 				XATTR_SECURITY_PREFIX_LEN);
^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 int hfsplus_initxattrs(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 				const struct xattr *xattr_array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 				void *fs_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	const struct xattr *xattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	char *xattr_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 		GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	if (!xattr_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	for (xattr = xattr_array; xattr->name != NULL; xattr++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 		if (!strcmp(xattr->name, ""))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 		strcpy(xattr_name, XATTR_SECURITY_PREFIX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 		strcpy(xattr_name +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 			XATTR_SECURITY_PREFIX_LEN, xattr->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 		memset(xattr_name +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 			XATTR_SECURITY_PREFIX_LEN + strlen(xattr->name), 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 		err = __hfsplus_setxattr(inode, xattr_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 					xattr->value, xattr->value_len, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	kfree(xattr_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int hfsplus_init_security(struct inode *inode, struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 				const struct qstr *qstr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	return security_inode_init_security(inode, dir, qstr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 					&hfsplus_initxattrs, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) const struct xattr_handler hfsplus_xattr_security_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 	.prefix	= XATTR_SECURITY_PREFIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	.get	= hfsplus_security_getxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	.set	= hfsplus_security_setxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) };