Skip to content

Commit a3d49f6

Browse files
author
Miklos Szeredi
committed
ovl: fail if trusted xattrs are needed but caller lacks permission
JIRA: https://issues.redhat.com/browse/RHEL-83562 commit 6c4a5f9 Author: Mike Baynton <mike@mbaynton.com> Date: Wed Jul 10 22:52:04 2024 -0500 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: stable@vger.kernel.org # v6.6+ Signed-off-by: Mike Baynton <mike@mbaynton.com> Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 0a650b5 commit a3d49f6

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
@@ -753,11 +753,6 @@ int ovl_fs_params_verify(const struct ovl_fs_context *ctx,
753753
{
754754
struct ovl_opt_set set = ctx->set;
755755

756-
if (ctx->nr_data > 0 && !config->metacopy) {
757-
pr_err("lower data-only dirs require metacopy support.\n");
758-
return -EINVAL;
759-
}
760-
761756
/* Workdir/index are useless in non-upper mount */
762757
if (!config->upperdir) {
763758
if (config->workdir) {
@@ -909,6 +904,39 @@ int ovl_fs_params_verify(const struct ovl_fs_context *ctx,
909904
config->metacopy = false;
910905
}
911906

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

0 commit comments

Comments
 (0)