Skip to content

Commit 6c4a5f9

Browse files
mbayntonamir73il
authored andcommitted
ovl: fail if trusted xattrs are needed but caller lacks permission
Some overlayfs features require permission to read/write trusted.* xattrs. These include redirect_dir, verity, metacopy, and data-only layers. This patch adds additional validations at mount time to stop overlays from mounting in certain cases where the resulting mount would not function according to the user's expectations because they lack permission to access trusted.* xattrs (for example, not global root.) Similar checks in ovl_make_workdir() that disable features instead of failing are still relevant and used in cases where the resulting mount can still work "reasonably well." Generally, if the feature was enabled through kernel config or module option, any mount that worked before will still work the same; this applies to redirect_dir and metacopy. The user must explicitly request these features in order to generate a mount failure. Verity and data-only layers on the other hand must be explictly requested and have no "reasonable" disabled or degraded alternative, so mounts attempting either always fail. "lower data-only dirs require metacopy support" moved down in case userxattr is set, which disables metacopy. Cc: [email protected] # v6.6+ Signed-off-by: Mike Baynton <[email protected]> Signed-off-by: Amir Goldstein <[email protected]>
1 parent 930b7c3 commit 6c4a5f9

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

fs/overlayfs/params.c

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -755,11 +755,6 @@ int ovl_fs_params_verify(const struct ovl_fs_context *ctx,
755755
{
756756
struct ovl_opt_set set = ctx->set;
757757

758-
if (ctx->nr_data > 0 && !config->metacopy) {
759-
pr_err("lower data-only dirs require metacopy support.\n");
760-
return -EINVAL;
761-
}
762-
763758
/* Workdir/index are useless in non-upper mount */
764759
if (!config->upperdir) {
765760
if (config->workdir) {
@@ -911,6 +906,39 @@ int ovl_fs_params_verify(const struct ovl_fs_context *ctx,
911906
config->metacopy = false;
912907
}
913908

909+
/*
910+
* Fail if we don't have trusted xattr capability and a feature was
911+
* explicitly requested that requires them.
912+
*/
913+
if (!config->userxattr && !capable(CAP_SYS_ADMIN)) {
914+
if (set.redirect &&
915+
config->redirect_mode != OVL_REDIRECT_NOFOLLOW) {
916+
pr_err("redirect_dir requires permission to access trusted xattrs\n");
917+
return -EPERM;
918+
}
919+
if (config->metacopy && set.metacopy) {
920+
pr_err("metacopy requires permission to access trusted xattrs\n");
921+
return -EPERM;
922+
}
923+
if (config->verity_mode) {
924+
pr_err("verity requires permission to access trusted xattrs\n");
925+
return -EPERM;
926+
}
927+
if (ctx->nr_data > 0) {
928+
pr_err("lower data-only dirs require permission to access trusted xattrs\n");
929+
return -EPERM;
930+
}
931+
/*
932+
* Other xattr-dependent features should be disabled without
933+
* great disturbance to the user in ovl_make_workdir().
934+
*/
935+
}
936+
937+
if (ctx->nr_data > 0 && !config->metacopy) {
938+
pr_err("lower data-only dirs require metacopy support.\n");
939+
return -EINVAL;
940+
}
941+
914942
return 0;
915943
}
916944

0 commit comments

Comments
 (0)