Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee4ef412 authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "ANDROID: overlayfs: internal getxattr operations without sepolicy checking"

parents a3518891 f4ca486c
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -365,6 +365,21 @@ int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name,
	return err;
}

int __ovl_xattr_get(struct dentry *dentry, struct inode *inode,
		    const char *name, void *value, size_t size)
{
	ssize_t res;
	const struct cred *old_cred;
	struct dentry *realdentry =
		ovl_i_dentry_upper(inode) ?: ovl_dentry_lower(dentry);

	old_cred = ovl_override_creds(dentry->d_sb);
	res = __vfs_getxattr(realdentry, d_inode(realdentry), name, value,
			     size);
	ovl_revert_creds(old_cred);
	return res;
}

int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name,
		  void *value, size_t size)
{
+7 −5
Original line number Diff line number Diff line
@@ -109,10 +109,11 @@ int ovl_check_fh_len(struct ovl_fh *fh, int fh_len)

static struct ovl_fh *ovl_get_fh(struct dentry *dentry, const char *name)
{
	int res, err;
	ssize_t res;
	int err;
	struct ovl_fh *fh = NULL;

	res = vfs_getxattr(dentry, name, NULL, 0);
	res = ovl_vfs_getxattr(dentry, name, NULL, 0);
	if (res < 0) {
		if (res == -ENODATA || res == -EOPNOTSUPP)
			return NULL;
@@ -126,7 +127,7 @@ static struct ovl_fh *ovl_get_fh(struct dentry *dentry, const char *name)
	if (!fh)
		return ERR_PTR(-ENOMEM);

	res = vfs_getxattr(dentry, name, fh, res);
	res = ovl_vfs_getxattr(dentry, name, fh, res);
	if (res < 0)
		goto fail;

@@ -144,10 +145,11 @@ static struct ovl_fh *ovl_get_fh(struct dentry *dentry, const char *name)
	return NULL;

fail:
	pr_warn_ratelimited("overlayfs: failed to get origin (%i)\n", res);
	pr_warn_ratelimited("overlayfs: failed to get origin (%zi)\n", res);
	goto out;
invalid:
	pr_warn_ratelimited("overlayfs: invalid origin (%*phN)\n", res, fh);
	pr_warn_ratelimited("overlayfs: invalid origin (%*phN)\n",
			    (int)res, fh);
	goto out;
}

+4 −0
Original line number Diff line number Diff line
@@ -209,6 +209,8 @@ void ovl_drop_write(struct dentry *dentry);
struct dentry *ovl_workdir(struct dentry *dentry);
const struct cred *ovl_override_creds(struct super_block *sb);
void ovl_revert_creds(const struct cred *oldcred);
ssize_t ovl_vfs_getxattr(struct dentry *dentry, const char *name, void *buf,
			 size_t size);
struct super_block *ovl_same_sb(struct super_block *sb);
int ovl_can_decode_fh(struct super_block *sb);
struct dentry *ovl_indexdir(struct super_block *sb);
@@ -351,6 +353,8 @@ int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name,
		  const void *value, size_t size, int flags);
int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name,
		  void *value, size_t size);
int __ovl_xattr_get(struct dentry *dentry, struct inode *inode,
		    const char *name, void *value, size_t size);
ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size);
struct posix_acl *ovl_get_acl(struct inode *inode, int type);
int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags);
+18 −0
Original line number Diff line number Diff line
@@ -884,6 +884,14 @@ ovl_posix_acl_xattr_get(const struct xattr_handler *handler,
	return ovl_xattr_get(dentry, inode, handler->name, buffer, size);
}

static int __maybe_unused
__ovl_posix_acl_xattr_get(const struct xattr_handler *handler,
			  struct dentry *dentry, struct inode *inode,
			  const char *name, void *buffer, size_t size)
{
	return __ovl_xattr_get(dentry, inode, handler->name, buffer, size);
}

