Skip to content

Commit 76381a4

Browse files
kvaneeshericvh
authored andcommitted
fs/9p: Add access = client option to opt in acl evaluation.
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com> Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
1 parent ad77dbc commit 76381a4

6 files changed

Lines changed: 110 additions & 7 deletions

File tree

‎Documentation/filesystems/9p.txt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ OPTIONS
111111
This can be used to share devices/named pipes/sockets between
112112
hosts. This functionality will be expanded in later versions.
113113

114-
access there are three access modes.
114+
access there are four access modes.
115115
user = if a user tries to access a file on v9fs
116116
filesystem for the first time, v9fs sends an
117117
attach command (Tattach) for that user.
@@ -120,6 +120,8 @@ OPTIONS
120120
the files on the mounted filesystem
121121
any = v9fs does single attach and performs all
122122
operations as one user
123+
client = ACL based access check on the 9p client
124+
side for access validation
123125

124126
cachetag cache tag to use the specified persistent cache.
125127
cache tags for existing cache sessions can be listed at

‎fs/9p/acl.c‎

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "xattr.h"
2323
#include "acl.h"
2424
#include "v9fs_vfs.h"
25+
#include "v9fs.h"
2526

2627
static struct posix_acl *__v9fs_get_acl(struct p9_fid *fid, char *name)
2728
{
@@ -55,7 +56,14 @@ int v9fs_get_acl(struct inode *inode, struct p9_fid *fid)
5556
{
5657
int retval = 0;
5758
struct posix_acl *pacl, *dacl;
59+
struct v9fs_session_info *v9ses;
5860

61+
v9ses = v9fs_inode2v9ses(inode);
62+
if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT) {
63+
set_cached_acl(inode, ACL_TYPE_DEFAULT, NULL);
64+
set_cached_acl(inode, ACL_TYPE_ACCESS, NULL);
65+
return 0;
66+
}
5967
/* get the default/access acl values and cache them */
6068
dacl = __v9fs_get_acl(fid, POSIX_ACL_XATTR_DEFAULT);
6169
pacl = __v9fs_get_acl(fid, POSIX_ACL_XATTR_ACCESS);
@@ -85,7 +93,18 @@ static struct posix_acl *v9fs_get_cached_acl(struct inode *inode, int type)
8593

8694
int v9fs_check_acl(struct inode *inode, int mask)
8795
{
88-
struct posix_acl *acl = v9fs_get_cached_acl(inode, ACL_TYPE_ACCESS);
96+
struct posix_acl *acl;
97+
struct v9fs_session_info *v9ses;
98+
99+
v9ses = v9fs_inode2v9ses(inode);
100+
if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT) {
101+
/*
102+
* On access = client mode get the acl
103+
* values from the server
104+
*/
105+
return 0;
106+
}
107+
acl = v9fs_get_cached_acl(inode, ACL_TYPE_ACCESS);
89108

90109
if (IS_ERR(acl))
91110
return PTR_ERR(acl);
@@ -204,15 +223,41 @@ int v9fs_acl_mode(struct inode *dir, mode_t *modep,
204223

205224
}
206225

226+
static int v9fs_remote_get_acl(struct dentry *dentry, const char *name,
227+
void *buffer, size_t size, int type)
228+
{
229+
char *full_name;
230+
231+
switch (type) {
232+
case ACL_TYPE_ACCESS:
233+
full_name = POSIX_ACL_XATTR_ACCESS;
234+
break;
235+
case ACL_TYPE_DEFAULT:
236+
full_name = POSIX_ACL_XATTR_DEFAULT;
237+
break;
238+
default:
239+
BUG();
240+
}
241+
return v9fs_xattr_get(dentry, full_name, buffer, size);
242+
}
243+
207244
static int v9fs_xattr_get_acl(struct dentry *dentry, const char *name,
208245
void *buffer, size_t size, int type)
209246
{
247+
struct v9fs_session_info *v9ses;
210248
struct posix_acl *acl;
211249
int error;
212250

213251
if (strcmp(name, "") != 0)
214252
return -EINVAL;
215253

254+
v9ses = v9fs_inode2v9ses(dentry->d_inode);
255+
/*
256+
* We allow set/get/list of acl when access=client is not specified
257+
*/
258+
if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT)
259+
return v9fs_remote_get_acl(dentry, name, buffer, size, type);
260+
216261
acl = v9fs_get_cached_acl(dentry->d_inode, type);
217262
if (IS_ERR(acl))
218263
return PTR_ERR(acl);
@@ -224,16 +269,47 @@ static int v9fs_xattr_get_acl(struct dentry *dentry, const char *name,
224269
return error;
225270
}
226271

272+
static int v9fs_remote_set_acl(struct dentry *dentry, const char *name,
273+
const void *value, size_t size,
274+
int flags, int type)
275+
{
276+
char *full_name;
277+
278+
switch (type) {
279+
case ACL_TYPE_ACCESS:
280+
full_name = POSIX_ACL_XATTR_ACCESS;
281+
break;
282+
case ACL_TYPE_DEFAULT:
283+
full_name = POSIX_ACL_XATTR_DEFAULT;
284+
break;
285+
default:
286+
BUG();
287+
}
288+
return v9fs_xattr_set(dentry, full_name, value, size, flags);
289+
}
290+
291+
227292
static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name,
228293
const void *value, size_t size,
229294
int flags, int type)
230295
{
231296
int retval;
232297
struct posix_acl *acl;
298+
struct v9fs_session_info *v9ses;
233299
struct inode *inode = dentry->d_inode;
234300

235301
if (strcmp(name, "") != 0)
236302
return -EINVAL;
303+
304+
v9ses = v9fs_inode2v9ses(dentry->d_inode);
305+
/*
306+
* set the attribute on the remote. Without even looking at the
307+
* xattr value. We leave it to the server to validate
308+
*/
309+
if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT)
310+
return v9fs_remote_set_acl(dentry, name,
311+
value, size, flags, type);
312+
237313
if (S_ISLNK(inode->i_mode))
238314
return -EOPNOTSUPP;
239315
if (!is_owner_or_cap(inode))

