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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Squashfs - a compressed read only filesystem for Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Phillip Lougher <phillip@squashfs.org.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * xattr.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/vfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "squashfs_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "squashfs_fs_sb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "squashfs_fs_i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "squashfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static const struct xattr_handler *squashfs_xattr_handler(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) ssize_t squashfs_listxattr(struct dentry *d, char *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	size_t buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct inode *inode = d_inode(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct squashfs_sb_info *msblk = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	u64 start = SQUASHFS_XATTR_BLK(squashfs_i(inode)->xattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 						 + msblk->xattr_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	int offset = SQUASHFS_XATTR_OFFSET(squashfs_i(inode)->xattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	int count = squashfs_i(inode)->xattr_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	size_t rest = buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	/* check that the file system has xattrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	if (msblk->xattr_id_table == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	/* loop reading each xattr name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	while (count--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		struct squashfs_xattr_entry entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		struct squashfs_xattr_val val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		const struct xattr_handler *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		int name_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		err = squashfs_read_metadata(sb, &entry, &start, &offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 							sizeof(entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		name_size = le16_to_cpu(entry.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		handler = squashfs_xattr_handler(le16_to_cpu(entry.type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		if (handler && (!handler->list || handler->list(d))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			const char *prefix = handler->prefix ?: handler->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			size_t prefix_size = strlen(prefix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			if (buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 				if (prefix_size + name_size + 1 > rest) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 					err = -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 					goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 				memcpy(buffer, prefix, prefix_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 				buffer += prefix_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			err = squashfs_read_metadata(sb, buffer, &start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 				&offset, name_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 				goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			if (buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 				buffer[name_size] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 				buffer += name_size + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			rest -= prefix_size + name_size + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		} else  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			/* no handler or insuffficient privileges, so skip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			err = squashfs_read_metadata(sb, NULL, &start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 				&offset, name_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 				goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		/* skip remaining xattr entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		err = squashfs_read_metadata(sb, &val, &start, &offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 						sizeof(val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		err = squashfs_read_metadata(sb, NULL, &start, &offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 						le32_to_cpu(val.vsize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	err = buffer_size - rest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static int squashfs_xattr_get(struct inode *inode, int name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	const char *name, void *buffer, size_t buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	struct squashfs_sb_info *msblk = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	u64 start = SQUASHFS_XATTR_BLK(squashfs_i(inode)->xattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 						 + msblk->xattr_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	int offset = SQUASHFS_XATTR_OFFSET(squashfs_i(inode)->xattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	int count = squashfs_i(inode)->xattr_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	int name_len = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	int err, vsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	char *target = kmalloc(name_len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (target == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		return  -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	/* loop reading each xattr name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	for (; count; count--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		struct squashfs_xattr_entry entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		struct squashfs_xattr_val val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		int type, prefix, name_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		err = squashfs_read_metadata(sb, &entry, &start, &offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 							sizeof(entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		name_size = le16_to_cpu(entry.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		type = le16_to_cpu(entry.type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		prefix = type & SQUASHFS_XATTR_PREFIX_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		if (prefix == name_index && name_size == name_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			err = squashfs_read_metadata(sb, target, &start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 						&offset, name_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			err = squashfs_read_metadata(sb, NULL, &start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 						&offset, name_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		if (prefix == name_index && name_size == name_len &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 					strncmp(target, name, name_size) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			/* found xattr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			if (type & SQUASHFS_XATTR_VALUE_OOL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 				__le64 xattr_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 				u64 xattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				/* val is a reference to the real location */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 				err = squashfs_read_metadata(sb, &val, &start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 						&offset, sizeof(val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 				if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 					goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 				err = squashfs_read_metadata(sb, &xattr_val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 					&start, &offset, sizeof(xattr_val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 				if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 					goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 				xattr = le64_to_cpu(xattr_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 				start = SQUASHFS_XATTR_BLK(xattr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 							msblk->xattr_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 				offset = SQUASHFS_XATTR_OFFSET(xattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			/* read xattr value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			err = squashfs_read_metadata(sb, &val, &start, &offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 							sizeof(val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 				goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			vsize = le32_to_cpu(val.vsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			if (buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 				if (vsize > buffer_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 					err = -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 					goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 				err = squashfs_read_metadata(sb, buffer, &start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 					 &offset, vsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 				if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 					goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		/* no match, skip remaining xattr entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		err = squashfs_read_metadata(sb, &val, &start, &offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 							sizeof(val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		err = squashfs_read_metadata(sb, NULL, &start, &offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 						le32_to_cpu(val.vsize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	err = count ? vsize : -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	kfree(target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static int squashfs_xattr_handler_get(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 				      struct dentry *unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 				      struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 				      const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 				      void *buffer, size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	return squashfs_xattr_get(inode, handler->flags, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  * User namespace support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static const struct xattr_handler squashfs_xattr_user_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	.prefix	= XATTR_USER_PREFIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	.flags	= SQUASHFS_XATTR_USER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	.get	= squashfs_xattr_handler_get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  * Trusted namespace support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static bool squashfs_trusted_xattr_handler_list(struct dentry *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	return capable(CAP_SYS_ADMIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static const struct xattr_handler squashfs_xattr_trusted_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	.prefix	= XATTR_TRUSTED_PREFIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	.flags	= SQUASHFS_XATTR_TRUSTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	.list	= squashfs_trusted_xattr_handler_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	.get	= squashfs_xattr_handler_get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * Security namespace support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static const struct xattr_handler squashfs_xattr_security_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	.prefix	= XATTR_SECURITY_PREFIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	.flags	= SQUASHFS_XATTR_SECURITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	.get	= squashfs_xattr_handler_get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static const struct xattr_handler *squashfs_xattr_handler(int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (type & ~(SQUASHFS_XATTR_PREFIX_MASK | SQUASHFS_XATTR_VALUE_OOL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		/* ignore unrecognised type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	switch (type & SQUASHFS_XATTR_PREFIX_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	case SQUASHFS_XATTR_USER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		return &squashfs_xattr_user_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	case SQUASHFS_XATTR_TRUSTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		return &squashfs_xattr_trusted_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	case SQUASHFS_XATTR_SECURITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		return &squashfs_xattr_security_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		/* ignore unrecognised type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) const struct xattr_handler *squashfs_xattr_handlers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	&squashfs_xattr_user_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	&squashfs_xattr_trusted_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	&squashfs_xattr_security_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)