static int __maybe_unused
ovl_posix_acl_xattr_set(const struct xattr_handler *handler,
			struct dentry *dentry, struct inode *inode,
@@ -964,6 +972,13 @@ static int ovl_other_xattr_get(const struct xattr_handler *handler,
	return ovl_xattr_get(dentry, inode, name, buffer, size);
}

static int __ovl_other_xattr_get(const struct xattr_handler *handler,
				 struct dentry *dentry, struct inode *inode,
				 const char *name, void *buffer, size_t size)
{
	return __ovl_xattr_get(dentry, inode, name, buffer, size);
}

static int ovl_other_xattr_set(const struct xattr_handler *handler,
			       struct dentry *dentry, struct inode *inode,
			       const char *name, const void *value,
@@ -977,6 +992,7 @@ ovl_posix_acl_access_xattr_handler = {
	.name = XATTR_NAME_POSIX_ACL_ACCESS,
	.flags = ACL_TYPE_ACCESS,
	.get = ovl_posix_acl_xattr_get,
	.__get = __ovl_posix_acl_xattr_get,
	.set = ovl_posix_acl_xattr_set,
};

@@ -985,6 +1001,7 @@ ovl_posix_acl_default_xattr_handler = {
	.name = XATTR_NAME_POSIX_ACL_DEFAULT,
	.flags = ACL_TYPE_DEFAULT,
	.get = ovl_posix_acl_xattr_get,
	.__get = __ovl_posix_acl_xattr_get,
	.set = ovl_posix_acl_xattr_set,
};

@@ -997,6 +1014,7 @@ static const struct xattr_handler ovl_own_xattr_handler = {
static const struct xattr_handler ovl_other_xattr_handler = {
	.prefix	= "", /* catch all */
	.get = ovl_other_xattr_get,
	.__get = __ovl_other_xattr_get,
	.set = ovl_other_xattr_set,
};

+15 −9
Original line number Diff line number Diff line
@@ -51,6 +51,12 @@ void ovl_revert_creds(const struct cred *old_cred)
		revert_creds(old_cred);
}

ssize_t ovl_vfs_getxattr(struct dentry *dentry, const char *name, void *buf,
			 size_t size)
{
	return __vfs_getxattr(dentry, d_inode(dentry), name, buf, size);
}

struct super_block *ovl_same_sb(struct super_block *sb)
{
	struct ovl_fs *ofs = sb->s_fs_info;
@@ -549,9 +555,9 @@ void ovl_copy_up_end(struct dentry *dentry)

bool ovl_check_origin_xattr(struct dentry *dentry)
{
	int res;
	ssize_t res;

	res = vfs_getxattr(dentry, OVL_XATTR_ORIGIN, NULL, 0);
	res = ovl_vfs_getxattr(dentry, OVL_XATTR_ORIGIN, NULL, 0);

	/* Zero size value means "copied up but origin unknown" */
	if (res >= 0)
@@ -562,13 +568,13 @@ bool ovl_check_origin_xattr(struct dentry *dentry)

bool ovl_check_dir_xattr(struct dentry *dentry, const char *name)
{
	int res;
	ssize_t res;
	char val;

	if (!d_is_dir(dentry))
		return false;

	res = vfs_getxattr(dentry, name, &val, 1);
	res = ovl_vfs_getxattr(dentry, name, &val, 1);
	if (res == 1 && val == 'y')
		return true;

@@ -852,13 +858,13 @@ int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir)
/* err < 0, 0 if no metacopy xattr, 1 if metacopy xattr found */
int ovl_check_metacopy_xattr(struct dentry *dentry)
{
	int res;
	ssize_t res;

	/* Only regular files can have metacopy xattr */
	if (!S_ISREG(d_inode(dentry)->i_mode))
		return 0;

	res = vfs_getxattr(dentry, OVL_XATTR_METACOPY, NULL, 0);
	res = ovl_vfs_getxattr(dentry, OVL_XATTR_METACOPY, NULL, 0);
	if (res < 0) {
		if (res == -ENODATA || res == -EOPNOTSUPP)
			return 0;
@@ -867,7 +873,7 @@ int ovl_check_metacopy_xattr(struct dentry *dentry)

	return 1;
out:
	pr_warn_ratelimited("overlayfs: failed to get metacopy (%i)\n", res);
	pr_warn_ratelimited("overlayfs: failed to get metacopy (%zi)\n", res);
	return res;
}

@@ -893,7 +899,7 @@ ssize_t ovl_getxattr(struct dentry *dentry, char *name, char **value,
	ssize_t res;
	char *buf = NULL;

	res = vfs_getxattr(dentry, name, NULL, 0);
	res = ovl_vfs_getxattr(dentry, name, NULL, 0);
	if (res < 0) {
		if (res == -ENODATA || res == -EOPNOTSUPP)
			return -ENODATA;
@@ -905,7 +911,7 @@ ssize_t ovl_getxattr(struct dentry *dentry, char *name, char **value,
		if (!buf)
			return -ENOMEM;

		res = vfs_getxattr(dentry, name, buf, res);
		res = ovl_vfs_getxattr(dentry, name, buf, res);
		if (res < 0)
			goto fail;
	}