[Devel] [PATCH RH9] fs/namei: allow hardlinking between mounts with the same superblock

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Fri Nov 12 15:34:08 MSK 2021


When we dump deleted files in criu, we are re-linking them back to fs, so
we don't need to copy them. But if the mount where this file resides is
overmounted we need to uncover it first. Uncovering it in original mount
namespace is very difficult since we may need to unfreeze processes back
if we failed somewhere later or even doing snapshot. So we copy mount
namespace and uncover this mount there. Unfortunately we can't hardlink
open fd to this uncovered mount since it is not the same mount where the
file was.
Technically there is no problem to create hardlink if superblock is
the same for both mounts. Allow this for CAP_SYS_ADMIN and ve_pseudosper.

https://jira.sw.ru/browse/PSBM-127834
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 fs/namei.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/namei.c b/fs/namei.c
index 38f52c1..6361f52 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -39,6 +39,7 @@
 #include <linux/bitops.h>
 #include <linux/init_task.h>
 #include <linux/uaccess.h>
+#include <linux/ve.h>
 
 #include "internal.h"
 #include "mount.h"
@@ -4370,7 +4371,12 @@ static int do_linkat(int olddfd, const char __user *oldname, int newdfd,
 
 	error = -EXDEV;
 	if (old_path.mnt != new_path.mnt)
-		goto out_dput;
+#ifdef CONFIG_VE
+		if (!((old_path.mnt->mnt_sb == new_path.mnt->mnt_sb) &&
+		      (capable(CAP_SYS_ADMIN) || get_exec_env()->is_pseudosuper)))
+#endif
+			goto out_dput;
+
 	mnt_userns = mnt_user_ns(new_path.mnt);
 	error = may_linkat(mnt_userns, &old_path);
 	if (unlikely(error))
-- 
1.8.3.1



More information about the Devel mailing list