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. Signed-off-by: Mark Salyzyn <salyzyn@android.com> Cc: Miklos Szeredi <miklos@szeredi.hu> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: Amir Goldstein <amir73il@gmail.com> Cc: Randy Dunlap <rdunlap@infradead.org> Cc: Stephen Smalley <sds@tycho.nsa.gov> Cc: linux-unionfs@vger.kernel.org Cc: linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: kernel-team@android.com --- v9: - Add to the caveats v8: - drop pr_warn message after straw poll to remove it. - added a use case in the commit message v7: - change name of internal parameter to ovl_override_creds_def - report override_creds only if different than default v6: - Drop CONFIG_OVERLAY_FS_OVERRIDE_CREDS. - Do better with the documentation. - pr_warn message adjusted to report consequences. v5: - beefed up the caveats in the Documentation - Is dependent on "overlayfs: check CAP_DAC_READ_SEARCH before issuing exportfs_decode_fh" "overlayfs: check CAP_MKNOD before issuing vfs_whiteout" - Added prwarn when override_creds=off v4: - spelling and grammar errors in text v3: - Change name from caller_credentials / creator_credentials to the boolean override_creds. - Changed from creator to mounter credentials. - Updated and fortified the documentation. - Added CONFIG_OVERLAY_FS_OVERRIDE_CREDS v2: - Forward port changed attr to stat, resulting in a build error. - altered commit message. Signed-off-by: Mark Salyzyn <salyzyn@google.com> (cherry picked from https://lore.kernel.org/patchwork/patch/1009299) Bug: 109821005 Bug: 112955896 Bug: 127298877 Change-Id: I1d99298ec5e71174734481be3497763c6b9d42e1
This commit is contained in:
parent
b1af104fff
commit
f5f87ecac1
7 changed files with 73 additions and 19 deletions
|
@ -82,6 +82,29 @@ Only the lists of names from directories are merged. Other content
|
||||||
such as metadata and extended attributes are reported for the upper
|
such as metadata and extended attributes are reported for the upper
|
||||||
directory only. These attributes of the lower directory are hidden.
|
directory only. These attributes of the lower directory are hidden.
|
||||||
|
|
||||||
|
credentials
|
||||||
|
-----------
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
In the case where caller MAC or DAC credentials do not overlap, a
|
||||||
|
use case available in older versions of the driver, the
|
||||||
|
override_creds mount flag can be turned off and help when the use
|
||||||
|
pattern has caller with legitimate credentials where the mounter
|
||||||
|
does not. Several unintended side effects will occur though. The
|
||||||
|
caller without certain key capabilities or lower privilege will not
|
||||||
|
always be able to delete files or directories, create nodes, or
|
||||||
|
search some restricted directories. The ability to search and read
|
||||||
|
a directory entry is spotty as a result of the cache mechanism not
|
||||||
|
retesting 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.
|
||||||
|
|
||||||
whiteouts and opaque directories
|
whiteouts and opaque directories
|
||||||
--------------------------------
|
--------------------------------
|
||||||
|
|
||||||
|
|
|
@ -421,7 +421,7 @@ int ovl_copy_up(struct dentry *dentry)
|
||||||
dput(parent);
|
dput(parent);
|
||||||
dput(next);
|
dput(next);
|
||||||
}
|
}
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,7 +148,7 @@ static int ovl_dir_getattr(struct vfsmount *mnt, struct dentry *dentry,
|
||||||
type = ovl_path_real(dentry, &realpath);
|
type = ovl_path_real(dentry, &realpath);
|
||||||
old_cred = ovl_override_creds(dentry->d_sb);
|
old_cred = ovl_override_creds(dentry->d_sb);
|
||||||
err = vfs_getattr(&realpath, stat);
|
err = vfs_getattr(&realpath, stat);
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
@ -497,7 +497,8 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
|
||||||
override_cred->fsgid = inode->i_gid;
|
override_cred->fsgid = inode->i_gid;
|
||||||
if (!hardlink) {
|
if (!hardlink) {
|
||||||
err = security_dentry_create_files_as(dentry,
|
err = security_dentry_create_files_as(dentry,
|
||||||
stat->mode, &dentry->d_name, old_cred,
|
stat->mode, &dentry->d_name,
|
||||||
|
old_cred ? old_cred : current_cred(),
|
||||||
override_cred);
|
override_cred);
|
||||||
if (err) {
|
if (err) {
|
||||||
put_cred(override_cred);
|
put_cred(override_cred);
|
||||||
|
@ -515,7 +516,7 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
|
||||||
link, hardlink);
|
link, hardlink);
|
||||||
}
|
}
|
||||||
out_revert_creds:
|
out_revert_creds:
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
struct inode *realinode = d_inode(ovl_dentry_upper(dentry));
|
struct inode *realinode = d_inode(ovl_dentry_upper(dentry));
|
||||||
|
|
||||||
|
@ -757,7 +758,7 @@ static int ovl_do_remove(struct dentry *dentry, bool is_dir)
|
||||||
err = ovl_remove_upper(dentry, is_dir);
|
err = ovl_remove_upper(dentry, is_dir);
|
||||||
else
|
else
|
||||||
err = ovl_remove_and_whiteout(dentry, is_dir);
|
err = ovl_remove_and_whiteout(dentry, is_dir);
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
if (is_dir)
|
if (is_dir)
|
||||||
clear_nlink(dentry->d_inode);
|
clear_nlink(dentry->d_inode);
|
||||||
|
@ -998,7 +999,7 @@ out_dput_old:
|
||||||
out_unlock:
|
out_unlock:
|
||||||
unlock_rename(new_upperdir, old_upperdir);
|
unlock_rename(new_upperdir, old_upperdir);
|
||||||
out_revert_creds:
|
out_revert_creds:
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
out_drop_write:
|
out_drop_write:
|
||||||
ovl_drop_write(old);
|
ovl_drop_write(old);
|
||||||
out:
|
out:
|
||||||
|
|
|
@ -34,7 +34,7 @@ static int ovl_copy_up_truncate(struct dentry *dentry)
|
||||||
stat.size = 0;
|
stat.size = 0;
|
||||||
err = ovl_copy_up_one(parent, dentry, &lowerpath, &stat);
|
err = ovl_copy_up_one(parent, dentry, &lowerpath, &stat);
|
||||||
}
|
}
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
|
|
||||||
out_dput_parent:
|
out_dput_parent:
|
||||||
dput(parent);
|
dput(parent);
|
||||||
|
@ -91,7 +91,7 @@ int ovl_setattr(struct dentry *dentry, struct iattr *attr)
|
||||||
inode_lock(upperdentry->d_inode);
|
inode_lock(upperdentry->d_inode);
|
||||||
old_cred = ovl_override_creds(dentry->d_sb);
|
old_cred = ovl_override_creds(dentry->d_sb);
|
||||||
err = notify_change(upperdentry, attr, NULL);
|
err = notify_change(upperdentry, attr, NULL);
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
if (!err)
|
if (!err)
|
||||||
ovl_copyattr(upperdentry->d_inode, dentry->d_inode);
|
ovl_copyattr(upperdentry->d_inode, dentry->d_inode);
|
||||||
inode_unlock(upperdentry->d_inode);
|
inode_unlock(upperdentry->d_inode);
|
||||||
|
@ -115,7 +115,7 @@ static int ovl_getattr(struct vfsmount *mnt, struct dentry *dentry,
|
||||||
ovl_path_real(dentry, &realpath);
|
ovl_path_real(dentry, &realpath);
|
||||||
old_cred = ovl_override_creds(dentry->d_sb);
|
old_cred = ovl_override_creds(dentry->d_sb);
|
||||||
err = vfs_getattr(&realpath, stat);
|
err = vfs_getattr(&realpath, stat);
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ int ovl_permission(struct inode *inode, int mask)
|
||||||
mask |= MAY_READ;
|
mask |= MAY_READ;
|
||||||
}
|
}
|
||||||
err = inode_permission(realinode, mask);
|
err = inode_permission(realinode, mask);
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ static const char *ovl_get_link(struct dentry *dentry,
|
||||||
|
|
||||||
old_cred = ovl_override_creds(dentry->d_sb);
|
old_cred = ovl_override_creds(dentry->d_sb);
|
||||||
p = vfs_get_link(ovl_dentry_real(dentry), done);
|
p = vfs_get_link(ovl_dentry_real(dentry), done);
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ int ovl_xattr_set(struct dentry *dentry, const char *name, const void *value,
|
||||||
WARN_ON(flags != XATTR_REPLACE);
|
WARN_ON(flags != XATTR_REPLACE);
|
||||||
err = vfs_removexattr(realpath.dentry, name);
|
err = vfs_removexattr(realpath.dentry, name);
|
||||||
}
|
}
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
|
|
||||||
out_drop_write:
|
out_drop_write:
|
||||||
ovl_drop_write(dentry);
|
ovl_drop_write(dentry);
|
||||||
|
@ -223,7 +223,7 @@ int ovl_xattr_get(struct dentry *dentry, const char *name,
|
||||||
|
|
||||||
old_cred = ovl_override_creds(dentry->d_sb);
|
old_cred = ovl_override_creds(dentry->d_sb);
|
||||||
res = vfs_getxattr(realdentry, name, value, size);
|
res = vfs_getxattr(realdentry, name, value, size);
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size)
|
||||||
|
|
||||||
old_cred = ovl_override_creds(dentry->d_sb);
|
old_cred = ovl_override_creds(dentry->d_sb);
|
||||||
res = vfs_listxattr(realdentry, list, size);
|
res = vfs_listxattr(realdentry, list, size);
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
if (res <= 0 || size == 0)
|
if (res <= 0 || size == 0)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ struct posix_acl *ovl_get_acl(struct inode *inode, int type)
|
||||||
|
|
||||||
old_cred = ovl_override_creds(inode->i_sb);
|
old_cred = ovl_override_creds(inode->i_sb);
|
||||||
acl = get_acl(realinode, type);
|
acl = get_acl(realinode, type);
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
|
|
||||||
return acl;
|
return acl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,6 +164,7 @@ bool ovl_dentry_is_opaque(struct dentry *dentry);
|
||||||
void ovl_dentry_set_opaque(struct dentry *dentry, bool opaque);
|
void ovl_dentry_set_opaque(struct dentry *dentry, bool opaque);
|
||||||
bool ovl_is_whiteout(struct dentry *dentry);
|
bool ovl_is_whiteout(struct dentry *dentry);
|
||||||
const struct cred *ovl_override_creds(struct super_block *sb);
|
const struct cred *ovl_override_creds(struct super_block *sb);
|
||||||
|
void ovl_revert_creds(const struct cred *oldcred);
|
||||||
void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry);
|
void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry);
|
||||||
void ovl_inode_update(struct inode *inode, struct inode *upperinode);
|
void ovl_inode_update(struct inode *inode, struct inode *upperinode);
|
||||||
struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
|
struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
|
||||||
|
|
|
@ -223,7 +223,7 @@ static int ovl_check_whiteouts(struct dentry *dir, struct ovl_readdir_data *rdd)
|
||||||
}
|
}
|
||||||
inode_unlock(dir->d_inode);
|
inode_unlock(dir->d_inode);
|
||||||
}
|
}
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ struct ovl_config {
|
||||||
char *upperdir;
|
char *upperdir;
|
||||||
char *workdir;
|
char *workdir;
|
||||||
bool default_permissions;
|
bool default_permissions;
|
||||||
|
bool override_creds;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* private information held for overlayfs's superblock */
|
/* private information held for overlayfs's superblock */
|
||||||
|
@ -266,9 +267,17 @@ const struct cred *ovl_override_creds(struct super_block *sb)
|
||||||
{
|
{
|
||||||
struct ovl_fs *ofs = sb->s_fs_info;
|
struct ovl_fs *ofs = sb->s_fs_info;
|
||||||
|
|
||||||
|
if (!ofs->config.override_creds)
|
||||||
|
return NULL;
|
||||||
return override_creds(ofs->creator_cred);
|
return override_creds(ofs->creator_cred);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ovl_revert_creds(const struct cred *old_cred)
|
||||||
|
{
|
||||||
|
if (old_cred)
|
||||||
|
revert_creds(old_cred);
|
||||||
|
}
|
||||||
|
|
||||||
static bool ovl_is_opaquedir(struct dentry *dentry)
|
static bool ovl_is_opaquedir(struct dentry *dentry)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
@ -584,7 +593,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
|
||||||
ovl_copyattr(realdentry->d_inode, inode);
|
ovl_copyattr(realdentry->d_inode, inode);
|
||||||
}
|
}
|
||||||
|
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
oe->opaque = upperopaque;
|
oe->opaque = upperopaque;
|
||||||
oe->__upperdentry = upperdentry;
|
oe->__upperdentry = upperdentry;
|
||||||
memcpy(oe->lowerstack, stack, sizeof(struct path) * ctr);
|
memcpy(oe->lowerstack, stack, sizeof(struct path) * ctr);
|
||||||
|
@ -603,7 +612,7 @@ out_put:
|
||||||
out_put_upper:
|
out_put_upper:
|
||||||
dput(upperdentry);
|
dput(upperdentry);
|
||||||
out:
|
out:
|
||||||
revert_creds(old_cred);
|
ovl_revert_creds(old_cred);
|
||||||
return ERR_PTR(err);
|
return ERR_PTR(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -656,6 +665,11 @@ static int ovl_statfs(struct dentry *dentry, struct kstatfs *buf)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ovl_show_options
|
* ovl_show_options
|
||||||
*
|
*
|
||||||
|
@ -674,6 +688,9 @@ static int ovl_show_options(struct seq_file *m, struct dentry *dentry)
|
||||||
}
|
}
|
||||||
if (ufs->config.default_permissions)
|
if (ufs->config.default_permissions)
|
||||||
seq_puts(m, ",default_permissions");
|
seq_puts(m, ",default_permissions");
|
||||||
|
if (ufs->config.override_creds != ovl_override_creds_def)
|
||||||
|
seq_show_option(m, "override_creds",
|
||||||
|
ufs->config.override_creds ? "on" : "off");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -700,6 +717,8 @@ enum {
|
||||||
OPT_UPPERDIR,
|
OPT_UPPERDIR,
|
||||||
OPT_WORKDIR,
|
OPT_WORKDIR,
|
||||||
OPT_DEFAULT_PERMISSIONS,
|
OPT_DEFAULT_PERMISSIONS,
|
||||||
|
OPT_OVERRIDE_CREDS_ON,
|
||||||
|
OPT_OVERRIDE_CREDS_OFF,
|
||||||
OPT_ERR,
|
OPT_ERR,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -708,6 +727,8 @@ static const match_table_t ovl_tokens = {
|
||||||
{OPT_UPPERDIR, "upperdir=%s"},
|
{OPT_UPPERDIR, "upperdir=%s"},
|
||||||
{OPT_WORKDIR, "workdir=%s"},
|
{OPT_WORKDIR, "workdir=%s"},
|
||||||
{OPT_DEFAULT_PERMISSIONS, "default_permissions"},
|
{OPT_DEFAULT_PERMISSIONS, "default_permissions"},
|
||||||
|
{OPT_OVERRIDE_CREDS_ON, "override_creds=on"},
|
||||||
|
{OPT_OVERRIDE_CREDS_OFF, "override_creds=off"},
|
||||||
{OPT_ERR, NULL}
|
{OPT_ERR, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -738,6 +759,7 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
|
config->override_creds = ovl_override_creds_def;
|
||||||
while ((p = ovl_next_opt(&opt)) != NULL) {
|
while ((p = ovl_next_opt(&opt)) != NULL) {
|
||||||
int token;
|
int token;
|
||||||
substring_t args[MAX_OPT_ARGS];
|
substring_t args[MAX_OPT_ARGS];
|
||||||
|
@ -772,6 +794,14 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config)
|
||||||
config->default_permissions = true;
|
config->default_permissions = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case OPT_OVERRIDE_CREDS_ON:
|
||||||
|
config->override_creds = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OPT_OVERRIDE_CREDS_OFF:
|
||||||
|
config->override_creds = false;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
pr_err("overlayfs: unrecognized mount option \"%s\" or missing value\n", p);
|
pr_err("overlayfs: unrecognized mount option \"%s\" or missing value\n", p);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -1353,7 +1383,6 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
|
||||||
ovl_copyattr(realinode, d_inode(root_dentry));
|
ovl_copyattr(realinode, d_inode(root_dentry));
|
||||||
|
|
||||||
sb->s_root = root_dentry;
|
sb->s_root = root_dentry;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_free_oe:
|
out_free_oe:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue