From f6480aaa10f6a4bdcf1b52b0d101cda725b8a177 Mon Sep 17 00:00:00 2001 From: David Howells Date: Wed, 9 Mar 2005 16:42:51 -0800 Subject: [PATCH] Properly share process and session keyrings with CLONE_THREAD [try #2] The attached patch causes process and session keyrings to be shared properly when CLONE_THREAD is in force. It does this by moving the keyring pointers into struct signal_struct[*]. [*] I have a patch to rename this to struct thread_group that I'll revisit after the advent of 2.6.11. Furthermore, once this patch is applied, process keyrings will no longer be allocated at fork, but will instead only be allocated when needed. Allocating them at fork was a way of half getting around the sharing across threads problem, but that's no longer necessary. This revision of the patch has the documentation changes patch rolled into it and no longer abstracts the locking for signal_struct into a pair of macros. Signed-Off-By: David Howells Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- include/linux/key.h | 5 +++++ include/linux/sched.h | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'include/linux') diff --git a/include/linux/key.h b/include/linux/key.h index 15eaba537341..6aa46d0e812f 100644 --- a/include/linux/key.h +++ b/include/linux/key.h @@ -58,6 +58,7 @@ struct key; struct seq_file; struct user_struct; +struct signal_struct; struct key_type; struct key_owner; @@ -258,7 +259,9 @@ extern struct key root_user_keyring, root_session_keyring; extern int alloc_uid_keyring(struct user_struct *user); extern void switch_uid_keyring(struct user_struct *new_user); extern int copy_keys(unsigned long clone_flags, struct task_struct *tsk); +extern int copy_thread_group_keys(struct task_struct *tsk); extern void exit_keys(struct task_struct *tsk); +extern void exit_thread_group_keys(struct signal_struct *tg); extern int suid_keys(struct task_struct *tsk); extern int exec_keys(struct task_struct *tsk); extern void key_fsuid_changed(struct task_struct *tsk); @@ -274,7 +277,9 @@ extern void key_init(void); #define alloc_uid_keyring(u) 0 #define switch_uid_keyring(u) do { } while(0) #define copy_keys(f,t) 0 +#define copy_thread_group_keys(t) 0 #define exit_keys(t) do { } while(0) +#define exit_thread_group_keys(tg) do { } while(0) #define suid_keys(t) do { } while(0) #define exec_keys(t) do { } while(0) #define key_fsuid_changed(t) do { } while(0) diff --git a/include/linux/sched.h b/include/linux/sched.h index cf90d1ed1a1f..f564b18dbaed 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -348,6 +348,13 @@ struct signal_struct { struct rlimit rlim[RLIM_NLIMITS]; struct list_head cpu_timers[3]; + + /* keep the process-shared keyrings here so that they do the right + * thing in threads created with CLONE_THREAD */ +#ifdef CONFIG_KEYS + struct key *session_keyring; /* keyring inherited over fork */ + struct key *process_keyring; /* keyring private to this process */ +#endif }; /* @@ -631,8 +638,6 @@ struct task_struct { unsigned keep_capabilities:1; struct user_struct *user; #ifdef CONFIG_KEYS - struct key *session_keyring; /* keyring inherited over fork */ - struct key *process_keyring; /* keyring private to this process (CLONE_THREAD) */ struct key *thread_keyring; /* keyring private to this thread */ #endif int oomkilladj; /* OOM kill score adjustment (bit shift). */ -- cgit v1.2.3