]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.6.5/posix_acl-add-set_posix_acl.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.6.5 / posix_acl-add-set_posix_acl.patch
1 From 485e71e8fb6356c08c7fc6bcce4bf02c9a9a663f Mon Sep 17 00:00:00 2001
2 From: Andreas Gruenbacher <agruenba@redhat.com>
3 Date: Wed, 22 Jun 2016 23:57:25 +0200
4 Subject: posix_acl: Add set_posix_acl
5
6 From: Andreas Gruenbacher <agruenba@redhat.com>
7
8 commit 485e71e8fb6356c08c7fc6bcce4bf02c9a9a663f upstream.
9
10 Factor out part of posix_acl_xattr_set into a common function that takes
11 a posix_acl, which nfsd can also call.
12
13 The prototype already exists in include/linux/posix_acl.h.
14
15 Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
16 Cc: Christoph Hellwig <hch@infradead.org>
17 Cc: Al Viro <viro@zeniv.linux.org.uk>
18 Signed-off-by: J. Bruce Fields <bfields@redhat.com>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20
21 ---
22 fs/posix_acl.c | 42 +++++++++++++++++++++++-------------------
23 1 file changed, 23 insertions(+), 19 deletions(-)
24
25 --- a/fs/posix_acl.c
26 +++ b/fs/posix_acl.c
27 @@ -786,39 +786,43 @@ posix_acl_xattr_get(const struct xattr_h
28 return error;
29 }
30
31 -static int
32 -posix_acl_xattr_set(const struct xattr_handler *handler,
33 - struct dentry *dentry, const char *name,
34 - const void *value, size_t size, int flags)
35 +int
36 +set_posix_acl(struct inode *inode, int type, struct posix_acl *acl)
37 {
38 - struct inode *inode = d_backing_inode(dentry);
39 - struct posix_acl *acl = NULL;
40 - int ret;
41 -
42 if (!IS_POSIXACL(inode))
43 return -EOPNOTSUPP;
44 if (!inode->i_op->set_acl)
45 return -EOPNOTSUPP;
46
47 - if (handler->flags == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode))
48 - return value ? -EACCES : 0;
49 + if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode))
50 + return acl ? -EACCES : 0;
51 if (!inode_owner_or_capable(inode))
52 return -EPERM;
53
54 + if (acl) {
55 + int ret = posix_acl_valid(acl);
56 + if (ret)
57 + return ret;
58 + }
59 + return inode->i_op->set_acl(inode, acl, type);
60 +}
61 +EXPORT_SYMBOL(set_posix_acl);
62 +
63 +static int
64 +posix_acl_xattr_set(const struct xattr_handler *handler,
65 + struct dentry *dentry, const char *name,
66 + const void *value, size_t size, int flags)
67 +{
68 + struct inode *inode = d_backing_inode(dentry);
69 + struct posix_acl *acl = NULL;
70 + int ret;
71 +
72 if (value) {
73 acl = posix_acl_from_xattr(&init_user_ns, value, size);
74 if (IS_ERR(acl))
75 return PTR_ERR(acl);
76 -
77 - if (acl) {
78 - ret = posix_acl_valid(acl);
79 - if (ret)
80 - goto out;
81 - }
82 }
83 -
84 - ret = inode->i_op->set_acl(inode, acl, handler->flags);
85 -out:
86 + ret = set_posix_acl(inode, handler->flags, acl);
87 posix_acl_release(acl);
88 return ret;
89 }