Skip to content

Commit e45b254

Browse files
ebiedermMiklos Szeredi
authored andcommitted
fuse: Ensure posix acls are translated outside of init_user_ns
Ensure the translation happens by failing to read or write posix acls when the filesystem has not indicated it supports posix acls. This ensures that modern cached posix acl support is available and used when dealing with posix acls. This is important because only that path has the code to convernt the uids and gids in posix acls into the user namespace of a fuse filesystem. Signed-off-by: "Eric W. Biederman" <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 5ba2419 commit e45b254

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

fs/fuse/fuse_i.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,7 @@ ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
985985
int fuse_removexattr(struct inode *inode, const char *name);
986986
extern const struct xattr_handler *fuse_xattr_handlers[];
987987
extern const struct xattr_handler *fuse_acl_xattr_handlers[];
988+
extern const struct xattr_handler *fuse_no_acl_xattr_handlers[];
988989

989990
struct posix_acl;
990991
struct posix_acl *fuse_get_acl(struct inode *inode, int type);

fs/fuse/inode.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,13 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
11001100
file->f_cred->user_ns != sb->s_user_ns)
11011101
goto err_fput;
11021102

1103+
/*
1104+
* If we are not in the initial user namespace posix
1105+
* acls must be translated.
1106+
*/
1107+
if (sb->s_user_ns != &init_user_ns)
1108+
sb->s_xattr = fuse_no_acl_xattr_handlers;
1109+
11031110
fc = kmalloc(sizeof(*fc), GFP_KERNEL);
11041111
err = -ENOMEM;
11051112
if (!fc)

fs/fuse/xattr.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,26 @@ static int fuse_xattr_set(const struct xattr_handler *handler,
192192
return fuse_setxattr(inode, name, value, size, flags);
193193
}
194194

195+
static bool no_xattr_list(struct dentry *dentry)
196+
{
197+
return false;
198+
}
199+
200+
static int no_xattr_get(const struct xattr_handler *handler,
201+
struct dentry *dentry, struct inode *inode,
202+
const char *name, void *value, size_t size)
203+
{
204+
return -EOPNOTSUPP;
205+
}
206+
207+
static int no_xattr_set(const struct xattr_handler *handler,
208+
struct dentry *dentry, struct inode *nodee,
209+
const char *name, const void *value,
210+
size_t size, int flags)
211+
{
212+
return -EOPNOTSUPP;
213+
}
214+
195215
static const struct xattr_handler fuse_xattr_handler = {
196216
.prefix = "",
197217
.get = fuse_xattr_get,
@@ -209,3 +229,26 @@ const struct xattr_handler *fuse_acl_xattr_handlers[] = {
209229
&fuse_xattr_handler,
210230
NULL
211231
};
232+
233+
static const struct xattr_handler fuse_no_acl_access_xattr_handler = {
234+
.name = XATTR_NAME_POSIX_ACL_ACCESS,
235+
.flags = ACL_TYPE_ACCESS,
236+
.list = no_xattr_list,
237+
.get = no_xattr_get,
238+
.set = no_xattr_set,
239+
};
240+
241+
static const struct xattr_handler fuse_no_acl_default_xattr_handler = {
242+
.name = XATTR_NAME_POSIX_ACL_DEFAULT,
243+
.flags = ACL_TYPE_ACCESS,
244+
.list = no_xattr_list,
245+
.get = no_xattr_get,
246+
.set = no_xattr_set,
247+
};
248+
249+
const struct xattr_handler *fuse_no_acl_xattr_handlers[] = {
250+
&fuse_no_acl_access_xattr_handler,
251+
&fuse_no_acl_default_xattr_handler,
252+
&fuse_xattr_handler,
253+
NULL
254+
};

0 commit comments

Comments
 (0)