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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Copyright IBM Corporation, 2010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * This program is free software; you can redistribute it and/or modify it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * under the terms of version 2.1 of the GNU Lesser General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * as published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * This program is distributed in the hope that it would be useful, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <net/9p/9p.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <net/9p/client.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/posix_acl_xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "acl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "v9fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "v9fs_vfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include "fid.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static struct posix_acl *__v9fs_get_acl(struct p9_fid *fid, char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	ssize_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	void *value = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct posix_acl *acl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	size = v9fs_fid_xattr_get(fid, name, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (size > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		value = kzalloc(size, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		if (!value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 			return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		size = v9fs_fid_xattr_get(fid, name, value, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		if (size > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 			acl = posix_acl_from_xattr(&init_user_ns, value, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 			if (IS_ERR(acl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 				goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	} else if (size == -ENODATA || size == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		   size == -ENOSYS || size == -EOPNOTSUPP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		acl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		acl = ERR_PTR(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	kfree(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	return acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) int v9fs_get_acl(struct inode *inode, struct p9_fid *fid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct posix_acl *pacl, *dacl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	v9ses = v9fs_inode2v9ses(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			((v9ses->flags & V9FS_ACL_MASK) != V9FS_POSIX_ACL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		set_cached_acl(inode, ACL_TYPE_DEFAULT, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		set_cached_acl(inode, ACL_TYPE_ACCESS, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	/* get the default/access acl values and cache them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	dacl = __v9fs_get_acl(fid, XATTR_NAME_POSIX_ACL_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	pacl = __v9fs_get_acl(fid, XATTR_NAME_POSIX_ACL_ACCESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (!IS_ERR(dacl) && !IS_ERR(pacl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		set_cached_acl(inode, ACL_TYPE_DEFAULT, dacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		set_cached_acl(inode, ACL_TYPE_ACCESS, pacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		retval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (!IS_ERR(dacl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		posix_acl_release(dacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (!IS_ERR(pacl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		posix_acl_release(pacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static struct posix_acl *v9fs_get_cached_acl(struct inode *inode, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	struct posix_acl *acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	 * 9p Always cache the acl value when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	 * instantiating the inode (v9fs_inode_from_fid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	acl = get_cached_acl(inode, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	BUG_ON(is_uncached_acl(acl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	return acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct posix_acl *v9fs_iop_get_acl(struct inode *inode, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	v9ses = v9fs_inode2v9ses(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			((v9ses->flags & V9FS_ACL_MASK) != V9FS_POSIX_ACL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		 * On access = client  and acl = on mode get the acl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		 * values from the server
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return v9fs_get_cached_acl(inode, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static int v9fs_set_acl(struct p9_fid *fid, int type, struct posix_acl *acl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	void *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (!acl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	/* Set a setxattr request to server */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	size = posix_acl_xattr_size(acl->a_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	buffer = kmalloc(size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	retval = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		goto err_free_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	case ACL_TYPE_ACCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		name = XATTR_NAME_POSIX_ACL_ACCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	case ACL_TYPE_DEFAULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		name = XATTR_NAME_POSIX_ACL_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	retval = v9fs_fid_xattr_set(fid, name, buffer, size, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) err_free_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) int v9fs_acl_chmod(struct inode *inode, struct p9_fid *fid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct posix_acl *acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (S_ISLNK(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	acl = v9fs_get_cached_acl(inode, ACL_TYPE_ACCESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (acl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		retval = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		set_cached_acl(inode, ACL_TYPE_ACCESS, acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		retval = v9fs_set_acl(fid, ACL_TYPE_ACCESS, acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		posix_acl_release(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) int v9fs_set_create_acl(struct inode *inode, struct p9_fid *fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			struct posix_acl *dacl, struct posix_acl *acl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	set_cached_acl(inode, ACL_TYPE_DEFAULT, dacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	set_cached_acl(inode, ACL_TYPE_ACCESS, acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	v9fs_set_acl(fid, ACL_TYPE_DEFAULT, dacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	v9fs_set_acl(fid, ACL_TYPE_ACCESS, acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) void v9fs_put_acl(struct posix_acl *dacl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		  struct posix_acl *acl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	posix_acl_release(dacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	posix_acl_release(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) int v9fs_acl_mode(struct inode *dir, umode_t *modep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		  struct posix_acl **dpacl, struct posix_acl **pacl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	umode_t mode = *modep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	struct posix_acl *acl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (!S_ISLNK(mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		acl = v9fs_get_cached_acl(dir, ACL_TYPE_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		if (IS_ERR(acl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			return PTR_ERR(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		if (!acl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			mode &= ~current_umask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (acl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		if (S_ISDIR(mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			*dpacl = posix_acl_dup(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		retval = __posix_acl_create(&acl, GFP_NOFS, &mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		if (retval > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			*pacl = acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			posix_acl_release(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	*modep  = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static int v9fs_xattr_get_acl(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			      struct dentry *dentry, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			      const char *name, void *buffer, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			      int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	struct posix_acl *acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	v9ses = v9fs_dentry2v9ses(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	 * We allow set/get/list of acl when access=client is not specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		return v9fs_xattr_get(dentry, handler->name, buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	acl = v9fs_get_cached_acl(inode, handler->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (IS_ERR(acl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		return PTR_ERR(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (acl == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	posix_acl_release(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static int v9fs_xattr_set_acl(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			      struct dentry *dentry, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			      const char *name, const void *value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			      size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	struct posix_acl *acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	v9ses = v9fs_dentry2v9ses(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	 * set the attribute on the remote. Without even looking at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	 * xattr value. We leave it to the server to validate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		return v9fs_xattr_set(dentry, handler->name, value, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 				      flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (S_ISLNK(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (!inode_owner_or_capable(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		/* update the cached acl value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		acl = posix_acl_from_xattr(&init_user_ns, value, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		if (IS_ERR(acl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			return PTR_ERR(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		else if (acl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			retval = posix_acl_valid(inode->i_sb->s_user_ns, acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 				goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		acl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	switch (handler->flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	case ACL_TYPE_ACCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		if (acl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			struct iattr iattr = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			struct posix_acl *old_acl = acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			retval = posix_acl_update_mode(inode, &iattr.ia_mode, &acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 				goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			if (!acl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 				 * ACL can be represented
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 				 * by the mode bits. So don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 				 * update ACL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 				posix_acl_release(old_acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 				value = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 				size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			iattr.ia_valid = ATTR_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			/* FIXME should we update ctime ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			 * What is the following setxattr update the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			 * mode ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			v9fs_vfs_setattr_dotl(dentry, &iattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	case ACL_TYPE_DEFAULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		if (!S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			retval = acl ? -EINVAL : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	retval = v9fs_xattr_set(dentry, handler->name, value, size, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	if (!retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		set_cached_acl(inode, handler->flags, acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	posix_acl_release(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) const struct xattr_handler v9fs_xattr_acl_access_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	.name	= XATTR_NAME_POSIX_ACL_ACCESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	.flags	= ACL_TYPE_ACCESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	.get	= v9fs_xattr_get_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	.set	= v9fs_xattr_set_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) const struct xattr_handler v9fs_xattr_acl_default_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	.name	= XATTR_NAME_POSIX_ACL_DEFAULT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	.flags	= ACL_TYPE_DEFAULT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	.get	= v9fs_xattr_get_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	.set	= v9fs_xattr_set_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) };