cr: deal with credentials
PATCH 25/30 cr: deal with credentials
Dump/restore struct cred, struct user, struct user_namespace, struct group_info
FIXME: restore struct user
FIXME: restore struct file::f_cred
Signed-off-by Alexey Dobriyan <[email protected]>
---
include/linux/cr.h | 46 ++++ include/linux/cred.h | 1 kernel/cr/Kconfig | 1 kernel/cr/Makefile | 1 kernel/cr/cpt-sys.c | 24 ++ kernel/cr/cr-cred.c | 514 +++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/cr/cr-file.c | 2 kernel/cr/cr-task.c | 8 kernel/cr/cr.h | 14 + kernel/cred.c | 2 10 files changed, 612 insertions(+), 1 deletion(-)
include/linux/cr.h +46 -0
@@ -44,6 +44,10 @@ struct cr_object_header {#define CR_OBJ_FS_STRUCT 13#define CR_OBJ_SIGNAL_STRUCT 14#define CR_OBJ_SIGHAND_STRUCT 15 +#define CR_OBJ_CRED 16 +#define CR_OBJ_GROUP_INFO 17 +#define CR_OBJ_USER_STRUCT 18 +#define CR_OBJ_USER_NS 19__u32 cr_type;/* object type */ __u32 cr_len;/* object length in bytes including header */ } __packed;
@@ -74,6 +78,9 @@ struct cr_image_task_struct {__u8 cr_real_blocked[16 ];__u8 cr_saved_sigmask[16 ]; +cr_pos_t cr_pos_real_cred; +cr_pos_t cr_pos_cred; +__u8 cr_comm[16 ];/* Native arch of task, one of CR_ARCH_*. */
@@ -288,6 +295,7 @@ struct cr_image_file {__u32 cr_euid;__u32 cr_signum; } cr_f_owner; +cr_pos_t cr_pos_f_cred;__u32 cr_name_len;/* __u8 cr_name[cr_name_len] */ } __packed;
@@ -301,6 +309,44 @@ struct cr_image_fd {__u32 cr_fd_flags; } __packed; +struct cr_image_cred { +struct cr_object_header cr_hdr; + +__u32 cr_uid; +__u32 cr_gid; +__u32 cr_suid; +__u32 cr_sgid; +__u32 cr_euid; +__u32 cr_egid; +__u32 cr_fsuid; +__u32 cr_fsgid; +__u32 cr_securebits; +__u64 cr_cap_inheritable; +__u64 cr_cap_permitted; +__u64 cr_cap_effective; +__u64 cr_cap_bset; +cr_pos_t cr_pos_user; +cr_pos_t cr_pos_group_info; +} __packed; + +struct cr_image_group_info { +struct cr_object_header cr_hdr; + +__u32 cr_ngroups; +/* __u32 cr_gid[cr_ngroups]; */ +} __packed; + +struct cr_image_user_struct { +struct cr_object_header cr_hdr; + +cr_pos_t cr_pos_user_ns; +__u32 cr_uid; +} __packed; + +struct cr_image_user_ns { +struct cr_object_header cr_hdr; +} __packed; +struct cr_image_pid {struct cr_object_header cr_hdr;
include/linux/cred.h +1 -0
@@ -142,6 +142,7 @@ struct cred {struct rcu_head rcu;/* RCU deletion hook */ }; +extern struct kmem_cache *cred_jar;extern void __put_cred (struct cred *);extern int copy_creds (struct task_struct *,unsigned long );extern struct cred *prepare_creds (void );
kernel/cr/Kconfig +1 -0
@@ -1,6 +1,7 @@ config CR bool "Container checkpoint/restart" depends on PID_NS + depends on USER_NS depends on UTS_NS select FREEZER help
kernel/cr/Makefile +1 -0
@@ -1,6 +1,7 @@ obj-$(CONFIG_CR) += cr.o cr-y := cpt-sys.o rst-sys.o cr-y += cr-context.o +cr-y += cr-cred.o cr-y += cr-file.o cr-y += cr-fs.o cr-y += cr-mm.o
kernel/cr/cpt-sys.c +24 -0
@@ -92,6 +92,18 @@ static int cr_collect(struct cr_context *ctx) rv =cr_collect_all_sighand_struct (ctx);if (rv <0 )return rv; + rv =cr_collect_all_cred (ctx); +if (rv <0 ) +return rv; + rv =cr_collect_all_group_info (ctx); +if (rv <0 ) +return rv; + rv =cr_collect_all_user_struct (ctx); +if (rv <0 ) +return rv; + rv =cr_collect_all_user_ns (ctx); +if (rv <0 ) +return rv; rv =cr_collect_all_pid (ctx);if (rv <0 )return rv;
@@ -134,6 +146,18 @@ static int cr_dump(struct cr_context *ctx) rv =cr_dump_all_pid (ctx);if (rv <0 )return rv; + rv =cr_dump_all_user_ns (ctx); +if (rv <0 ) +return rv; + rv =cr_dump_all_user_struct (ctx); +if (rv <0 ) +return rv; + rv =cr_dump_all_group_info (ctx); +if (rv <0 ) +return rv; + rv =cr_dump_all_cred (ctx); +if (rv <0 ) +return rv; rv =cr_dump_all_file (ctx);if (rv <0 )return rv;
new file mode 100644
kernel/cr/cr-cred.c new file +514 -0
514 lines not on this page · raw message
kernel/cr/cr-file.c +2 -0
@@ -133,6 +133,8 @@ int generic_file_checkpoint(struct file *file, struct cr_context *ctx) i->cr_f_owner.cr_uid = file->f_owner.uid; i->cr_f_owner.cr_euid = file->f_owner.euid; i->cr_f_owner.cr_signum = file->f_owner.signum; + tmp =cr_find_obj_by_ptr (ctx, file->f_cred,CR_CTX_CRED ); + i->cr_pos_f_cred = tmp->o_pos; buf =kmalloc (PAGE_SIZE ,GFP_KERNEL );if (!buf) {
kernel/cr/cr-task.c +8 -0
@@ -140,6 +140,11 @@ static int cr_dump_task_struct(struct cr_context *ctx, struct cr_object *obj)cr_dump_sigset (i->cr_real_blocked, &tsk->real_blocked);cr_dump_sigset (i->cr_saved_sigmask, &tsk->saved_sigmask); + tmp =cr_find_obj_by_ptr (ctx, tsk->real_cred,CR_CTX_CRED ); + i->cr_pos_real_cred = tmp->o_pos; + tmp =cr_find_obj_by_ptr (ctx, tsk->cred,CR_CTX_CRED ); + i->cr_pos_cred = tmp->o_pos; +BUILD_BUG_ON (TASK_COMM_LEN !=16 );strlcpy ((char *)i->cr_comm, (const char *)tsk->comm,sizeof (i->cr_comm));
@@ -210,6 +215,9 @@ static int task_struct_restorer(void *_tsk_ctx)cr_restore_sigset (&tsk->blocked, i->cr_blocked);cr_restore_sigset (&tsk->real_blocked, i->cr_real_blocked);cr_restore_sigset (&tsk->saved_sigmask, i->cr_saved_sigmask); + rv =cr_restore_cred (ctx, i); +if (rv <0 ) + goto out; rv =0 ; out:
kernel/cr/cr.h +14 -0
@@ -22,9 +22,11 @@ struct cr_object {/* Not visible to userspace! */ enum cr_context_obj_type { +CR_CTX_CRED ,CR_CTX_FILE ,CR_CTX_FILES_STRUCT ,CR_CTX_FS_STRUCT , +CR_CTX_GROUP_INFO ,CR_CTX_MM_STRUCT ,CR_CTX_NSPROXY ,CR_CTX_PID ,
@@ -32,6 +34,8 @@ enum cr_context_obj_type {CR_CTX_SIGHAND_STRUCT ,CR_CTX_SIGNAL_STRUCT ,CR_CTX_TASK_STRUCT , +CR_CTX_USER_NS , +CR_CTX_USER_STRUCT ,CR_CTX_UTS_NS , NR_CR_CTX_TYPES };
@@ -85,9 +89,11 @@ static inline void cr_restore_sigset(sigset_t *sig, __u8 *cr_image_sigset)memcpy (sig, cr_image_sigset,sizeof (sigset_t)); } +int cr_collect_all_cred (struct cr_context *ctx);int cr_collect_all_files_struct (struct cr_context *ctx);int cr_collect_all_file (struct cr_context *ctx);int cr_collect_all_fs_struct (struct cr_context *ctx); +int cr_collect_all_group_info (struct cr_context *ctx);int cr_collect_all_mm_struct (struct cr_context *ctx);int cr_collect_all_nsproxy (struct cr_context *ctx);int cr_collect_all_pid_ns (struct cr_context *ctx);
@@ -95,11 +101,15 @@ int cr_collect_all_pid(struct cr_context *ctx);int cr_collect_all_sighand_struct (struct cr_context *ctx);int cr_collect_all_signal_struct (struct cr_context *ctx);int cr_collect_all_task_struct (struct cr_context *ctx); +int cr_collect_all_user_ns (struct cr_context *ctx); +int cr_collect_all_user_struct (struct cr_context *ctx);int cr_collect_all_uts_ns (struct cr_context *ctx); +int cr_dump_all_cred (struct cr_context *ctx);int cr_dump_all_files_struct (struct cr_context *ctx);int cr_dump_all_file (struct cr_context *ctx);int cr_dump_all_fs_struct (struct cr_context *ctx); +int cr_dump_all_group_info (struct cr_context *ctx);int cr_dump_all_mm_struct (struct cr_context *ctx);int cr_dump_all_nsproxy (struct cr_context *ctx);int cr_dump_all_pid_ns (struct cr_context *ctx);
@@ -107,11 +117,15 @@ int cr_dump_all_pid(struct cr_context *ctx);int cr_dump_all_sighand_struct (struct cr_context *ctx);int cr_dump_all_signal_struct (struct cr_context *ctx);int cr_dump_all_task_struct (struct cr_context *ctx); +int cr_dump_all_user_ns (struct cr_context *ctx); +int cr_dump_all_user_struct (struct cr_context *ctx);int cr_dump_all_uts_ns (struct cr_context *ctx); +int cr_restore_cred (struct cr_context *ctx,struct cr_image_task_struct *i);int cr_restore_files_struct (struct cr_context *ctx,loff_t pos);int cr_restore_file (struct cr_context *ctx,loff_t pos);int cr_restore_fs_struct (struct cr_context *ctx,loff_t pos); +int cr_restore_group_info (struct cr_context *ctx,loff_t pos);int cr_restore_mm_struct (struct cr_context *ctx,loff_t pos);int cr_restore_nsproxy (struct cr_context *ctx,loff_t pos);int cr_restore_pid_ns (struct cr_context *ctx,loff_t pos);
kernel/cred.c +1 -1
@@ -18,7 +18,7 @@#include <linux/cn_proc.h> #include "cred-internals.h" -static struct kmem_cache *cred_jar; +struct kmem_cache *cred_jar;/* * The common credentials for the initial task's thread group