Skip to contentSkip to conversation

cred: #include init.h in cred.h

PATCH In review Alexey Dobriyan 19 participants 145 messages May 22, 2009 – Jun 4, 2009 19 messages not in the archive Page 2 of 2

Subsystems (14)
Networking Memory management x86 VFS +10 more subsystems
lore
Share & tools
lore
#153 lore raw

PATCH 29/38 C/R: formally checkpoint/restore struct mnt_namespace

In reply to Alexey Dobriyan
---
 fs/namespace.c                 |   70 ++++++++++++++++++++++++++++++++++++++++
 include/linux/kstate-image.h   |    6 +++
 include/linux/kstate.h         |    4 ++
 kernel/kstate/cpt-sys.c        |    6 +++
 kernel/kstate/kstate-context.c |    6 +++
 kernel/kstate/kstate-object.c  |    4 ++
 kernel/nsproxy.c               |   24 +++++++++++---
 7 files changed, 115 insertions(+), 5 deletions(-)
fs/namespace.c +70 -0
index be33bfc..ccd7b54 100644
@@ -3,6 +3,7 @@
  *
  * (C) Copyright Al Viro 2000, 2001
  *	Released under GPL v2.
+ * Copyright (C) 2000-2009 Parallels Holdings, Ltd.
  *
  * Based on code from fs/super.c, copyright Linus Torvalds and others.
  * Heavily rewritten.
@@ -2309,3 +2310,72 @@ void __put_mnt_ns(struct mnt_namespace *ns)
 	release_mounts(&umount_list);
 	kfree(ns);
 }
