ANDROID: overlayfs: override_creds=off option bypass creator_cred
By default, all access to the upper, lower and work directories is the recorded mounter's MAC and DAC credentials. The incoming accesses are checked against the caller's credentials. If the principles of least privilege are applied, the mounter's credentials might not overlap the credentials of the caller's when accessing the overlayfs filesystem. For example, a file that a lower DAC privileged caller can execute, is MAC denied to the generally higher DAC privileged mounter, to prevent an attack vector. We add the option to turn off override_creds in the mount options; all subsequent operations after mount on the filesystem will be only the caller's credentials. The module boolean parameter and mount option override_creds is also added as a presence check for this "feature", existence of /sys/module/overlay/parameters/override_creds. It was not always this way. Circa 4.6 there was no recorded mounter's credentials, instead privileged access to upper or work directories were temporarily increased to perform the operations. The MAC (selinux) policies were caller's in all cases. override_creds=off partially returns us to this older access model minus the insecure temporary credential increases. This is to permit use in a system with non-overlapping security models for each executable including the agent that mounts the overlayfs filesystem. In Android this is the case since init, which performs the mount operations, has a minimal MAC set of privileges to reduce any attack surface, and services that use the content have a different set of MAC privileges (eg: read, for vendor labelled configuration, execute for vendor libraries and modules). The caveats are not a problem in the Android usage model, however they should be fixed for completeness and for general use in time. Bug: 329657783 Change-Id: I3d59cdae4984b5eee87f226bdb8a9dd7fbd5248c Signed-off-by: David Anderson <dvander@google.com> Signed-off-by: Mark Salyzyn <salyzyn@android.com> Signed-off-by: Daniel Rosenberg <drosen@google.com> Test: adb-remount-test.sh
This commit is contained in:
@@ -204,7 +204,7 @@ handle it in two different ways:
|
||||
|
||||
1. return EXDEV error: this error is returned by rename(2) when trying to
|
||||
move a file or directory across filesystem boundaries. Hence
|
||||
applications are usually prepared to hande this error (mv(1) for example
|
||||
applications are usually prepared to handle this error (mv(1) for example
|
||||
recursively copies the directory tree). This is the default behavior.
|
||||
|
||||
2. If the "redirect_dir" feature is enabled, then the directory will be
|
||||
@@ -332,6 +332,30 @@ and::
|
||||
The resulting access permissions should be the same. The difference is in
|
||||
the time of copy (on-demand vs. up-front).
|
||||
|
||||
### Non overlapping credentials
|
||||
|
||||
As noted above, all access to the upper, lower and work directories is the
|
||||
recorded mounter's MAC and DAC credentials. The incoming accesses are
|
||||
checked against the caller's credentials.
|
||||
|
||||
It is possible, however, that the mounting process (say, init) has access to
|
||||
mount an overlay, but not access to read or execute certain files in the lower
|
||||
dir. Meanwhile another process may ONLY have access to files in the lower dir.
|
||||
This scenario is very common in a "principle of least privilege" security
|
||||
model. And in this case, using the mounter's credentials will result in access
|
||||
errors for the calling process, even though the calling process can access the
|
||||
lower dir.
|
||||
|
||||
To address this, the override_creds=off mount option will disable using the
|
||||
mounter's credentials.
|
||||
|
||||
The ability to search and read a directory entry is spotty as a result of the
|
||||
cache mechanism not re-testing the credentials because of the assumption, a
|
||||
privileged caller can fill cache, then a lower privilege can read the directory
|
||||
cache. The uneven security model where cache, upperdir and workdir are opened
|
||||
at privilege, but accessed without creating a form of privilege escalation,
|
||||
should only be used with strict understanding of the side effects and of the
|
||||
security policies.
|
||||
|
||||
Multiple lower layers
|
||||
---------------------
|
||||
|
||||
+25
-15
@@ -163,7 +163,7 @@ ssize_t backing_file_read_iter(struct file *file, struct iov_iter *iter,
|
||||
struct backing_file_ctx *ctx)
|
||||
{
|
||||
struct backing_aio *aio = NULL;
|
||||
const struct cred *old_cred;
|
||||
const struct cred *old_cred = NULL;
|
||||
ssize_t ret;
|
||||
|
||||
if (WARN_ON_ONCE(!(file->f_mode & FMODE_BACKING)))
|
||||
@@ -176,7 +176,8 @@ ssize_t backing_file_read_iter(struct file *file, struct iov_iter *iter,
|
||||
!(file->f_mode & FMODE_CAN_ODIRECT))
|
||||
return -EINVAL;
|
||||
|
||||
old_cred = override_creds(ctx->cred);
|
||||
if (ctx->cred)
|
||||
old_cred = override_creds(ctx->cred);
|
||||
if (is_sync_kiocb(iocb)) {
|
||||
rwf_t rwf = iocb_to_rw_flags(flags);
|
||||
|
||||
@@ -197,7 +198,8 @@ ssize_t backing_file_read_iter(struct file *file, struct iov_iter *iter,
|
||||
backing_aio_cleanup(aio, ret);
|
||||
}
|
||||
out:
|
||||
revert_creds(old_cred);
|
||||
if (old_cred)
|
||||
revert_creds(old_cred);
|
||||
|
||||
if (ctx->accessed)
|
||||
ctx->accessed(ctx->user_file);
|
||||
@@ -210,7 +212,7 @@ ssize_t backing_file_write_iter(struct file *file, struct iov_iter *iter,
|
||||
struct kiocb *iocb, int flags,
|
||||
struct backing_file_ctx *ctx)
|
||||
{
|
||||
const struct cred *old_cred;
|
||||
const struct cred *old_cred = NULL;
|
||||
ssize_t ret;
|
||||
|
||||
if (WARN_ON_ONCE(!(file->f_mode & FMODE_BACKING)))
|
||||
@@ -233,7 +235,8 @@ ssize_t backing_file_write_iter(struct file *file, struct iov_iter *iter,
|
||||
*/
|
||||
flags &= ~IOCB_DIO_CALLER_COMP;
|
||||
|
||||
old_cred = override_creds(ctx->cred);
|
||||
if (ctx->cred)
|
||||
old_cred = override_creds(ctx->cred);
|
||||
if (is_sync_kiocb(iocb)) {
|
||||
rwf_t rwf = iocb_to_rw_flags(flags);
|
||||
|
||||
@@ -264,7 +267,8 @@ ssize_t backing_file_write_iter(struct file *file, struct iov_iter *iter,
|
||||
backing_aio_cleanup(aio, ret);
|
||||
}
|
||||
out:
|
||||
revert_creds(old_cred);
|
||||
if (old_cred)
|
||||
revert_creds(old_cred);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -275,15 +279,17 @@ ssize_t backing_file_splice_read(struct file *in, loff_t *ppos,
|
||||
unsigned int flags,
|
||||
struct backing_file_ctx *ctx)
|
||||
{
|
||||
const struct cred *old_cred;
|
||||
const struct cred *old_cred = NULL;
|
||||
ssize_t ret;
|
||||
|
||||
if (WARN_ON_ONCE(!(in->f_mode & FMODE_BACKING)))
|
||||
return -EIO;
|
||||
|
||||
old_cred = override_creds(ctx->cred);
|
||||
if (ctx->cred)
|
||||
old_cred = override_creds(ctx->cred);
|
||||
ret = vfs_splice_read(in, ppos, pipe, len, flags);
|
||||
revert_creds(old_cred);
|
||||
if (old_cred)
|
||||
revert_creds(old_cred);
|
||||
|
||||
if (ctx->accessed)
|
||||
ctx->accessed(ctx->user_file);
|
||||
@@ -297,7 +303,7 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe,
|
||||
unsigned int flags,
|
||||
struct backing_file_ctx *ctx)
|
||||
{
|
||||
const struct cred *old_cred;
|
||||
const struct cred *old_cred = NULL;
|
||||
ssize_t ret;
|
||||
|
||||
if (WARN_ON_ONCE(!(out->f_mode & FMODE_BACKING)))
|
||||
@@ -310,11 +316,13 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
old_cred = override_creds(ctx->cred);
|
||||
if (ctx->cred)
|
||||
old_cred = override_creds(ctx->cred);
|
||||
file_start_write(out);
|
||||
ret = out->f_op->splice_write(pipe, out, ppos, len, flags);
|
||||
file_end_write(out);
|
||||
revert_creds(old_cred);
|
||||
if (old_cred)
|
||||
revert_creds(old_cred);
|
||||
|
||||
if (ctx->end_write)
|
||||
ctx->end_write(ctx->user_file);
|
||||
@@ -326,7 +334,7 @@ EXPORT_SYMBOL_GPL(backing_file_splice_write);
|
||||
int backing_file_mmap(struct file *file, struct vm_area_struct *vma,
|
||||
struct backing_file_ctx *ctx)
|
||||
{
|
||||
const struct cred *old_cred;
|
||||
const struct cred *old_cred = NULL;
|
||||
int ret;
|
||||
|
||||
if (WARN_ON_ONCE(!(file->f_mode & FMODE_BACKING)) ||
|
||||
@@ -338,9 +346,11 @@ int backing_file_mmap(struct file *file, struct vm_area_struct *vma,
|
||||
|
||||
vma_set_file(vma, file);
|
||||
|
||||
old_cred = override_creds(ctx->cred);
|
||||
if (ctx->cred)
|
||||
old_cred = override_creds(ctx->cred);
|
||||
ret = call_mmap(vma->vm_file, vma);
|
||||
revert_creds(old_cred);
|
||||
if (old_cred)
|
||||
revert_creds(old_cred);
|
||||
|
||||
if (ctx->accessed)
|
||||
ctx->accessed(ctx->user_file);
|
||||
|
||||
@@ -1225,7 +1225,7 @@ static int ovl_copy_up_flags(struct dentry *dentry, int flags)
|
||||
dput(parent);
|
||||
dput(next);
|
||||
}
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
+22
-12
@@ -554,7 +554,8 @@ out_cleanup:
|
||||
}
|
||||
|
||||
static int ovl_setup_cred_for_create(struct dentry *dentry, struct inode *inode,
|
||||
umode_t mode, const struct cred *old_cred)
|
||||
umode_t mode, const struct cred *old_cred,
|
||||
const struct cred **hold_cred)
|
||||
{
|
||||
int err;
|
||||
struct cred *override_cred;
|
||||
@@ -571,9 +572,8 @@ static int ovl_setup_cred_for_create(struct dentry *dentry, struct inode *inode,
|
||||
put_cred(override_cred);
|
||||
return err;
|
||||
}
|
||||
put_cred(override_creds(override_cred));
|
||||
*hold_cred = override_creds(override_cred);
|
||||
put_cred(override_cred);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -581,7 +581,7 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
|
||||
struct ovl_cattr *attr, bool origin)
|
||||
{
|
||||
int err;
|
||||
const struct cred *old_cred;
|
||||
const struct cred *old_cred, *hold_cred = NULL;
|
||||
struct dentry *parent = dentry->d_parent;
|
||||
|
||||
old_cred = ovl_override_creds(dentry->d_sb);
|
||||
@@ -609,8 +609,13 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
|
||||
* But in the other hardlink case, ovl_link() does not
|
||||
* create a new inode, so just use the ovl mounter's
|
||||
* fs{u,g}id.
|
||||
*
|
||||
* Retain current_cred() via hold_cred, since we need to
|
||||
* restore it if old_cred was NULL.
|
||||
*/
|
||||
err = ovl_setup_cred_for_create(dentry, inode, attr->mode, old_cred);
|
||||
err = ovl_setup_cred_for_create(dentry, inode, attr->mode,
|
||||
old_cred ?: current_cred(),
|
||||
&hold_cred);
|
||||
if (err)
|
||||
goto out_revert_creds;
|
||||
}
|
||||
@@ -621,7 +626,9 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
|
||||
err = ovl_create_over_whiteout(dentry, inode, attr);
|
||||
|
||||
out_revert_creds:
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred ?: hold_cred);
|
||||
if (old_cred && hold_cred)
|
||||
put_cred(hold_cred);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -702,7 +709,7 @@ static int ovl_set_link_redirect(struct dentry *dentry)
|
||||
|
||||
old_cred = ovl_override_creds(dentry->d_sb);
|
||||
err = ovl_set_redirect(dentry, false);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
|
||||
return err;
|
||||
}
|
||||
@@ -912,7 +919,7 @@ static int ovl_do_remove(struct dentry *dentry, bool is_dir)
|
||||
err = ovl_remove_upper(dentry, is_dir, &list);
|
||||
else
|
||||
err = ovl_remove_and_whiteout(dentry, &list);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
if (!err) {
|
||||
if (is_dir)
|
||||
clear_nlink(dentry->d_inode);
|
||||
@@ -1292,7 +1299,7 @@ out_dput_old:
|
||||
out_unlock:
|
||||
unlock_rename(new_upperdir, old_upperdir);
|
||||
out_revert_creds:
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(old->d_sb, old_cred);
|
||||
if (update_nlink)
|
||||
ovl_nlink_end(new);
|
||||
else
|
||||
@@ -1306,7 +1313,7 @@ out:
|
||||
static int ovl_create_tmpfile(struct file *file, struct dentry *dentry,
|
||||
struct inode *inode, umode_t mode)
|
||||
{
|
||||
const struct cred *old_cred;
|
||||
const struct cred *old_cred, *hold_cred = NULL;
|
||||
struct path realparentpath;
|
||||
struct file *realfile;
|
||||
struct dentry *newdentry;
|
||||
@@ -1315,7 +1322,8 @@ static int ovl_create_tmpfile(struct file *file, struct dentry *dentry,
|
||||
int err;
|
||||
|
||||
old_cred = ovl_override_creds(dentry->d_sb);
|
||||
err = ovl_setup_cred_for_create(dentry, inode, mode, old_cred);
|
||||
err = ovl_setup_cred_for_create(dentry, inode, mode,
|
||||
old_cred ?: current_cred(), &hold_cred);
|
||||
if (err)
|
||||
goto out_revert_creds;
|
||||
|
||||
@@ -1337,7 +1345,9 @@ static int ovl_create_tmpfile(struct file *file, struct dentry *dentry,
|
||||
fput(realfile);
|
||||
}
|
||||
out_revert_creds:
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred ?: hold_cred);
|
||||
if (old_cred && hold_cred)
|
||||
put_cred(hold_cred);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -52,7 +52,7 @@ static struct file *ovl_open_realfile(const struct file *file,
|
||||
realfile = backing_file_open(&file->f_path, flags, realpath,
|
||||
current_cred());
|
||||
}
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(inode->i_sb, old_cred);
|
||||
|
||||
pr_debug("open(%p[%pD2/%c], 0%o) -> (%p, 0%o)\n",
|
||||
file, file, ovl_whatisit(inode, realinode), file->f_flags,
|
||||
@@ -214,7 +214,7 @@ static loff_t ovl_llseek(struct file *file, loff_t offset, int whence)
|
||||
|
||||
old_cred = ovl_override_creds(inode->i_sb);
|
||||
ret = vfs_llseek(real.file, offset, whence);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(inode->i_sb, old_cred);
|
||||
|
||||
file->f_pos = real.file->f_pos;
|
||||
ovl_inode_unlock(inode);
|
||||
@@ -401,7 +401,7 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync)
|
||||
if (file_inode(real.file) == ovl_inode_upper(file_inode(file))) {
|
||||
old_cred = ovl_override_creds(file_inode(file)->i_sb);
|
||||
ret = vfs_fsync_range(real.file, start, end, datasync);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(file_inode(file)->i_sb, old_cred);
|
||||
}
|
||||
|
||||
fdput(real);
|
||||
@@ -441,7 +441,7 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len
|
||||
|
||||
old_cred = ovl_override_creds(file_inode(file)->i_sb);
|
||||
ret = vfs_fallocate(real.file, mode, offset, len);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(file_inode(file)->i_sb, old_cred);
|
||||
|
||||
/* Update size */
|
||||
ovl_file_modified(file);
|
||||
@@ -466,7 +466,7 @@ static int ovl_fadvise(struct file *file, loff_t offset, loff_t len, int advice)
|
||||
|
||||
old_cred = ovl_override_creds(file_inode(file)->i_sb);
|
||||
ret = vfs_fadvise(real.file, offset, len, advice);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(file_inode(file)->i_sb, old_cred);
|
||||
|
||||
fdput(real);
|
||||
|
||||
@@ -525,7 +525,7 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,
|
||||
flags);
|
||||
break;
|
||||
}
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(file_inode(file_out)->i_sb, old_cred);
|
||||
|
||||
/* Update size */
|
||||
ovl_file_modified(file_out);
|
||||
@@ -587,7 +587,7 @@ static int ovl_flush(struct file *file, fl_owner_t id)
|
||||
if (real.file->f_op->flush) {
|
||||
old_cred = ovl_override_creds(file_inode(file)->i_sb);
|
||||
err = real.file->f_op->flush(real.file, id);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(file_inode(file)->i_sb, old_cred);
|
||||
}
|
||||
fdput(real);
|
||||
|
||||
|
||||
+10
-10
@@ -80,7 +80,7 @@ int ovl_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
|
||||
inode_lock(upperdentry->d_inode);
|
||||
old_cred = ovl_override_creds(dentry->d_sb);
|
||||
err = ovl_do_notify_change(ofs, upperdentry, attr);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
if (!err)
|
||||
ovl_copyattr(dentry->d_inode);
|
||||
inode_unlock(upperdentry->d_inode);
|
||||
@@ -280,7 +280,7 @@ int ovl_getattr(struct mnt_idmap *idmap, const struct path *path,
|
||||
stat->nlink = dentry->d_inode->i_nlink;
|
||||
|
||||
out:
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
|
||||
return err;
|
||||
}
|
||||
@@ -317,7 +317,7 @@ int ovl_permission(struct mnt_idmap *idmap,
|
||||
mask |= MAY_READ;
|
||||
}
|
||||
err = inode_permission(mnt_idmap(realpath.mnt), realinode, mask);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(inode->i_sb, old_cred);
|
||||
|
||||
return err;
|
||||
}
|
||||
@@ -334,7 +334,7 @@ static const char *ovl_get_link(struct dentry *dentry,
|
||||
|
||||
old_cred = ovl_override_creds(dentry->d_sb);
|
||||
p = vfs_get_link(ovl_dentry_real(dentry), done);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -469,7 +469,7 @@ struct posix_acl *do_ovl_get_acl(struct mnt_idmap *idmap,
|
||||
|
||||
old_cred = ovl_override_creds(inode->i_sb);
|
||||
acl = ovl_get_acl_path(&realpath, posix_acl_xattr_name(type), noperm);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(inode->i_sb, old_cred);
|
||||
}
|
||||
|
||||
return acl;
|
||||
@@ -498,7 +498,7 @@ static int ovl_set_or_remove_acl(struct dentry *dentry, struct inode *inode,
|
||||
old_cred = ovl_override_creds(dentry->d_sb);
|
||||
real_acl = vfs_get_acl(mnt_idmap(realpath.mnt), realdentry,
|
||||
acl_name);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
if (IS_ERR(real_acl)) {
|
||||
err = PTR_ERR(real_acl);
|
||||
goto out;
|
||||
@@ -523,7 +523,7 @@ static int ovl_set_or_remove_acl(struct dentry *dentry, struct inode *inode,
|
||||
err = ovl_do_set_acl(ofs, realdentry, acl_name, acl);
|
||||
else
|
||||
err = ovl_do_remove_acl(ofs, realdentry, acl_name);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
ovl_drop_write(dentry);
|
||||
|
||||
/* copy c/mtime */
|
||||
@@ -600,7 +600,7 @@ static int ovl_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
|
||||
|
||||
old_cred = ovl_override_creds(inode->i_sb);
|
||||
err = realinode->i_op->fiemap(realinode, fieinfo, start, len);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(inode->i_sb, old_cred);
|
||||
|
||||
return err;
|
||||
}
|
||||
@@ -671,7 +671,7 @@ int ovl_fileattr_set(struct mnt_idmap *idmap,
|
||||
err = ovl_set_protattr(inode, upperpath.dentry, fa);
|
||||
if (!err)
|
||||
err = ovl_real_fileattr_set(&upperpath, fa);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(inode->i_sb, old_cred);
|
||||
ovl_drop_write(dentry);
|
||||
|
||||
/*
|
||||
@@ -733,7 +733,7 @@ int ovl_fileattr_get(struct dentry *dentry, struct fileattr *fa)
|
||||
old_cred = ovl_override_creds(inode->i_sb);
|
||||
err = ovl_real_fileattr_get(&realpath, fa);
|
||||
ovl_fileattr_prot_flags(inode, fa);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(inode->i_sb, old_cred);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -961,7 +961,7 @@ static int ovl_maybe_validate_verity(struct dentry *dentry)
|
||||
if (err == 0)
|
||||
ovl_set_flag(OVL_VERIFIED_DIGEST, inode);
|
||||
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
}
|
||||
|
||||
ovl_inode_unlock(inode);
|
||||
@@ -995,7 +995,7 @@ static int ovl_maybe_lookup_lowerdata(struct dentry *dentry)
|
||||
|
||||
old_cred = ovl_override_creds(dentry->d_sb);
|
||||
err = ovl_lookup_data_layers(dentry, redirect, &datapath);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
if (err)
|
||||
goto out_err;
|
||||
|
||||
@@ -1342,7 +1342,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
|
||||
|
||||
ovl_dentry_init_reval(dentry, upperdentry, OVL_I_E(inode));
|
||||
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
if (origin_path) {
|
||||
dput(origin_path->dentry);
|
||||
kfree(origin_path);
|
||||
@@ -1366,7 +1366,7 @@ out_put_upper:
|
||||
kfree(upperredirect);
|
||||
out:
|
||||
kfree(d.redirect);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
|
||||
@@ -1423,7 +1423,7 @@ bool ovl_lower_positive(struct dentry *dentry)
|
||||
dput(this);
|
||||
}
|
||||
}
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
|
||||
return positive;
|
||||
}
|
||||
|
||||
@@ -429,10 +429,15 @@ int ovl_want_write(struct dentry *dentry);
|
||||
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(struct super_block *sb, const struct cred *oldcred);
|
||||
|
||||
static inline const struct cred *ovl_creds(struct super_block *sb)
|
||||
{
|
||||
return OVL_FS(sb)->creator_cred;
|
||||
struct ovl_fs *ofs = OVL_FS(sb);
|
||||
|
||||
if (!ofs->config.override_creds)
|
||||
return NULL;
|
||||
return ofs->creator_cred;
|
||||
}
|
||||
|
||||
int ovl_can_decode_fh(struct super_block *sb);
|
||||
|
||||
@@ -19,6 +19,7 @@ struct ovl_config {
|
||||
bool metacopy;
|
||||
bool userxattr;
|
||||
bool ovl_volatile;
|
||||
bool override_creds;
|
||||
};
|
||||
|
||||
struct ovl_sb {
|
||||
|
||||
@@ -43,6 +43,11 @@ module_param_named(metacopy, ovl_metacopy_def, bool, 0644);
|
||||
MODULE_PARM_DESC(metacopy,
|
||||
"Default to on or off for the metadata only copy up feature");
|
||||
|
||||
static bool __read_mostly ovl_override_creds_def = true;
|
||||
module_param_named(override_creds, ovl_override_creds_def, bool, 0644);
|
||||
MODULE_PARM_DESC(ovl_override_creds_def,
|
||||
"Use mounter's credentials for accesses");
|
||||
|
||||
enum ovl_opt {
|
||||
Opt_lowerdir,
|
||||
Opt_lowerdir_add,
|
||||
@@ -59,6 +64,7 @@ enum ovl_opt {
|
||||
Opt_metacopy,
|
||||
Opt_verity,
|
||||
Opt_volatile,
|
||||
Opt_override_creds,
|
||||
};
|
||||
|
||||
static const struct constant_table ovl_parameter_bool[] = {
|
||||
@@ -155,6 +161,7 @@ const struct fs_parameter_spec ovl_parameter_spec[] = {
|
||||
fsparam_enum("metacopy", Opt_metacopy, ovl_parameter_bool),
|
||||
fsparam_enum("verity", Opt_verity, ovl_parameter_verity),
|
||||
fsparam_flag("volatile", Opt_volatile),
|
||||
fsparam_enum("override_creds", Opt_override_creds, ovl_parameter_bool),
|
||||
{}
|
||||
};
|
||||
|
||||
@@ -596,6 +603,9 @@ static int ovl_parse_param(struct fs_context *fc, struct fs_parameter *param)
|
||||
case Opt_userxattr:
|
||||
config->userxattr = true;
|
||||
break;
|
||||
case Opt_override_creds:
|
||||
config->override_creds = result.uint_32;
|
||||
break;
|
||||
default:
|
||||
pr_err("unrecognized mount option \"%s\" or missing value\n",
|
||||
param->key);
|
||||
|
||||
@@ -290,7 +290,7 @@ static int ovl_check_whiteouts(const struct path *path, struct ovl_readdir_data
|
||||
}
|
||||
inode_unlock(dir->d_inode);
|
||||
}
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(rdd->dentry->d_sb, old_cred);
|
||||
|
||||
return err;
|
||||
}
|
||||
@@ -808,7 +808,7 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx)
|
||||
}
|
||||
err = 0;
|
||||
out:
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -860,7 +860,7 @@ static struct file *ovl_dir_open_realfile(const struct file *file,
|
||||
|
||||
old_cred = ovl_override_creds(file_inode(file)->i_sb);
|
||||
res = ovl_path_open(realpath, O_RDONLY | (file->f_flags & O_LARGEFILE));
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(file_inode(file)->i_sb, old_cred);
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -987,7 +987,7 @@ int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list)
|
||||
|
||||
old_cred = ovl_override_creds(dentry->d_sb);
|
||||
err = ovl_dir_read_merged(dentry, list, &root);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
||||
+10
-2
@@ -65,9 +65,17 @@ const struct cred *ovl_override_creds(struct super_block *sb)
|
||||
{
|
||||
struct ovl_fs *ofs = OVL_FS(sb);
|
||||
|
||||
if (!ofs->config.override_creds)
|
||||
return NULL;
|
||||
return override_creds(ofs->creator_cred);
|
||||
}
|
||||
|
||||
void ovl_revert_creds(struct super_block *sb, const struct cred *old_cred)
|
||||
{
|
||||
if (old_cred)
|
||||
revert_creds(old_cred);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if underlying fs supports file handles and try to determine encoding
|
||||
* type, in order to deduce maximum inode number used by fs.
|
||||
@@ -1178,7 +1186,7 @@ int ovl_nlink_start(struct dentry *dentry)
|
||||
* value relative to the upper inode nlink in an upper inode xattr.
|
||||
*/
|
||||
err = ovl_set_nlink_upper(dentry);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
if (err)
|
||||
goto out_drop_write;
|
||||
|
||||
@@ -1203,7 +1211,7 @@ void ovl_nlink_end(struct dentry *dentry)
|
||||
|
||||
old_cred = ovl_override_creds(dentry->d_sb);
|
||||
ovl_cleanup_index(dentry);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
}
|
||||
|
||||
ovl_inode_unlock(inode);
|
||||
|
||||
@@ -47,7 +47,7 @@ static int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char
|
||||
ovl_path_lower(dentry, &realpath);
|
||||
old_cred = ovl_override_creds(dentry->d_sb);
|
||||
err = vfs_getxattr(mnt_idmap(realpath.mnt), realdentry, name, NULL, 0);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
if (err < 0)
|
||||
goto out;
|
||||
}
|
||||
@@ -72,7 +72,7 @@ static int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char
|
||||
WARN_ON(flags != XATTR_REPLACE);
|
||||
err = ovl_do_removexattr(ofs, realdentry, name);
|
||||
}
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
ovl_drop_write(dentry);
|
||||
|
||||
/* copy c/mtime */
|
||||
@@ -91,7 +91,7 @@ static int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char
|
||||
ovl_i_path_real(inode, &realpath);
|
||||
old_cred = ovl_override_creds(dentry->d_sb);
|
||||
res = vfs_getxattr(mnt_idmap(realpath.mnt), realpath.dentry, name, value, size);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size)
|
||||
|
||||
old_cred = ovl_override_creds(dentry->d_sb);
|
||||
res = vfs_listxattr(realdentry, list, size);
|
||||
revert_creds(old_cred);
|
||||
ovl_revert_creds(dentry->d_sb, old_cred);
|
||||
if (res <= 0 || size == 0)
|
||||
return res;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user