‎fs/9p/fid.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ struct p9_fid *v9fs_fid_lookup(struct dentry *dentry)
149149
switch (access) {
150150
case V9FS_ACCESS_SINGLE:
151151
case V9FS_ACCESS_USER:
152+
case V9FS_ACCESS_CLIENT:
152153
uid = current_fsuid();
153154
any = 0;
154155
break;

‎fs/9p/v9fs.c‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,17 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
193193
v9ses->flags |= V9FS_ACCESS_USER;
194194
else if (strcmp(s, "any") == 0)
195195
v9ses->flags |= V9FS_ACCESS_ANY;
196-
else {
196+
else if (strcmp(s, "client") == 0) {
197+
#ifdef CONFIG_9P_FS_POSIX_ACL
198+
v9ses->flags |= V9FS_ACCESS_CLIENT;
199+
#else
200+
P9_DPRINTK(P9_DEBUG_ERROR,
201+
"access=client option not supported\n");
202+
kfree(s);
203+
ret = -EINVAL;
204+
goto free_and_return;
205+
#endif
206+
} else {
197207
v9ses->flags |= V9FS_ACCESS_SINGLE;
198208
v9ses->uid = simple_strtoul(s, &e, 10);
199209
if (*e != '\0')
@@ -278,6 +288,16 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
278288

279289
v9ses->maxdata = v9ses->clnt->msize - P9_IOHDRSZ;
280290

291+
if (!v9fs_proto_dotl(v9ses) &&
292+
((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_CLIENT)) {
293+
/*
294+
* We support ACCESS_CLIENT only for dotl.
295+
* Fall back to ACCESS_USER
296+
*/
297+
v9ses->flags &= ~V9FS_ACCESS_MASK;
298+
v9ses->flags |= V9FS_ACCESS_USER;
299+
}
300+
/*FIXME !! */
281301
/* for legacy mode, fall back to V9FS_ACCESS_ANY */
282302
if (!(v9fs_proto_dotu(v9ses) || v9fs_proto_dotl(v9ses)) &&
283303
((v9ses->flags&V9FS_ACCESS_MASK) == V9FS_ACCESS_USER)) {

‎fs/9p/v9fs.h‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,17 @@
3333
*
3434
* Session flags reflect options selected by users at mount time
3535
*/
36+
#define V9FS_ACCESS_ANY (V9FS_ACCESS_SINGLE | \
37+
V9FS_ACCESS_USER | \
38+
V9FS_ACCESS_CLIENT)
39+
#define V9FS_ACCESS_MASK V9FS_ACCESS_ANY
40+
3641
enum p9_session_flags {
3742
V9FS_PROTO_2000U = 0x01,
3843
V9FS_PROTO_2000L = 0x02,
3944
V9FS_ACCESS_SINGLE = 0x04,
4045
V9FS_ACCESS_USER = 0x08,
41-
V9FS_ACCESS_ANY = 0x0C,
42-
V9FS_ACCESS_MASK = 0x0C,
46+
V9FS_ACCESS_CLIENT = 0x10
4347
};
4448

4549
/* possible values of ->cache */

‎fs/9p/vfs_super.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ v9fs_fill_super(struct super_block *sb, struct v9fs_session_info *v9ses,
9090
MS_NOATIME;
9191

9292
#ifdef CONFIG_9P_FS_POSIX_ACL
93-
sb->s_flags |= MS_POSIXACL;
93+
if ((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_CLIENT)
94+
sb->s_flags |= MS_POSIXACL;
9495
#endif
9596

9697
save_mount_options(sb, data);
@@ -181,7 +182,6 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags,
181182
retval = v9fs_get_acl(inode, fid);
182183
if (retval)
183184
goto release_sb;
184-
185185
v9fs_fid_add(root, fid);
186186

187187
P9_DPRINTK(P9_DEBUG_VFS, " simple set mount, return 0\n");

0 commit comments

Comments
 (0)