+
+#ifdef CONFIG_CHECKPOINT
+#include <linux/kstate.h>
+#include <linux/kstate-image.h>
+
+static int collect_mnt_ns(struct kstate_context *ctx, struct mnt_namespace *mnt_ns)
+{
+	int rv;
+
+	rv = kstate_collect_object(ctx, mnt_ns, KSTATE_CTX_MNT_NS);
+	pr_debug("collect mnt_ns %p: rv %d\n", mnt_ns, rv);
+	return rv;
+}
+
+int kstate_collect_all_mnt_ns(struct kstate_context *ctx)
+{
+	struct kstate_object *obj;
+	int rv;
+
+	for_each_kstate_object(ctx, obj, KSTATE_CTX_NSPROXY) {
+		struct nsproxy *nsproxy = obj->o_obj;
+
+		rv = collect_mnt_ns(ctx, nsproxy->mnt_ns);
+		if (rv < 0)
+			return rv;
+	}
+	for_each_kstate_object(ctx, obj, KSTATE_CTX_MNT_NS) {
+		struct mnt_namespace *mnt_ns = obj->o_obj;
+		unsigned int cnt = atomic_read(&mnt_ns->count);
+
+		if (obj->o_count + 1 != cnt) {
+			pr_err("mnt_ns %p has external references %lu:%u\n", mnt_ns, obj->o_count, cnt);
+			return -EINVAL;
+		}
+	}
+	return 0;
+}
+
+static int dump_mnt_ns(struct kstate_context *ctx, struct kstate_object *obj)
+{
+	struct mnt_namespace *mnt_ns = obj->o_obj;
+	struct kstate_image_mnt_ns *i;
+	int rv;
+
+	i = kstate_prepare_image(KSTATE_OBJ_MNT_NS, sizeof(*i));
+	if (!i)
+		return -ENOMEM;
+
+	rv = kstate_write_image(ctx, i, sizeof(*i), obj);
+	kfree(i);
+	pr_debug("dump mnt_ns %p: ref {%llu, %u}, rv %d\n", mnt_ns, (unsigned long long)obj->o_ref.pos, obj->o_ref.id, rv);
+	return rv;
+}
+
+int kstate_dump_all_mnt_ns(struct kstate_context *ctx)
+{
+	struct kstate_object *obj;
+	int rv;
+
+	for_each_kstate_object(ctx, obj, KSTATE_CTX_MNT_NS) {
+		rv = dump_mnt_ns(ctx, obj);
+		if (rv < 0)
+			return rv;
+	}
+	return 0;
+}
+
+/* FIXME kstate_restore_mnt_ns() */
+#endif
include/linux/kstate-image.h +6 -0
index 43a1458..fa4921b 100644
@@ -46,6 +46,7 @@ struct kstate_image_header {
 #define KSTATE_OBJ_NSPROXY	6
 #define KSTATE_OBJ_UTS_NS	7
 #define KSTATE_OBJ_IPC_NS	8
+#define KSTATE_OBJ_MNT_NS	9
 
 struct kstate_object_header {
 	__u32		obj_type;
@@ -213,6 +214,7 @@ struct kstate_image_nsproxy {
 
 	kstate_ref_t	ref_uts_ns;
 	kstate_ref_t	ref_ipc_ns;	/* KSTATE_REF_UNDEF if IPC_NS=n */
+	kstate_ref_t	ref_mnt_ns;
 } __packed;
 
 struct kstate_image_uts_ns {
@@ -229,4 +231,8 @@ struct kstate_image_uts_ns {
 struct kstate_image_ipc_ns {
 	struct kstate_object_header hdr;
 } __packed;
+
+struct kstate_image_mnt_ns {
+	struct kstate_object_header hdr;
+} __packed;
 #endif
include/linux/kstate.h +4 -0
index 61bed98..43e2556 100644
@@ -26,6 +26,7 @@ enum kstate_context_obj_type {
 	KSTATE_CTX_IPC_NS,
 #endif
 	KSTATE_CTX_MM_STRUCT,
+	KSTATE_CTX_MNT_NS,
 	KSTATE_CTX_NSPROXY,
 	KSTATE_CTX_TASK_STRUCT,
 	KSTATE_CTX_UTS_NS,
@@ -96,6 +97,9 @@ static inline int kstate_dump_all_ipc_ns(struct kstate_context *ctx)
 }
 #endif
 
+int kstate_collect_all_mnt_ns(struct kstate_context *ctx);
+int kstate_dump_all_mnt_ns(struct kstate_context *ctx);
+
 #if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
 extern const __u32 kstate_kernel_arch;
 int kstate_arch_check_image_header(struct kstate_image_header *i);
kernel/kstate/cpt-sys.c +6 -0
index 1b03de5..0e3c74c 100644
@@ -74,6 +74,9 @@ static int kstate_collect(struct kstate_context *ctx)
 	rv = kstate_collect_all_ipc_ns(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_collect_all_mnt_ns(ctx);
+	if (rv < 0)
+		return rv;
 	rv = kstate_collect_all_mm_struct(ctx);
 	if (rv < 0)
 		return rv;
@@ -136,6 +139,9 @@ static int kstate_dump(struct kstate_context *ctx)
 	rv = kstate_dump_all_mm_struct(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_dump_all_mnt_ns(ctx);
+	if (rv < 0)
+		return rv;
 	rv = kstate_dump_all_ipc_ns(ctx);
 	if (rv < 0)
 		return rv;
kernel/kstate/kstate-context.c +6 -0
index c2449d5..700c0f4 100644
@@ -2,6 +2,7 @@
 #include <linux/file.h>
 #include <linux/ipc_namespace.h>
 #include <linux/list.h>
+#include <linux/mnt_namespace.h>
 #include <linux/nsproxy.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
@@ -50,6 +51,11 @@ void kstate_context_destroy(struct kstate_context *ctx)
 		list_del(&obj->o_list);
 		kfree(obj);
 	}
+	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_MNT_NS) {
+		put_mnt_ns((struct mnt_namespace *)obj->o_obj);
+		list_del(&obj->o_list);
+		kfree(obj);
+	}
 	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_NSPROXY) {
 		put_nsproxy((struct nsproxy *)obj->o_obj);
 		list_del(&obj->o_list);
kernel/kstate/kstate-object.c +4 -0
index 0056572..6b1ab4a 100644
@@ -2,6 +2,7 @@
 #include <linux/fs.h>
 #include <linux/ipc_namespace.h>
 #include <linux/mm_types.h>
+#include <linux/mnt_namespace.h>
 #include <linux/nsproxy.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
@@ -43,6 +44,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_conte
 	case KSTATE_CTX_MM_STRUCT:
 		atomic_inc(&((struct mm_struct *)obj->o_obj)->mm_users);
 		break;
+	case KSTATE_CTX_MNT_NS:
+		get_mnt_ns((struct mnt_namespace *)obj->o_obj);
+		break;
 	case KSTATE_CTX_NSPROXY:
 		get_nsproxy((struct nsproxy *)obj->o_obj);
 		break;
kernel/nsproxy.c +19 -5
index 7cb82e3..4e22ec4 100644
@@ -286,6 +286,8 @@ static int dump_nsproxy(struct kstate_context *ctx, struct kstate_object *obj)
 #else
 	i->ref_ipc_ns = KSTATE_REF_UNDEF;
 #endif
+	tmp = find_kstate_obj_by_ptr(ctx, nsproxy->mnt_ns, KSTATE_CTX_MNT_NS);
+	i->ref_mnt_ns = tmp->o_ref;
 
 	rv = kstate_write_image(ctx, i, sizeof(*i), obj);
 	kfree(i);
@@ -373,11 +375,22 @@ static int restore_ipc_ns(struct kstate_context *ctx, kstate_ref_t *ref, struct
 }
 #endif
 
+static int restore_mnt_ns(struct kstate_context *ctx, kstate_ref_t *ref, struct nsproxy *nsproxy)
+{
+	struct mnt_namespace *mnt_ns;
+
+	/* FIXME */
+	mnt_ns = ctx->init_tsk->nsproxy->mnt_ns;
+
+	get_mnt_ns(mnt_ns);
+	nsproxy->mnt_ns = mnt_ns;
+	return 0;
+}
+
 int kstate_restore_nsproxy(struct kstate_context *ctx, kstate_ref_t *ref)
 {
 	struct kstate_image_nsproxy *i;
 	struct nsproxy *nsproxy;
-	struct mnt_namespace *mnt_ns;
 	struct pid_namespace *pid_ns;
 #ifdef CONFIG_NET_NS
 	struct net *net_ns;
@@ -400,10 +413,9 @@ int kstate_restore_nsproxy(struct kstate_context *ctx, kstate_ref_t *ref)
 	rv = restore_ipc_ns(ctx, &i->ref_ipc_ns, nsproxy);
 	if (rv < 0)
 		goto out_ipc_ns;
-
-	mnt_ns = ctx->init_tsk->nsproxy->mnt_ns;
-	get_mnt_ns(mnt_ns);
-	nsproxy->mnt_ns = mnt_ns;
+	rv = restore_mnt_ns(ctx, &i->ref_mnt_ns, nsproxy);
+	if (rv < 0)
+		goto out_mnt_ns;
 
 	pid_ns = ctx->init_tsk->nsproxy->pid_ns;
 	nsproxy->pid_ns = get_pid_ns(pid_ns);
@@ -420,6 +432,8 @@ int kstate_restore_nsproxy(struct kstate_context *ctx, kstate_ref_t *ref)
 	pr_debug("restore nsproxy %p, ref {%llu, %u}, rv %d\n", nsproxy, (unsigned long long)ref->pos, ref->id, rv);
 	return rv;
 
+out_mnt_ns:
+	put_ipc_ns(nsproxy->ipc_ns);
 out_ipc_ns:
 	put_uts_ns(nsproxy->uts_ns);
 out_uts_ns:
Signature · 1 line
1.5.6.5
#154 lore raw

PATCH 30/38 C/R: checkpoint/restore struct pid_namespace

In reply to Alexey Dobriyan

pidns are hierarchical, so we dump parent pidns first. On restore, parent task is restored first and restores parent pidns for itself, which means that when child restores its pidns, parent pidns already exists.

This fullfills loop protection and, given, every pidns has init task which pins it even works reliably. :-)

---
 include/linux/kstate-image.h   |    9 ++
 include/linux/kstate.h         |    5 +
 kernel/kstate/cpt-sys.c        |    6 ++
 kernel/kstate/kstate-context.c |    6 ++
 kernel/kstate/kstate-object.c  |    4 +
 kernel/nsproxy.c               |   30 ++++++-
 kernel/pid_namespace.c         |  168 +++++++++++++++++++++++++++++++++++++++-
 7 files changed, 223 insertions(+), 5 deletions(-)
include/linux/kstate-image.h +9 -0
index fa4921b..64328e1 100644
@@ -47,6 +47,7 @@ struct kstate_image_header {
 #define KSTATE_OBJ_UTS_NS	7
 #define KSTATE_OBJ_IPC_NS	8
 #define KSTATE_OBJ_MNT_NS	9
+#define KSTATE_OBJ_PID_NS	10
 
 struct kstate_object_header {
 	__u32		obj_type;
@@ -215,6 +216,7 @@ struct kstate_image_nsproxy {
 	kstate_ref_t	ref_uts_ns;
 	kstate_ref_t	ref_ipc_ns;	/* KSTATE_REF_UNDEF if IPC_NS=n */
 	kstate_ref_t	ref_mnt_ns;
+	kstate_ref_t	ref_pid_ns;
 } __packed;
 
 struct kstate_image_uts_ns {
@@ -235,4 +237,11 @@ struct kstate_image_ipc_ns {
 struct kstate_image_mnt_ns {
 	struct kstate_object_header hdr;
 } __packed;
+
+struct kstate_image_pid_ns {
+	struct kstate_object_header hdr;
+
+	kstate_ref_t	ref_parent;	/* KSTATE_REF_UNDEF if root pid_ns */
+	__u32		last_pid;
+} __packed;
 #endif
include/linux/kstate.h +5 -0
index 43e2556..c925cef 100644
@@ -28,6 +28,7 @@ enum kstate_context_obj_type {
 	KSTATE_CTX_MM_STRUCT,
 	KSTATE_CTX_MNT_NS,
 	KSTATE_CTX_NSPROXY,
+	KSTATE_CTX_PID_NS,
 	KSTATE_CTX_TASK_STRUCT,
 	KSTATE_CTX_UTS_NS,
 	NR_KSTATE_CTX_TYPES
@@ -100,6 +101,10 @@ static inline int kstate_dump_all_ipc_ns(struct kstate_context *ctx)
 int kstate_collect_all_mnt_ns(struct kstate_context *ctx);
 int kstate_dump_all_mnt_ns(struct kstate_context *ctx);
 
+int kstate_collect_all_pid_ns(struct kstate_context *ctx);
+int kstate_dump_all_pid_ns(struct kstate_context *ctx);
+int kstate_restore_pid_ns(struct kstate_context *ctx, kstate_ref_t *ref);
+
 #if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
 extern const __u32 kstate_kernel_arch;
 int kstate_arch_check_image_header(struct kstate_image_header *i);
kernel/kstate/cpt-sys.c +6 -0
index 0e3c74c..cbaf038 100644
@@ -77,6 +77,9 @@ static int kstate_collect(struct kstate_context *ctx)
 	rv = kstate_collect_all_mnt_ns(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_collect_all_pid_ns(ctx);
+	if (rv < 0)
+		return rv;
 	rv = kstate_collect_all_mm_struct(ctx);
 	if (rv < 0)
 		return rv;
@@ -133,6 +136,9 @@ static int kstate_dump(struct kstate_context *ctx)
 	rv = kstate_dump_image_header(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_dump_all_pid_ns(ctx);
+	if (rv < 0)
+		return rv;
 	rv = kstate_dump_all_file(ctx);
 	if (rv < 0)
 		return rv;
kernel/kstate/kstate-context.c +6 -0
index 700c0f4..7cd1f45 100644
@@ -4,6 +4,7 @@
 #include <linux/list.h>
 #include <linux/mnt_namespace.h>
 #include <linux/nsproxy.h>
+#include <linux/pid_namespace.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/utsname.h>
@@ -61,6 +62,11 @@ void kstate_context_destroy(struct kstate_context *ctx)
 		list_del(&obj->o_list);
 		kfree(obj);
 	}
+	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_PID_NS) {
+		put_pid_ns((struct pid_namespace *)obj->o_obj);
+		list_del(&obj->o_list);
+		kfree(obj);
+	}
 	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_TASK_STRUCT) {
 		put_task_struct((struct task_struct *)obj->o_obj);
 		list_del(&obj->o_list);
kernel/kstate/kstate-object.c +4 -0
index 6b1ab4a..13bb75c 100644
@@ -4,6 +4,7 @@
 #include <linux/mm_types.h>
 #include <linux/mnt_namespace.h>
 #include <linux/nsproxy.h>
+#include <linux/pid_namespace.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/utsname.h>
@@ -50,6 +51,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_conte
 	case KSTATE_CTX_NSPROXY:
 		get_nsproxy((struct nsproxy *)obj->o_obj);
 		break;
+	case KSTATE_CTX_PID_NS:
+		get_pid_ns((struct pid_namespace *)obj->o_obj);
+		break;
 	case KSTATE_CTX_TASK_STRUCT:
 		get_task_struct((struct task_struct *)obj->o_obj);
 		break;
kernel/nsproxy.c +26 -4
index 4e22ec4..0b1f66d 100644
@@ -288,6 +288,8 @@ static int dump_nsproxy(struct kstate_context *ctx, struct kstate_object *obj)
 #endif
 	tmp = find_kstate_obj_by_ptr(ctx, nsproxy->mnt_ns, KSTATE_CTX_MNT_NS);
 	i->ref_mnt_ns = tmp->o_ref;
+	tmp = find_kstate_obj_by_ptr(ctx, nsproxy->pid_ns, KSTATE_CTX_PID_NS);
+	i->ref_pid_ns = tmp->o_ref;
 
 	rv = kstate_write_image(ctx, i, sizeof(*i), obj);
 	kfree(i);
@@ -387,11 +389,29 @@ static int restore_mnt_ns(struct kstate_context *ctx, kstate_ref_t *ref, struct
 	return 0;
 }
 
+static int restore_pid_ns(struct kstate_context *ctx, kstate_ref_t *ref, struct nsproxy *nsproxy)
+{
+	struct pid_namespace *pid_ns;
+	struct kstate_object *tmp;
+	int rv;
+
+	tmp = find_kstate_obj_by_ref(ctx, ref, KSTATE_CTX_PID_NS);
+	if (!tmp) {
+		rv = kstate_restore_pid_ns(ctx, ref);
+		if (rv < 0)
+			return rv;
+		tmp = find_kstate_obj_by_ref(ctx, ref, KSTATE_CTX_PID_NS);
+	}
+	pid_ns = tmp->o_obj;
+
+	nsproxy->pid_ns = get_pid_ns(pid_ns);
+	return 0;
+}
+
 int kstate_restore_nsproxy(struct kstate_context *ctx, kstate_ref_t *ref)
 {
 	struct kstate_image_nsproxy *i;
 	struct nsproxy *nsproxy;
-	struct pid_namespace *pid_ns;
 #ifdef CONFIG_NET_NS
 	struct net *net_ns;
 #endif
@@ -416,9 +436,9 @@ int kstate_restore_nsproxy(struct kstate_context *ctx, kstate_ref_t *ref)
 	rv = restore_mnt_ns(ctx, &i->ref_mnt_ns, nsproxy);
 	if (rv < 0)
 		goto out_mnt_ns;
-
-	pid_ns = ctx->init_tsk->nsproxy->pid_ns;
-	nsproxy->pid_ns = get_pid_ns(pid_ns);
+	rv = restore_pid_ns(ctx, &i->ref_pid_ns, nsproxy);
+	if (rv < 0)
+		goto out_pid_ns;
 
 #ifdef CONFIG_NET_NS
 	net_ns = ctx->init_tsk->nsproxy->net_ns;
@@ -432,6 +452,8 @@ int kstate_restore_nsproxy(struct kstate_context *ctx, kstate_ref_t *ref)
 	pr_debug("restore nsproxy %p, ref {%llu, %u}, rv %d\n", nsproxy, (unsigned long long)ref->pos, ref->id, rv);
 	return rv;
 
+out_pid_ns:
+	put_mnt_ns(nsproxy->mnt_ns);
 out_mnt_ns:
 	put_ipc_ns(nsproxy->ipc_ns);
 out_ipc_ns:
kernel/pid_namespace.c +167 -1

181 lines not on this page · raw message

Signature · 1 line
1.5.6.5
#155 lore raw

PATCH 31/38 C/R: formally checkpoint/restore struct net_namespace

In reply to Alexey Dobriyan
---
 include/linux/kstate-image.h   |    6 ++
 include/linux/kstate.h         |   19 +++++++
 include/net/net_namespace.h    |    1 +
 kernel/kstate/cpt-sys.c        |    6 ++
 kernel/kstate/kstate-context.c |    8 +++
 kernel/kstate/kstate-object.c  |    6 ++
 kernel/nsproxy.c               |   66 +++++++++++++++++++++++---
 net/core/net_namespace.c       |  102 +++++++++++++++++++++++++++++++++++++++-
 8 files changed, 205 insertions(+), 9 deletions(-)
include/linux/kstate-image.h +6 -0
index 64328e1..8119f2b 100644
@@ -48,6 +48,7 @@ struct kstate_image_header {
 #define KSTATE_OBJ_IPC_NS	8
 #define KSTATE_OBJ_MNT_NS	9
 #define KSTATE_OBJ_PID_NS	10
+#define KSTATE_OBJ_NET_NS	11
 
 struct kstate_object_header {
 	__u32		obj_type;
@@ -217,6 +218,7 @@ struct kstate_image_nsproxy {
 	kstate_ref_t	ref_ipc_ns;	/* KSTATE_REF_UNDEF if IPC_NS=n */
 	kstate_ref_t	ref_mnt_ns;
 	kstate_ref_t	ref_pid_ns;
+	kstate_ref_t	ref_net_ns;	/* KSTATE_REF_UNDEF if NET_NS=n */
 } __packed;
 
 struct kstate_image_uts_ns {
@@ -244,4 +246,8 @@ struct kstate_image_pid_ns {
 	kstate_ref_t	ref_parent;	/* KSTATE_REF_UNDEF if root pid_ns */
 	__u32		last_pid;
 } __packed;
+
+struct kstate_image_net_ns {
+	struct kstate_object_header hdr;
+} __packed;
 #endif
include/linux/kstate.h +19 -0
index c925cef..a2bea1a 100644
@@ -27,6 +27,9 @@ enum kstate_context_obj_type {
 #endif
 	KSTATE_CTX_MM_STRUCT,
 	KSTATE_CTX_MNT_NS,
+#ifdef CONFIG_NET_NS
+	KSTATE_CTX_NET_NS,
+#endif
 	KSTATE_CTX_NSPROXY,
 	KSTATE_CTX_PID_NS,
 	KSTATE_CTX_TASK_STRUCT,
@@ -105,6 +108,22 @@ int kstate_collect_all_pid_ns(struct kstate_context *ctx);
 int kstate_dump_all_pid_ns(struct kstate_context *ctx);
 int kstate_restore_pid_ns(struct kstate_context *ctx, kstate_ref_t *ref);
 
+#ifdef CONFIG_NET_NS
+int kstate_collect_all_net_ns(struct kstate_context *ctx);
+int kstate_dump_all_net_ns(struct kstate_context *ctx);
+int kstate_restore_net_ns(struct kstate_context *ctx, kstate_ref_t *ref);
+#else
+static inline int kstate_collect_all_net_ns(struct kstate_context *ctx)
+{
+	return 0;
+}
+
+static inline int kstate_dump_all_net_ns(struct kstate_context *ctx)
+{
+	return 0;
+}
+#endif
+
 #if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
 extern const __u32 kstate_kernel_arch;
 int kstate_arch_check_image_header(struct kstate_image_header *i);
include/net/net_namespace.h +1 -0
index ded434b..a48e765 100644
@@ -107,6 +107,7 @@ static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
 extern struct list_head net_namespace_list;
 
 #ifdef CONFIG_NET_NS
+extern struct net *net_create(void);
 extern void __put_net(struct net *net);
 
 static inline struct net *get_net(struct net *net)
kernel/kstate/cpt-sys.c +6 -0
index cbaf038..620998a 100644
@@ -80,6 +80,9 @@ static int kstate_collect(struct kstate_context *ctx)
 	rv = kstate_collect_all_pid_ns(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_collect_all_net_ns(ctx);
+	if (rv < 0)
+		return rv;
 	rv = kstate_collect_all_mm_struct(ctx);
 	if (rv < 0)
 		return rv;
@@ -145,6 +148,9 @@ static int kstate_dump(struct kstate_context *ctx)
 	rv = kstate_dump_all_mm_struct(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_dump_all_net_ns(ctx);
+	if (rv < 0)
+		return rv;
 	rv = kstate_dump_all_mnt_ns(ctx);
 	if (rv < 0)
 		return rv;
kernel/kstate/kstate-context.c +8 -0
index 7cd1f45..423b45b 100644
@@ -8,6 +8,7 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/utsname.h>
+#include <net/net_namespace.h>
 
 #include <linux/kstate.h>
 
@@ -57,6 +58,13 @@ void kstate_context_destroy(struct kstate_context *ctx)
 		list_del(&obj->o_list);
 		kfree(obj);
 	}
+#ifdef CONFIG_NET_NS
+	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_NET_NS) {
+		put_net((struct net *)obj->o_obj);
+		list_del(&obj->o_list);
+		kfree(obj);
+	}
+#endif
 	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_NSPROXY) {
 		put_nsproxy((struct nsproxy *)obj->o_obj);
 		list_del(&obj->o_list);
kernel/kstate/kstate-object.c +6 -0
index 13bb75c..d9b36fa 100644
@@ -8,6 +8,7 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/utsname.h>
+#include <net/net_namespace.h>
 
 #include <linux/kstate.h>
 #include <linux/kstate-image.h>
@@ -48,6 +49,11 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_conte
 	case KSTATE_CTX_MNT_NS:
 		get_mnt_ns((struct mnt_namespace *)obj->o_obj);
 		break;
+#ifdef CONFIG_NET_NS
+	case KSTATE_CTX_NET_NS:
+		get_net((struct net *)obj->o_obj);
+		break;
+#endif
 	case KSTATE_CTX_NSPROXY:
 		get_nsproxy((struct nsproxy *)obj->o_obj);
 		break;
kernel/nsproxy.c +58 -8

94 lines not on this page · raw message

net/core/net_namespace.c +101 -1

119 lines not on this page · raw message

Signature · 1 line
1.5.6.5
#156 lore raw

PATCH 32/38 C/R: checkpoint/restore struct cred

In reply to Alexey Dobriyan

->group_info, ->user will be done in next patches

FIXME: insufficient checks for capabilities at least.

---
 include/linux/kstate-image.h   |   25 ++++++
 include/linux/kstate.h         |    5 +
 kernel/cred.c                  |  164 ++++++++++++++++++++++++++++++++++++++++
 kernel/kstate/cpt-sys.c        |    6 ++
 kernel/kstate/kstate-context.c |    5 +
 kernel/kstate/kstate-file.c    |   30 +++++++
 kernel/kstate/kstate-object.c  |    3 +
 kernel/kstate/kstate-task.c    |   55 +++++++++++++
 8 files changed, 293 insertions(+), 0 deletions(-)
include/linux/kstate-image.h +25 -0
index 8119f2b..3e768ca 100644
@@ -49,6 +49,7 @@ struct kstate_image_header {
 #define KSTATE_OBJ_MNT_NS	9
 #define KSTATE_OBJ_PID_NS	10
 #define KSTATE_OBJ_NET_NS	11
+#define KSTATE_OBJ_CRED		12
 
 struct kstate_object_header {
 	__u32		obj_type;
@@ -73,6 +74,9 @@ struct kstate_image_task_struct {
 	kstate_ref_t	ref_mm;
 	kstate_ref_t	ref_nsproxy;
 
+	kstate_ref_t	ref_real_cred;
+	kstate_ref_t	ref_cred;
+
 	__u8		comm[16];
 
 	/* Native arch of task, one of KSTATE_ARCH_*. */
@@ -207,6 +211,7 @@ struct kstate_image_file {
 	__u32		i_mode;
 	__u32		f_flags;
 	__u64		f_pos;
+	kstate_ref_t	ref_f_cred;
 	__u32		name_len;	/* including NUL */
 	/* __u8	name[name_len] */
 } __packed;
@@ -250,4 +255,24 @@ struct kstate_image_pid_ns {
 struct kstate_image_net_ns {
 	struct kstate_object_header hdr;
 } __packed;
+
+typedef __u64 kstate_cap_t;
+struct kstate_image_cred {
+	struct kstate_object_header hdr;
+
+	__u32		uid;
+	__u32		gid;
+	__u32		suid;
+	__u32		sgid;
+	__u32		euid;
+	__u32		egid;
+	__u32		fsuid;
+	__u32		fsgid;
+	__u32		securebits;
+
+	kstate_cap_t	cap_inheritable;
+	kstate_cap_t	cap_permitted;
+	kstate_cap_t	cap_effective;
+	kstate_cap_t	cap_bset;
+} __packed;
 #endif
include/linux/kstate.h +5 -0
index a2bea1a..bbed87b 100644
@@ -21,6 +21,7 @@ struct kstate_object {
 
 /* Not visible to userspace! */
 enum kstate_context_obj_type {
+	KSTATE_CTX_CRED,
 	KSTATE_CTX_FILE,
 #ifdef CONFIG_IPC_NS
 	KSTATE_CTX_IPC_NS,
@@ -124,6 +125,10 @@ static inline int kstate_dump_all_net_ns(struct kstate_context *ctx)
 }
 #endif
 
+int kstate_collect_all_cred(struct kstate_context *ctx);
+int kstate_dump_all_cred(struct kstate_context *ctx);
+int kstate_restore_cred(struct kstate_context *ctx, kstate_ref_t *ref);
+
 #if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
 extern const __u32 kstate_kernel_arch;
 int kstate_arch_check_image_header(struct kstate_image_header *i);
kernel/cred.c +164 -0

173 lines not on this page · raw message

kernel/kstate/cpt-sys.c +6 -0
index 620998a..b990fd3 100644
@@ -89,6 +89,9 @@ static int kstate_collect(struct kstate_context *ctx)
 	rv = kstate_collect_all_file(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_collect_all_cred(ctx);
+	if (rv < 0)
+		return rv;
 	return 0;
 }
 
@@ -142,6 +145,9 @@ static int kstate_dump(struct kstate_context *ctx)
 	rv = kstate_dump_all_pid_ns(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_dump_all_cred(ctx);
+	if (rv < 0)
+		return rv;
 	rv = kstate_dump_all_file(ctx);
 	if (rv < 0)
 		return rv;
kernel/kstate/kstate-context.c +5 -0
index 423b45b..01b6e5f 100644
@@ -36,6 +36,11 @@ void kstate_context_destroy(struct kstate_context *ctx)
 {
 	struct kstate_object *obj, *tmp;
 
+	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_CRED) {
+		put_cred((struct cred *)obj->o_obj);
+		list_del(&obj->o_list);
+		kfree(obj);
+	}
 	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_FILE) {
 		fput((struct file *)obj->o_obj);
 		list_del(&obj->o_list);
kernel/kstate/kstate-file.c +30 -0
index 8f678cd..f378be3 100644
@@ -86,6 +86,7 @@ int generic_file_checkpoint(struct file *file, struct kstate_context *ctx)
 {
 	struct kstate_object *obj;
 	struct kstate_image_file *i;
+	struct kstate_object *tmp;
 	struct kstat stat;
 	char *buf, *name;
 	int rv;
@@ -102,6 +103,9 @@ int generic_file_checkpoint(struct file *file, struct kstate_context *ctx)
 	/* Assume seeking over file doesn't have history. */
 	i->f_pos = file->f_pos;
 
+	tmp = find_kstate_obj_by_ptr(ctx, file->f_cred, KSTATE_CTX_CRED);
+	i->ref_f_cred = tmp->o_ref;
+
 	buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
 	if (!buf) {
 		rv = -ENOMEM;
@@ -154,6 +158,28 @@ int kstate_dump_all_file(struct kstate_context *ctx)
 	return 0;
 }
 
+static int file_restore_cred(struct kstate_context *ctx, kstate_ref_t *ref, struct file *file)
+{
+	struct cred *cred;
+	const struct cred *old_cred;
+	struct kstate_object *tmp;
+	int rv;
+
+	tmp = find_kstate_obj_by_ref(ctx, ref, KSTATE_CTX_CRED);
+	if (!tmp) {
+		rv = kstate_restore_cred(ctx, ref);
+		if (rv < 0)
+			return rv;
+		tmp = find_kstate_obj_by_ref(ctx, ref, KSTATE_CTX_CRED);
+	}
+	cred = tmp->o_obj;
+
+	old_cred = file->f_cred;
+	rcu_assign_pointer(file->f_cred, get_cred(cred));
+	put_cred(old_cred);
+	return 0;
+}
+
 int kstate_restore_file(struct kstate_context *ctx, kstate_ref_t *ref)
 {
 	struct kstate_image_file *i;
@@ -182,6 +208,10 @@ int kstate_restore_file(struct kstate_context *ctx, kstate_ref_t *ref)
 		rv = -EINVAL;
 		goto out_fput;
 	}
+
+	rv = file_restore_cred(ctx, &i->ref_f_cred, file);
+	if (rv < 0)
+		goto out_fput;
 	/* Assume seeking over file doesn't have history. */
 	if (vfs_llseek(file, i->f_pos, SEEK_SET) != i->f_pos) {
 		rv = -EINVAL;
kernel/kstate/kstate-object.c +3 -0
index d9b36fa..8000124 100644
@@ -35,6 +35,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_conte
 	list_add_tail(&obj->o_list, &ctx->obj[type]);
 
 	switch (type) {
+	case KSTATE_CTX_CRED:
+		get_cred((struct cred *)obj->o_obj);
+		break;
 	case KSTATE_CTX_FILE:
 		get_file((struct file *)obj->o_obj);
 		break;
kernel/kstate/kstate-task.c +55 -0

73 lines not on this page · raw message

Signature · 1 line
1.5.6.5
#157 lore raw

PATCH 33/38 C/R: checkpoint/restore aux groups (structy group_info)

In reply to Alexey Dobriyan
---
 include/linux/kstate-image.h   |   10 +++
 include/linux/kstate.h         |    5 ++
 kernel/cred.c                  |   30 +++++++++-
 kernel/groups.c                |  125 ++++++++++++++++++++++++++++++++++++++++
 kernel/kstate/cpt-sys.c        |    6 ++
 kernel/kstate/kstate-context.c |    5 ++
 kernel/kstate/kstate-object.c  |    3 +
 7 files changed, 182 insertions(+), 2 deletions(-)
include/linux/kstate-image.h +10 -0
index 3e768ca..dfd71ea 100644
@@ -50,6 +50,7 @@ struct kstate_image_header {
 #define KSTATE_OBJ_PID_NS	10
 #define KSTATE_OBJ_NET_NS	11
 #define KSTATE_OBJ_CRED		12
+#define KSTATE_OBJ_GROUP_INFO	13
 
 struct kstate_object_header {
 	__u32		obj_type;
@@ -274,5 +275,14 @@ struct kstate_image_cred {
 	kstate_cap_t	cap_permitted;
 	kstate_cap_t	cap_effective;
 	kstate_cap_t	cap_bset;
+
+	kstate_ref_t	ref_group_info;
+} __packed;
+
+struct kstate_image_group_info {
+	struct kstate_object_header hdr;
+
+	__u32		ngroups;
+	/* __u32	gid[ngroups]; */
 } __packed;
 #endif
include/linux/kstate.h +5 -0
index bbed87b..4df3bfa 100644
@@ -23,6 +23,7 @@ struct kstate_object {
 enum kstate_context_obj_type {
 	KSTATE_CTX_CRED,
 	KSTATE_CTX_FILE,
+	KSTATE_CTX_GROUP_INFO,
 #ifdef CONFIG_IPC_NS
 	KSTATE_CTX_IPC_NS,
 #endif
@@ -129,6 +130,10 @@ int kstate_collect_all_cred(struct kstate_context *ctx);
 int kstate_dump_all_cred(struct kstate_context *ctx);
 int kstate_restore_cred(struct kstate_context *ctx, kstate_ref_t *ref);
 
+int kstate_collect_all_group_info(struct kstate_context *ctx);
+int kstate_dump_all_group_info(struct kstate_context *ctx);
+int kstate_restore_group_info(struct kstate_context *ctx, kstate_ref_t *ref);
+
 #if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
 extern const __u32 kstate_kernel_arch;
 int kstate_arch_check_image_header(struct kstate_image_header *i);
kernel/cred.c +28 -2
index 9152c90..8543360 100644
@@ -662,6 +662,7 @@ static int dump_cred(struct kstate_context *ctx, struct kstate_object *obj)
 {
 	struct cred *cred = obj->o_obj;
 	struct kstate_image_cred *i;
+	struct kstate_object *tmp;
 	int rv;
 
 	i = kstate_prepare_image(KSTATE_OBJ_CRED, sizeof(*i));
@@ -684,6 +685,9 @@ static int dump_cred(struct kstate_context *ctx, struct kstate_object *obj)
 	memcpy(&i->cap_effective, &cred->cap_effective, sizeof(kstate_cap_t));
 	memcpy(&i->cap_bset, &cred->cap_bset, sizeof(kstate_cap_t));
 
+	tmp = find_kstate_obj_by_ptr(ctx, cred->group_info, KSTATE_CTX_GROUP_INFO);
+	i->ref_group_info = tmp->o_ref;
+
 	rv = kstate_write_image(ctx, i, sizeof(*i), obj);
 	kfree(i);
 	pr_debug("dump cred %p: ref {%llu, %u}, rv %d\n", cred, (unsigned long long)obj->o_ref.pos, obj->o_ref.id, rv);
@@ -703,6 +707,25 @@ int kstate_dump_all_cred(struct kstate_context *ctx)
 	return 0;
 }
 
+static int restore_group_info(struct kstate_context *ctx, kstate_ref_t *ref, struct cred *cred)
+{
+	struct group_info *gi;
+	struct kstate_object *tmp;
+	int rv;
+
+	tmp = find_kstate_obj_by_ref(ctx, ref, KSTATE_CTX_GROUP_INFO);
+	if (!tmp) {
+		rv = kstate_restore_group_info(ctx, ref);
+		if (rv < 0)
+			return rv;
+		tmp = find_kstate_obj_by_ref(ctx, ref, KSTATE_CTX_GROUP_INFO);
+	}
+	gi = tmp->o_obj;
+
+	cred->group_info = get_group_info(gi);
+	return 0;
+}
+
 int kstate_restore_cred(struct kstate_context *ctx, kstate_ref_t *ref)
 {
 	struct kstate_image_cred *i;
@@ -735,8 +758,9 @@ int kstate_restore_cred(struct kstate_context *ctx, kstate_ref_t *ref)
 	memcpy(&cred->cap_effective, &i->cap_effective, sizeof(i->cap_effective));
 	memcpy(&cred->cap_bset, &i->cap_bset, sizeof(i->cap_bset));
 
-	/* FIXME */
-	cred->group_info = get_group_info(&init_groups);
+	rv = restore_group_info(ctx, &i->ref_group_info, cred);
+	if (rv < 0)
+		goto out_group_info;
 	/* FIXME */
 	cred->user = get_uid(&root_user);
 	kfree(i);
@@ -747,6 +771,8 @@ int kstate_restore_cred(struct kstate_context *ctx, kstate_ref_t *ref)
 	pr_debug("restore cred %p: ref {%llu, %u}, rv %d\n", cred, (unsigned long long)ref->pos, ref->id, rv);
 	return rv;
 
+out_group_info:
+	kmem_cache_free(cred_jar, cred);
 out_free_image:
 	kfree(i);
 	pr_debug("%s: return %d, ref {%llu, %u}\n", __func__, rv, (unsigned long long)ref->pos, ref->id);
kernel/groups.c +125 -0

133 lines not on this page · raw message

kernel/kstate/cpt-sys.c +6 -0
index b990fd3..1b352c8 100644
@@ -92,6 +92,9 @@ static int kstate_collect(struct kstate_context *ctx)
 	rv = kstate_collect_all_cred(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_collect_all_group_info(ctx);
+	if (rv < 0)
+		return rv;
 	return 0;
 }
 
@@ -145,6 +148,9 @@ static int kstate_dump(struct kstate_context *ctx)
 	rv = kstate_dump_all_pid_ns(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_dump_all_group_info(ctx);
+	if (rv < 0)
+		return rv;
 	rv = kstate_dump_all_cred(ctx);
 	if (rv < 0)
 		return rv;
kernel/kstate/kstate-context.c +5 -0
index 01b6e5f..51b28c0 100644
@@ -46,6 +46,11 @@ void kstate_context_destroy(struct kstate_context *ctx)
 		list_del(&obj->o_list);
 		kfree(obj);
 	}
+	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_GROUP_INFO) {
+		put_group_info((struct group_info *)obj->o_obj);
+		list_del(&obj->o_list);
+		kfree(obj);
+	}
 #ifdef CONFIG_IPC_NS
 	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_IPC_NS) {
 		put_ipc_ns((struct ipc_namespace *)obj->o_obj);
kernel/kstate/kstate-object.c +3 -0
index 8000124..f6ce7a2 100644
@@ -41,6 +41,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_conte
 	case KSTATE_CTX_FILE:
 		get_file((struct file *)obj->o_obj);
 		break;
+	case KSTATE_CTX_GROUP_INFO:
+		get_group_info((struct group_info *)obj->o_obj);
+		break;
 #ifdef CONFIG_IPC_NS
 	case KSTATE_CTX_IPC_NS:
 		get_ipc_ns((struct ipc_namespace *)obj->o_obj);
Signature · 1 line
1.5.6.5
#158 lore raw

PATCH 34/38 C/R: checkpoint/restore struct user

In reply to Alexey Dobriyan

Note, user_namespace is in next patch as well as ->creator loop issue.

---
 include/linux/kstate-image.h   |    8 +++
 include/linux/kstate.h         |    5 ++
 kernel/cred.c                  |   28 +++++++++-
 kernel/kstate/cpt-sys.c        |    6 ++
 kernel/kstate/kstate-context.c |    5 ++
 kernel/kstate/kstate-object.c  |    3 +
 kernel/user.c                  |  121 ++++++++++++++++++++++++++++++++++++++++
 7 files changed, 174 insertions(+), 2 deletions(-)
include/linux/kstate-image.h +8 -0
index dfd71ea..605a2b5 100644
@@ -51,6 +51,7 @@ struct kstate_image_header {
 #define KSTATE_OBJ_NET_NS	11
 #define KSTATE_OBJ_CRED		12
 #define KSTATE_OBJ_GROUP_INFO	13
+#define KSTATE_OBJ_USER_STRUCT	14
 
 struct kstate_object_header {
 	__u32		obj_type;
@@ -277,6 +278,7 @@ struct kstate_image_cred {
 	kstate_cap_t	cap_bset;
 
 	kstate_ref_t	ref_group_info;
+	kstate_ref_t	ref_user;
 } __packed;
 
 struct kstate_image_group_info {
@@ -285,4 +287,10 @@ struct kstate_image_group_info {
 	__u32		ngroups;
 	/* __u32	gid[ngroups]; */
 } __packed;
+
+struct kstate_image_user_struct {
+	struct kstate_object_header hdr;
+
+	__u32		uid;
+} __packed;
 #endif
include/linux/kstate.h +5 -0
index 4df3bfa..dd6b982 100644
@@ -35,6 +35,7 @@ enum kstate_context_obj_type {
 	KSTATE_CTX_NSPROXY,
 	KSTATE_CTX_PID_NS,
 	KSTATE_CTX_TASK_STRUCT,
+	KSTATE_CTX_USER_STRUCT,
 	KSTATE_CTX_UTS_NS,
 	NR_KSTATE_CTX_TYPES
 };
@@ -134,6 +135,10 @@ int kstate_collect_all_group_info(struct kstate_context *ctx);
 int kstate_dump_all_group_info(struct kstate_context *ctx);
 int kstate_restore_group_info(struct kstate_context *ctx, kstate_ref_t *ref);
 
+int kstate_collect_all_user_struct(struct kstate_context *ctx);
+int kstate_dump_all_user_struct(struct kstate_context *ctx);
+int kstate_restore_user_struct(struct kstate_context *ctx, kstate_ref_t *ref);
+
 #if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
 extern const __u32 kstate_kernel_arch;
 int kstate_arch_check_image_header(struct kstate_image_header *i);
kernel/cred.c +26 -2
index 8543360..a16f357 100644
@@ -687,6 +687,8 @@ static int dump_cred(struct kstate_context *ctx, struct kstate_object *obj)
 
 	tmp = find_kstate_obj_by_ptr(ctx, cred->group_info, KSTATE_CTX_GROUP_INFO);
 	i->ref_group_info = tmp->o_ref;
+	tmp = find_kstate_obj_by_ptr(ctx, cred->user, KSTATE_CTX_USER_STRUCT);
+	i->ref_user = tmp->o_ref;
 
 	rv = kstate_write_image(ctx, i, sizeof(*i), obj);
 	kfree(i);
@@ -726,6 +728,25 @@ static int restore_group_info(struct kstate_context *ctx, kstate_ref_t *ref, str
 	return 0;
 }
 
+static int restore_user(struct kstate_context *ctx, kstate_ref_t *ref, struct cred *cred)
+{
+	struct user_struct *user;
+	struct kstate_object *tmp;
+	int rv;
+
+	tmp = find_kstate_obj_by_ref(ctx, ref, KSTATE_CTX_USER_STRUCT);
+	if (!tmp) {
+		rv = kstate_restore_user_struct(ctx, ref);
+		if (rv < 0)
+			return rv;
+		tmp = find_kstate_obj_by_ref(ctx, ref, KSTATE_CTX_USER_STRUCT);
+	}
+	user = tmp->o_obj;
+
+	cred->user = get_uid(user);
+	return 0;
+}
+
 int kstate_restore_cred(struct kstate_context *ctx, kstate_ref_t *ref)
 {
 	struct kstate_image_cred *i;
@@ -761,8 +782,9 @@ int kstate_restore_cred(struct kstate_context *ctx, kstate_ref_t *ref)
 	rv = restore_group_info(ctx, &i->ref_group_info, cred);
 	if (rv < 0)
 		goto out_group_info;
-	/* FIXME */
-	cred->user = get_uid(&root_user);
+	rv = restore_user(ctx, &i->ref_user, cred);
+	if (rv < 0)
+		goto out_user;
 	kfree(i);
 
 	rv = kstate_restore_object(ctx, cred, KSTATE_CTX_CRED, ref);
@@ -771,6 +793,8 @@ int kstate_restore_cred(struct kstate_context *ctx, kstate_ref_t *ref)
 	pr_debug("restore cred %p: ref {%llu, %u}, rv %d\n", cred, (unsigned long long)ref->pos, ref->id, rv);
 	return rv;
 
+out_user:
+	put_group_info(cred->group_info);
 out_group_info:
 	kmem_cache_free(cred_jar, cred);
 out_free_image:
kernel/kstate/cpt-sys.c +6 -0
index 1b352c8..a409577 100644
@@ -95,6 +95,9 @@ static int kstate_collect(struct kstate_context *ctx)
 	rv = kstate_collect_all_group_info(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_collect_all_user_struct(ctx);
+	if (rv < 0)
+		return rv;
 	return 0;
 }
 
@@ -148,6 +151,9 @@ static int kstate_dump(struct kstate_context *ctx)
 	rv = kstate_dump_all_pid_ns(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_dump_all_user_struct(ctx);
+	if (rv < 0)
+		return rv;
 	rv = kstate_dump_all_group_info(ctx);
 	if (rv < 0)
 		return rv;
kernel/kstate/kstate-context.c +5 -0
index 51b28c0..854f971 100644
@@ -90,6 +90,11 @@ void kstate_context_destroy(struct kstate_context *ctx)
 		list_del(&obj->o_list);
 		kfree(obj);
 	}
+	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_USER_STRUCT) {
+		free_uid((struct user_struct *)obj->o_obj);
+		list_del(&obj->o_list);
+		kfree(obj);
+	}
 	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_UTS_NS) {
 		put_uts_ns((struct uts_namespace *)obj->o_obj);
 		list_del(&obj->o_list);
kernel/kstate/kstate-object.c +3 -0
index f6ce7a2..75facda 100644
@@ -69,6 +69,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_conte
 	case KSTATE_CTX_TASK_STRUCT:
 		get_task_struct((struct task_struct *)obj->o_obj);
 		break;
+	case KSTATE_CTX_USER_STRUCT:
+		get_uid((struct user_struct *)obj->o_obj);
+		break;
 	case KSTATE_CTX_UTS_NS:
 		get_uts_ns((struct uts_namespace *)obj->o_obj);
 		break;
kernel/user.c +121 -0

130 lines not on this page · raw message

Signature · 1 line
1.5.6.5
#159 lore raw

PATCH 35/38 C/R: checkpoint/restore struct user_namespace

In reply to Alexey Dobriyan

We have first loop -- user->user_ns->creator (which is struct user_struct)

user_ns image references ->creator image but only partially because user_namespaces are dumped before user_structs.

---
 include/linux/kstate-image.h   |   12 +++
 include/linux/kstate.h         |    5 ++
 kernel/kstate/cpt-sys.c        |    6 ++
 kernel/kstate/kstate-context.c |    6 ++
 kernel/kstate/kstate-object.c  |    4 +
 kernel/user.c                  |   21 +++++-
 kernel/user_namespace.c        |  146 ++++++++++++++++++++++++++++++++++++++++
 7 files changed, 198 insertions(+), 2 deletions(-)
 delete mode 100644 kernel/kstate/kstate-uts_ns.c
include/linux/kstate-image.h +12 -0
index 605a2b5..a573833 100644
@@ -52,6 +52,7 @@ struct kstate_image_header {
 #define KSTATE_OBJ_CRED		12
 #define KSTATE_OBJ_GROUP_INFO	13
 #define KSTATE_OBJ_USER_STRUCT	14
+#define KSTATE_OBJ_USER_NS	15
 
 struct kstate_object_header {
 	__u32		obj_type;
@@ -291,6 +292,17 @@ struct kstate_image_group_info {
 struct kstate_image_user_struct {
 	struct kstate_object_header hdr;
 
+	kstate_ref_t	ref_user_ns;
 	__u32		uid;
 } __packed;
+
+struct kstate_image_user_ns {
+	struct kstate_object_header hdr;
+
+	/*
+	 * KSTATE_REF_UNDEF if user_ns creator user was outside of container,
+	 * otherwise partial {0, id} reference.
+	 */
+	kstate_ref_t	ref_creator;
+} __packed;
 #endif
include/linux/kstate.h +5 -0
index dd6b982..f0c8e09 100644
@@ -35,6 +35,7 @@ enum kstate_context_obj_type {
 	KSTATE_CTX_NSPROXY,
 	KSTATE_CTX_PID_NS,
 	KSTATE_CTX_TASK_STRUCT,
+	KSTATE_CTX_USER_NS,
 	KSTATE_CTX_USER_STRUCT,
 	KSTATE_CTX_UTS_NS,
 	NR_KSTATE_CTX_TYPES
@@ -139,6 +140,10 @@ int kstate_collect_all_user_struct(struct kstate_context *ctx);
 int kstate_dump_all_user_struct(struct kstate_context *ctx);
 int kstate_restore_user_struct(struct kstate_context *ctx, kstate_ref_t *ref);
 
+int kstate_collect_all_user_ns(struct kstate_context *ctx);
+int kstate_dump_all_user_ns(struct kstate_context *ctx);
+int kstate_restore_user_ns(struct kstate_context *ctx, kstate_ref_t *ref);
+
 #if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
 extern const __u32 kstate_kernel_arch;
 int kstate_arch_check_image_header(struct kstate_image_header *i);
kernel/kstate/cpt-sys.c +6 -0
index a409577..3df776e 100644
@@ -98,6 +98,9 @@ static int kstate_collect(struct kstate_context *ctx)
 	rv = kstate_collect_all_user_struct(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_collect_all_user_ns(ctx);
+	if (rv < 0)
+		return rv;
 	return 0;
 }
 
@@ -151,6 +154,9 @@ static int kstate_dump(struct kstate_context *ctx)
 	rv = kstate_dump_all_pid_ns(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_dump_all_user_ns(ctx);
+	if (rv < 0)
+		return rv;
 	rv = kstate_dump_all_user_struct(ctx);
 	if (rv < 0)
 		return rv;
kernel/kstate/kstate-context.c +6 -0
index 854f971..f8168cc 100644
@@ -7,6 +7,7 @@
 #include <linux/pid_namespace.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
+#include <linux/user_namespace.h>
 #include <linux/utsname.h>
 #include <net/net_namespace.h>
 
@@ -90,6 +91,11 @@ void kstate_context_destroy(struct kstate_context *ctx)
 		list_del(&obj->o_list);
 		kfree(obj);
 	}
+	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_USER_NS) {
+		put_user_ns((struct user_namespace *)obj->o_obj);
+		list_del(&obj->o_list);
+		kfree(obj);
+	}
 	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_USER_STRUCT) {
 		free_uid((struct user_struct *)obj->o_obj);
 		list_del(&obj->o_list);
kernel/kstate/kstate-object.c +4 -0
index 75facda..eb77027 100644
@@ -7,6 +7,7 @@
 #include <linux/pid_namespace.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
+#include <linux/user_namespace.h>
 #include <linux/utsname.h>
 #include <net/net_namespace.h>
 
@@ -69,6 +70,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_conte
 	case KSTATE_CTX_TASK_STRUCT:
 		get_task_struct((struct task_struct *)obj->o_obj);
 		break;
+	case KSTATE_CTX_USER_NS:
+		get_user_ns((struct user_namespace *)obj->o_obj);
+		break;
 	case KSTATE_CTX_USER_STRUCT:
 		get_uid((struct user_struct *)obj->o_obj);
 		break;
kernel/kstate/kstate-uts_ns.c deleted +0 -0
deleted file mode 100644
index e69de29..0000000
kernel/user.c +19 -2
index 9fda1f0..508c05d 100644
@@ -554,6 +554,10 @@ int kstate_collect_all_user_struct(struct kstate_context *ctx)
 		if (rv < 0)
 			return rv;
 	}
+	/*
+	 * Don't check refcounts here, user_ns->creator references weren't
+	 * accounted yet, it will fire every time CLONE_NEWUSER is used.
+	 */
 	return 0;
 }
 
@@ -561,12 +565,15 @@ static int dump_user_struct(struct kstate_context *ctx, struct kstate_object *ob
 {
 	struct user_struct *user = obj->o_obj;
 	struct kstate_image_user_struct *i;
+	struct kstate_object *tmp;
 	int rv;
 
 	i = kstate_prepare_image(KSTATE_OBJ_USER_STRUCT, sizeof(*i));
 	if (!i)
 		return -ENOMEM;
 
+	tmp = find_kstate_obj_by_ptr(ctx, user->user_ns, KSTATE_CTX_USER_NS);
+	i->ref_user_ns = tmp->o_ref;
 	i->uid = user->uid;
 
 	rv = kstate_write_image(ctx, i, sizeof(*i), obj);
@@ -592,14 +599,24 @@ int kstate_restore_user_struct(struct kstate_context *ctx, kstate_ref_t *ref)
 {
 	struct kstate_image_user_struct *i;
 	struct user_struct *user;
+	struct user_namespace *user_ns;
+	struct kstate_object *tmp;
 	int rv;
 
 	i = kstate_read_image(ctx, ref, KSTATE_OBJ_USER_STRUCT, sizeof(*i));
 	if (IS_ERR(i))
 		return PTR_ERR(i);
 
-	/* FIXME */
-	user = alloc_uid(&init_user_ns, i->uid);
+	tmp = find_kstate_obj_by_ref(ctx, &i->ref_user_ns, KSTATE_CTX_USER_NS);
+	if (!tmp) {
+		rv = kstate_restore_user_ns(ctx, &i->ref_user_ns);
+		if (rv < 0)
+			goto out_free_image;
+		tmp = find_kstate_obj_by_ref(ctx, &i->ref_user_ns, KSTATE_CTX_USER_NS);
+	}
+	user_ns = tmp->o_obj;
+
+	user = alloc_uid(user_ns, i->uid);
 	if (!user) {
 		rv = -ENOMEM;
 		goto out_free_image;
kernel/user_namespace.c +146 -0

153 lines not on this page · raw message

Signature · 1 line
1.5.6.5
#160 lore raw

PATCH 36/38 C/R: checkpoint/restore struct pid

In reply to Alexey Dobriyan

Deal with struct pid in general and task pids in particular.

Guess what, references to outside pids are banned which means that if child is created with simple CLONE_NEWPID, it's PIDTYPE_PGID and PIDTYPE_SID will be outside of newborn pidns.

On restore we don't know to where glue them and they weren't saved at all. So abort checkpointing in this case.

New-born container inits should use setpgrp(2) and setsid(2)!

---
 include/linux/kstate-image.h   |   13 +++
 include/linux/kstate.h         |    5 +
 include/linux/pid.h            |    2 +-
 kernel/fork.c                  |    2 +-
 kernel/kstate/cpt-sys.c        |    6 +
 kernel/kstate/kstate-context.c |    5 +
 kernel/kstate/kstate-object.c  |    3 +
 kernel/kstate/kstate-task.c    |   80 ++++++++++++++++
 kernel/pid.c                   |  199 +++++++++++++++++++++++++++++++++++++++-
 9 files changed, 308 insertions(+), 7 deletions(-)
include/linux/kstate-image.h +13 -0
index a573833..108bb2d 100644
@@ -53,6 +53,7 @@ struct kstate_image_header {
 #define KSTATE_OBJ_GROUP_INFO	13
 #define KSTATE_OBJ_USER_STRUCT	14
 #define KSTATE_OBJ_USER_NS	15
+#define KSTATE_OBJ_PID		16
 
 struct kstate_object_header {
 	__u32		obj_type;
@@ -80,6 +81,10 @@ struct kstate_image_task_struct {
 	kstate_ref_t	ref_real_cred;
 	kstate_ref_t	ref_cred;
 
+	kstate_ref_t	ref_pid;
+	kstate_ref_t	ref_pgid;
+	kstate_ref_t	ref_sid;
+
 	__u8		comm[16];
 
 	/* Native arch of task, one of KSTATE_ARCH_*. */
@@ -305,4 +310,12 @@ struct kstate_image_user_ns {
 	 */
 	kstate_ref_t	ref_creator;
 } __packed;
+
+struct kstate_image_pid {
+	struct kstate_object_header hdr;
+
+	kstate_ref_t	ref_pid_ns;	/* last-level pid_ns */
+	__u32		level;
+	__u32		nr[1];
+} __packed;
 #endif
include/linux/kstate.h +5 -0
index f0c8e09..99a4345 100644
@@ -33,6 +33,7 @@ enum kstate_context_obj_type {
 	KSTATE_CTX_NET_NS,
 #endif
 	KSTATE_CTX_NSPROXY,
+	KSTATE_CTX_PID,
 	KSTATE_CTX_PID_NS,
 	KSTATE_CTX_TASK_STRUCT,
 	KSTATE_CTX_USER_NS,
@@ -144,6 +145,10 @@ int kstate_collect_all_user_ns(struct kstate_context *ctx);
 int kstate_dump_all_user_ns(struct kstate_context *ctx);
 int kstate_restore_user_ns(struct kstate_context *ctx, kstate_ref_t *ref);
 
+int kstate_collect_all_pid(struct kstate_context *ctx);
+int kstate_dump_all_pid(struct kstate_context *ctx);
+int kstate_restore_pid(struct kstate_context *ctx, kstate_ref_t *ref);
+
 #if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
 extern const __u32 kstate_kernel_arch;
 int kstate_arch_check_image_header(struct kstate_image_header *i);
include/linux/pid.h +1 -1
index 49f1c2f..f775a85 100644
@@ -119,7 +119,7 @@ extern struct pid *find_get_pid(int nr);
 extern struct pid *find_ge_pid(int nr, struct pid_namespace *);
 int next_pidmap(struct pid_namespace *pid_ns, int last);
 
-extern struct pid *alloc_pid(struct pid_namespace *ns);
+extern struct pid *alloc_pid(struct pid_namespace *ns, int *nr, unsigned int level);
 extern void free_pid(struct pid *pid);
 
 /*
kernel/fork.c +1 -1
index ed377ad..97521ab 100644
@@ -1117,7 +1117,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
 
 	if (pid != &init_struct_pid) {
 		retval = -ENOMEM;
-		pid = alloc_pid(p->nsproxy->pid_ns);
+		pid = alloc_pid(p->nsproxy->pid_ns, NULL, 0);
 		if (!pid)
 			goto bad_fork_cleanup_io;
 
kernel/kstate/cpt-sys.c +6 -0
index 3df776e..119940d 100644
@@ -101,6 +101,9 @@ static int kstate_collect(struct kstate_context *ctx)
 	rv = kstate_collect_all_user_ns(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_collect_all_pid(ctx);
+	if (rv < 0)
+		return rv;
 	return 0;
 }
 
@@ -154,6 +157,9 @@ static int kstate_dump(struct kstate_context *ctx)
 	rv = kstate_dump_all_pid_ns(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_dump_all_pid(ctx);
+	if (rv < 0)
+		return rv;
 	rv = kstate_dump_all_user_ns(ctx);
 	if (rv < 0)
 		return rv;
kernel/kstate/kstate-context.c +5 -0
index f8168cc..9acb441 100644
@@ -81,6 +81,11 @@ void kstate_context_destroy(struct kstate_context *ctx)
 		list_del(&obj->o_list);
 		kfree(obj);
 	}
+	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_PID) {
+		put_pid((struct pid *)obj->o_obj);
+		list_del(&obj->o_list);
+		kfree(obj);
+	}
 	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_PID_NS) {
 		put_pid_ns((struct pid_namespace *)obj->o_obj);
 		list_del(&obj->o_list);
kernel/kstate/kstate-object.c +3 -0
index eb77027..ab026f0 100644
@@ -64,6 +64,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_conte
 	case KSTATE_CTX_NSPROXY:
 		get_nsproxy((struct nsproxy *)obj->o_obj);
 		break;
+	case KSTATE_CTX_PID:
+		get_pid((struct pid *)obj->o_obj);
+		break;
 	case KSTATE_CTX_PID_NS:
 		get_pid_ns((struct pid_namespace *)obj->o_obj);
 		break;
kernel/kstate/kstate-task.c +80 -0

98 lines not on this page · raw message

kernel/pid.c +194 -5

231 lines not on this page · raw message

Signature · 1 line
1.5.6.5
#161 lore raw

PATCH 37/38 C/R: checkpoint/restore opened files

In reply to Alexey Dobriyan

File descriptor is dumped as formally an object, despite it can't be shared by itself, only files_struct can.

Opening is done, veryfying that we opened right file, restoration of file position and nothing more.

---
 include/linux/kstate-image.h   |   16 +++
 include/linux/kstate.h         |    6 +
 kernel/kstate/cpt-sys.c        |    6 +
 kernel/kstate/kstate-context.c |    6 +
 kernel/kstate/kstate-file.c    |  201 ++++++++++++++++++++++++++++++++++++++++
 kernel/kstate/kstate-object.c  |    4 +
 kernel/kstate/kstate-task.c    |   54 +++++++++++
 7 files changed, 293 insertions(+), 0 deletions(-)
include/linux/kstate-image.h +16 -0
index 108bb2d..700fc62 100644
@@ -54,6 +54,8 @@ struct kstate_image_header {
 #define KSTATE_OBJ_USER_STRUCT	14
 #define KSTATE_OBJ_USER_NS	15
 #define KSTATE_OBJ_PID		16
+#define KSTATE_OBJ_FILES_STRUCT	17
+#define KSTATE_OBJ_FD		18
 
 struct kstate_object_header {
 	__u32		obj_type;
@@ -77,6 +79,7 @@ struct kstate_image_task_struct {
 
 	kstate_ref_t	ref_mm;
 	kstate_ref_t	ref_nsproxy;
+	kstate_ref_t	ref_files;
 
 	kstate_ref_t	ref_real_cred;
 	kstate_ref_t	ref_cred;
@@ -318,4 +321,17 @@ struct kstate_image_pid {
 	__u32		level;
 	__u32		nr[1];
 } __packed;
+
+struct kstate_image_files_struct {
+	struct kstate_object_header hdr;
+} __packed;
+
+struct kstate_image_fd {
+	struct kstate_object_header hdr;
+
+	kstate_ref_t	ref_file;
+	__u32		fd;
+#define KSTATE_FD_FLAGS_CLOEXEC		(1 << 0)
+	__u32		fd_flags;
+} __packed;
 #endif
include/linux/kstate.h +6 -0
index 99a4345..2473381 100644
@@ -23,6 +23,7 @@ struct kstate_object {
 enum kstate_context_obj_type {
 	KSTATE_CTX_CRED,
 	KSTATE_CTX_FILE,
+	KSTATE_CTX_FILES_STRUCT,
 	KSTATE_CTX_GROUP_INFO,
 #ifdef CONFIG_IPC_NS
 	KSTATE_CTX_IPC_NS,
@@ -149,6 +150,11 @@ int kstate_collect_all_pid(struct kstate_context *ctx);
 int kstate_dump_all_pid(struct kstate_context *ctx);
 int kstate_restore_pid(struct kstate_context *ctx, kstate_ref_t *ref);
 
+int kstate_collect_all_files_struct(struct kstate_context *ctx);
+int kstate_dump_all_files_struct(struct kstate_context *ctx);
+int kstate_restore_files_struct(struct kstate_context *ctx, kstate_ref_t *ref);
+int kstate_restore_fd(struct kstate_context *ctx, kstate_pos_t pos);
+
 #if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
 extern const __u32 kstate_kernel_arch;
 int kstate_arch_check_image_header(struct kstate_image_header *i);
kernel/kstate/cpt-sys.c +6 -0
index 119940d..05fc9d8 100644
@@ -86,6 +86,9 @@ static int kstate_collect(struct kstate_context *ctx)
 	rv = kstate_collect_all_mm_struct(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_collect_all_files_struct(ctx);
+	if (rv < 0)
+		return rv;
 	rv = kstate_collect_all_file(ctx);
 	if (rv < 0)
 		return rv;
@@ -175,6 +178,9 @@ static int kstate_dump(struct kstate_context *ctx)
 	rv = kstate_dump_all_file(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_dump_all_files_struct(ctx);
+	if (rv < 0)
+		return rv;
 	rv = kstate_dump_all_mm_struct(ctx);
 	if (rv < 0)
 		return rv;
kernel/kstate/kstate-context.c +6 -0
index 9acb441..3e1589f 100644
@@ -1,4 +1,5 @@
 /* Copyright (C) 2000-2009 Parallels Holdings, Ltd. */
+#include <linux/fdtable.h>
 #include <linux/file.h>
 #include <linux/ipc_namespace.h>
 #include <linux/list.h>
@@ -47,6 +48,11 @@ void kstate_context_destroy(struct kstate_context *ctx)
 		list_del(&obj->o_list);
 		kfree(obj);
 	}
+	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_FILES_STRUCT) {
+		put_files_struct((struct files_struct *)obj->o_obj);
+		list_del(&obj->o_list);
+		kfree(obj);
+	}
 	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_GROUP_INFO) {
 		put_group_info((struct group_info *)obj->o_obj);
 		list_del(&obj->o_list);
kernel/kstate/kstate-file.c +201 -0

210 lines not on this page · raw message

kernel/kstate/kstate-object.c +4 -0
index ab026f0..bc27985 100644
@@ -1,4 +1,5 @@
 /* Copyright (C) 2000-2009 Parallels Holdings, Ltd. */
+#include <linux/fdtable.h>
 #include <linux/fs.h>
 #include <linux/ipc_namespace.h>
 #include <linux/mm_types.h>
@@ -42,6 +43,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_conte
 	case KSTATE_CTX_FILE:
 		get_file((struct file *)obj->o_obj);
 		break;
+	case KSTATE_CTX_FILES_STRUCT:
+		atomic_inc(&((struct files_struct *)obj->o_obj)->count);
+		break;
 	case KSTATE_CTX_GROUP_INFO:
 		get_group_info((struct group_info *)obj->o_obj);
 		break;
kernel/kstate/kstate-task.c +54 -0

76 lines not on this page · raw message

Signature · 1 line
1.5.6.5
#162 lore raw

PATCH 38/38 C/R: checkpoint/restart struct sighand_struct

In reply to Alexey Dobriyan
---
 arch/x86/include/asm/signal.h  |    2 +
 include/linux/kstate-image.h   |   17 +++++
 include/linux/kstate.h         |   29 ++++++++
 kernel/kstate/cpt-sys.c        |    6 ++
 kernel/kstate/kstate-context.c |    5 ++
 kernel/kstate/kstate-object.c  |    3 +
 kernel/kstate/kstate-task.c    |   32 +++++++++
 kernel/signal.c                |  140 ++++++++++++++++++++++++++++++++++++++++
 8 files changed, 234 insertions(+), 0 deletions(-)
arch/x86/include/asm/signal.h +2 -0
index 7761a5d..f7c9040 100644
@@ -140,6 +140,7 @@ struct sigaction {
 	__sigrestore_t sa_restorer;
 	sigset_t sa_mask;		/* mask last for extensibility */
 };
+#define sa_restorer sa_restorer
 
 struct k_sigaction {
 	struct sigaction sa;
@@ -170,6 +171,7 @@ struct sigaction {
 	__sigrestore_t sa_restorer;
 	sigset_t sa_mask;		/* mask last for extensibility */
 };
+#define sa_restorer sa_restorer
 
 struct k_sigaction {
 	struct sigaction sa;
include/linux/kstate-image.h +17 -0
index 700fc62..38fb1a4 100644
@@ -18,6 +18,9 @@ static inline int kstate_ref_undefined(kstate_ref_t *ref)
 	return ref->pos == 0 && ref->id == 0;
 }
 
+typedef __u8 kstate_sigset_t[16];
+typedef __u64 kstate_ptr_t;
+
 struct kstate_image_header {
 	/* Immutable part except version bumps. */
 #define KSTATE_IMAGE_MAGIC	"LinuxC/R"
@@ -56,6 +59,7 @@ struct kstate_image_header {
 #define KSTATE_OBJ_PID		16
 #define KSTATE_OBJ_FILES_STRUCT	17
 #define KSTATE_OBJ_FD		18
+#define KSTATE_OBJ_SIGHAND_STRUCT	19
 
 struct kstate_object_header {
 	__u32		obj_type;
@@ -88,6 +92,8 @@ struct kstate_image_task_struct {
 	kstate_ref_t	ref_pgid;
 	kstate_ref_t	ref_sid;
 
+	kstate_ref_t	ref_sighand;
+
 	__u8		comm[16];
 
 	/* Native arch of task, one of KSTATE_ARCH_*. */
@@ -334,4 +340,15 @@ struct kstate_image_fd {
 #define KSTATE_FD_FLAGS_CLOEXEC		(1 << 0)
 	__u32		fd_flags;
 } __packed;
+
+struct kstate_image_sighand_struct {
+	struct kstate_object_header hdr;
+
+	struct {
+		kstate_ptr_t	sa_handler;
+		__u64		sa_flags;
+		kstate_ptr_t	sa_restorer;
+		kstate_sigset_t	sa_mask;
+	} sa[128];
+} __packed;
 #endif
include/linux/kstate.h +29 -0
index 2473381..c958d1d 100644
@@ -1,7 +1,9 @@
 /* Copyright (C) 2000-2009 Parallels Holdings, Ltd. */
 #ifndef __INCLUDE_LINUX_KSTATE_H
 #define __INCLUDE_LINUX_KSTATE_H
+#include <linux/compiler.h>
 #include <linux/list.h>
+#include <asm/signal.h>
 
 #include <linux/kstate-image.h>
 
@@ -36,6 +38,7 @@ enum kstate_context_obj_type {
 	KSTATE_CTX_NSPROXY,
 	KSTATE_CTX_PID,
 	KSTATE_CTX_PID_NS,
+	KSTATE_CTX_SIGHAND_STRUCT,
 	KSTATE_CTX_TASK_STRUCT,
 	KSTATE_CTX_USER_NS,
 	KSTATE_CTX_USER_STRUCT,
@@ -70,6 +73,28 @@ void *kstate_prepare_image(__u32 type, unsigned int len);
 void *kstate_read_image(struct kstate_context *ctx, kstate_ref_t *ref, __u32 type, unsigned int len);
 int kstate_write_image(struct kstate_context *ctx, void *i, unsigned int len, struct kstate_object *obj);
 
+static inline kstate_ptr_t kstate_export_ptr(const void __user *ptr)
+{
+	BUILD_BUG_ON(sizeof(kstate_ptr_t) < sizeof(ptr));
+	return (unsigned long)ptr;
+}
+
+static inline const void __user *kstate_import_ptr(kstate_ptr_t i)
+{
+	return (const void __user *)(unsigned long)i;
+}
+
+static inline void kstate_dump_sigset(kstate_sigset_t *i, sigset_t *sig)
+{
+	BUILD_BUG_ON(sizeof(sigset_t) > sizeof(kstate_sigset_t));
+	memcpy(i, sig, sizeof(sigset_t));
+}
+
+static inline void kstate_restore_sigset(sigset_t *sig, kstate_sigset_t *i)
+{
+	memcpy(sig, i, sizeof(sigset_t));
+}
+
 int kstate_collect_all_task_struct(struct kstate_context *ctx);
 int kstate_dump_all_task_struct(struct kstate_context *ctx);
 int kstate_restore_task_struct(struct kstate_context *ctx, kstate_ref_t *ref);
@@ -155,6 +180,10 @@ int kstate_dump_all_files_struct(struct kstate_context *ctx);
 int kstate_restore_files_struct(struct kstate_context *ctx, kstate_ref_t *ref);
 int kstate_restore_fd(struct kstate_context *ctx, kstate_pos_t pos);
 
+int kstate_collect_all_sighand_struct(struct kstate_context *ctx);
+int kstate_dump_all_sighand_struct(struct kstate_context *ctx);
+int kstate_restore_sighand_struct(struct kstate_context *ctx, kstate_ref_t *ref);
+
 #if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
 extern const __u32 kstate_kernel_arch;
 int kstate_arch_check_image_header(struct kstate_image_header *i);
kernel/kstate/cpt-sys.c +6 -0
index 05fc9d8..8225804 100644
@@ -104,6 +104,9 @@ static int kstate_collect(struct kstate_context *ctx)
 	rv = kstate_collect_all_user_ns(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_collect_all_sighand_struct(ctx);
+	if (rv < 0)
+		return rv;
 	rv = kstate_collect_all_pid(ctx);
 	if (rv < 0)
 		return rv;
@@ -163,6 +166,9 @@ static int kstate_dump(struct kstate_context *ctx)
 	rv = kstate_dump_all_pid(ctx);
 	if (rv < 0)
 		return rv;
+	rv = kstate_dump_all_sighand_struct(ctx);
+	if (rv < 0)
+		return rv;
 	rv = kstate_dump_all_user_ns(ctx);
 	if (rv < 0)
 		return rv;
kernel/kstate/kstate-context.c +5 -0
index 3e1589f..44111d1 100644
@@ -97,6 +97,11 @@ void kstate_context_destroy(struct kstate_context *ctx)
 		list_del(&obj->o_list);
 		kfree(obj);
 	}
+	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_SIGHAND_STRUCT) {
+		__cleanup_sighand((struct sighand_struct *)obj->o_obj);
+		list_del(&obj->o_list);
+		kfree(obj);
+	}
 	for_each_kstate_object_safe(ctx, obj, tmp, KSTATE_CTX_TASK_STRUCT) {
 		put_task_struct((struct task_struct *)obj->o_obj);
 		list_del(&obj->o_list);
kernel/kstate/kstate-object.c +3 -0
index bc27985..f871463 100644
@@ -74,6 +74,9 @@ int kstate_collect_object(struct kstate_context *ctx, void *p, enum kstate_conte
 	case KSTATE_CTX_PID_NS:
 		get_pid_ns((struct pid_namespace *)obj->o_obj);
 		break;
+	case KSTATE_CTX_SIGHAND_STRUCT:
+		atomic_inc(&((struct sighand_struct *)obj->o_obj)->count);
+		break;
 	case KSTATE_CTX_TASK_STRUCT:
 		get_task_struct((struct task_struct *)obj->o_obj);
 		break;
kernel/kstate/kstate-task.c +32 -0
index 101fcb8..2cfcb8f 100644
@@ -139,6 +139,9 @@ static int dump_task_struct(struct kstate_context *ctx, struct kstate_object *ob
 	tmp = find_kstate_obj_by_ptr(ctx, tsk->files, KSTATE_CTX_FILES_STRUCT);
 	i->ref_files = tmp->o_ref;
 
+	tmp = find_kstate_obj_by_ptr(ctx, tsk->sighand, KSTATE_CTX_SIGHAND_STRUCT);
+	i->ref_sighand = tmp->o_ref;
+
 	BUILD_BUG_ON(sizeof(i->comm) != sizeof(tsk->comm));
 	strlcpy((char *)i->comm, (const char *)tsk->comm, sizeof(i->comm));
 
@@ -402,6 +405,32 @@ static int restore_files(struct kstate_context *ctx, kstate_ref_t *ref)
 	return 0;
 }
 
+static int restore_sighand(struct kstate_context *ctx, kstate_ref_t *ref)
+{
+	struct sighand_struct *sighand;
+	struct kstate_object *tmp;
+	struct sighand_struct *old_sighand;
+	unsigned long flags;
+	int rv;
+
+	tmp = find_kstate_obj_by_ref(ctx, ref, KSTATE_CTX_SIGHAND_STRUCT);
+	if (!tmp) {
+		rv = kstate_restore_sighand_struct(ctx, ref);
+		if (rv < 0)
+			return rv;
+		tmp = find_kstate_obj_by_ref(ctx, ref, KSTATE_CTX_SIGHAND_STRUCT);
+	}
+	sighand = tmp->o_obj;
+
+	atomic_inc(&sighand->count);
+	old_sighand = current->sighand;
+	spin_lock_irqsave(&old_sighand->siglock, flags);
+	current->sighand = sighand;
+	spin_unlock_irqrestore(&old_sighand->siglock, flags);
+	__cleanup_sighand(old_sighand);
+	return 0;
+}
+
 struct task_struct_restore_context {
 	struct kstate_context *ctx;
 	struct kstate_image_task_struct *i;
@@ -468,6 +497,9 @@ static int task_struct_restorer(void *_tsk_ctx)
 	rv = restore_files(ctx, &i->ref_files);
 	if (rv < 0)
 		goto out;
+	rv = restore_sighand(ctx, &i->ref_sighand);
+	if (rv < 0)
+		goto out;
 
 out:
 	tsk_ctx->rv = rv;
kernel/signal.c +140 -0

149 lines not on this page · raw message

Signature · 1 line
1.5.6.5
#163 lore raw
In reply to Alexey Dobriyan

More patches before "[PATCH 18/38] C/R: core stuff" were already sent via usual channels and some are already in -next. There are being repeated to maintain clean series against mainline.

I forgot to mention that ->checkpoint hook was not added to vDSO mapping for several reasons so if someone want to test, boot with vdso=0 for now.