KEYS: Do some style cleanup in the key management code.
Subsystems (2)
David Howells
maintainerPATCH 1/2 KEYS: Do some style cleanup in the key management code.
Do a bit of a style clean up in the key management code. No functional changes.
Done using:
perl -p -i -e 's!^/[*]*/\n!!' security/keys/*.c
perl -p -i -e 's!} /[*] end [a-z0-9_]*[(][)] [*]/\n!}\n!' security/keys/*.c
sed -i -s -e ": next" -e N -e 's/^\n[}]$/}/' -e t -e P -e 's/^.*\n//' -e "b next" security/keys/*.c
To remove /*****/ lines, remove comments on the closing brace of a function to name the function and remove blank lines before the closing brace of a function.
---
security/keys/compat.c | 4 -- security/keys/encrypted_defined.c | 1 security/keys/key.c | 80 +++++++++---------------------------- security/keys/keyctl.c | 77 +++++++++--------------------------- security/keys/keyring.c | 64 +++++++----------------------- security/keys/permission.c | 8 +--- security/keys/proc.c | 7 --- security/keys/process_keys.c | 23 ++--------- security/keys/request_key_auth.c | 32 ++++----------- security/keys/user_defined.c | 32 ++++----------- 10 files changed, 80 insertions(+), 248 deletions(-)
security/keys/compat.c +1 -3
@@ -14,7 +14,6 @@#include <linux/compat.h> #include "internal.h" -/*****************************************************************************/ /* * the key control system call, 32-bit compatibility version for 64-bit archs * - this should only be called if the 64-bit arch uses weird pointers in
@@ -88,5 +87,4 @@ asmlinkage long compat_sys_keyctl(u32 option,default :return -EOPNOTSUPP ; } - -}/* end compat_sys_keyctl() */ +}
security/keys/encrypted_defined.c +0 -1
@@ -888,7 +888,6 @@ static int __init init_encrypted(void) out:encrypted_shash_release ();return ret; - } static void __exit cleanup_encrypted(void)
security/keys/key.c +20 -60
242 lines not on this page · raw message
security/keys/keyctl.c +19 -58
228 lines not on this page · raw message
security/keys/keyring.c +16 -48
192 lines not on this page · raw message
security/keys/permission.c +2 -6
@@ -13,7 +13,6 @@#include <linux/security.h> #include "internal.h" -/*****************************************************************************/ /** * key_task_permission - Check a key can be used * @key_ref: The key to check
@@ -79,12 +78,10 @@ use_these_perms:/* let LSM be the final arbiter */ return security_key_permission (key_ref, cred, perm); - -}/* end key_task_permission() */ +}EXPORT_SYMBOL (key_task_permission); -/*****************************************************************************/ /* * validate a key */
@@ -111,7 +108,6 @@ int key_validate(struct key *key) error:return ret; - -}/* end key_validate() */ +}EXPORT_SYMBOL (key_validate);
security/keys/proc.c +1 -6
@@ -60,7 +60,6 @@ static const struct file_operations proc_key_users_fops = { .release = seq_release, }; -/*****************************************************************************/ /* * declare the /proc files */
@@ -79,12 +78,10 @@ static int __init key_proc_init(void)panic ("Cannot create /proc/key-users\n" );return 0 ; - -}/* end key_proc_init() */ +}__initcall (key_proc_init); -/*****************************************************************************/ /* * implement "/proc/keys" to provides a list of the keys on the system */
@@ -293,7 +290,6 @@ static struct rb_node *key_user_first(struct rb_root *r)return __key_user_next (n); } -/*****************************************************************************/ /* * implement "/proc/key-users" to provides a list of the key users */
@@ -351,5 +347,4 @@ static int proc_key_users_show(struct seq_file *m, void *v) maxbytes);return 0 ; - }
security/keys/process_keys.c +5 -18
@@ -38,7 +38,6 @@ struct key_user root_key_user = { .user_ns = &init_user_ns, }; -/*****************************************************************************/ /* * install user and user session keyrings for a particular UID */
@@ -275,7 +274,6 @@ static int install_session_keyring(struct key *keyring)return commit_creds (new); } -/*****************************************************************************/ /* * the filesystem user ID changed */
@@ -288,10 +286,8 @@ void key_fsuid_changed(struct task_struct *tsk) tsk->cred->thread_keyring->uid = tsk->cred->fsuid;up_write (&tsk->cred->thread_keyring->sem); } +} -}/* end key_fsuid_changed() */ - -/*****************************************************************************/ /* * the filesystem group ID changed */
@@ -304,10 +300,8 @@ void key_fsgid_changed(struct task_struct *tsk) tsk->cred->thread_keyring->gid = tsk->cred->fsgid;up_write (&tsk->cred->thread_keyring->sem); } +} -}/* end key_fsgid_changed() */ - -/*****************************************************************************/ /* * search only my process keyrings for the first matching key * - we use the supplied match function to see if the description (or other
@@ -428,7 +422,6 @@ found:return key_ref; } -/*****************************************************************************/ /* * search the process keyrings for the first matching key * - we use the supplied match function to see if the description (or other
@@ -489,20 +482,16 @@ key_ref_t search_process_keyrings(struct key_type *type, found:return key_ref; +} -}/* end search_process_keyrings() */ - -/*****************************************************************************/ /* * see if the key we're looking at is the target key */ int lookup_user_key_possessed (const struct key *key,const void *target) {return key == target; +} -}/* end lookup_user_key_possessed() */ - -/*****************************************************************************/ /* * lookup a key given a key ID from userspace with a given permissions mask * - don't create special keyrings unless so requested
@@ -711,10 +700,8 @@ invalid_key: reget_creds:put_cred (cred); goto try_again; +} -}/* end lookup_user_key() */ - -/*****************************************************************************/ /* * join the named keyring as the session keyring if possible, or attempt to * create a new one of that name if not
security/keys/request_key_auth.c +8 -24
@@ -38,7 +38,6 @@ struct key_type key_type_request_key_auth = { .read = request_key_auth_read, }; -/*****************************************************************************/ /* * instantiate a request-key authorisation key */
@@ -48,10 +47,8 @@ static int request_key_auth_instantiate(struct key *key, { key->payload.data = (struct request_key_auth *) data;return 0 ; +} -}/* end request_key_auth_instantiate() */ - -/*****************************************************************************/ /* * reading a request-key authorisation key retrieves the callout information */
@@ -63,10 +60,8 @@ static void request_key_auth_describe(const struct key *key,seq_puts (m,"key:" );seq_puts (m, key->description);seq_printf (m," pid:%d ci:%zu" , rka->pid, rka->callout_len); +} -}/* end request_key_auth_describe() */ - -/*****************************************************************************/ /* * read the callout_info data * - the key's semaphore is read-locked
@@ -91,10 +86,8 @@ static long request_key_auth_read(const struct key *key, }return ret; +} -}/* end request_key_auth_read() */ - -/*****************************************************************************/ /* * handle revocation of an authorisation token key * - called with the key sem write-locked
@@ -109,10 +102,8 @@ static void request_key_auth_revoke(struct key *key)put_cred (rka->cred); rka->cred =NULL ; } +} -}/* end request_key_auth_revoke() */ - -/*****************************************************************************/ /* * destroy an instantiation authorisation token key */
@@ -131,10 +122,8 @@ static void request_key_auth_destroy(struct key *key)key_put (rka->dest_keyring);kfree (rka->callout_info);kfree (rka); +} -}/* end request_key_auth_destroy() */ - -/*****************************************************************************/ /* * create an authorisation token for /sbin/request-key or whoever to gain * access to the caller's security data
@@ -228,10 +217,8 @@ error_alloc:kfree (rka);kleave ("= %d" , ret);return ERR_PTR (ret); +} -}/* end request_key_auth_new() */ - -/*****************************************************************************/ /* * see if an authorisation key is associated with a particular key */
@@ -242,10 +229,8 @@ static int key_get_instantiation_authkey_match(const struct key *key,key_serial_t id = (key_serial_t )(unsigned long ) _id;return rka->target_key->serial == id; +} -}/* end key_get_instantiation_authkey_match() */ - -/*****************************************************************************/ /* * get the authorisation key for instantiation of a specific key if attached to * the current process's keyrings
@@ -278,5 +263,4 @@ struct key *key_get_instantiation_authkey(key_serial_t target_id) error:return authkey; - -}/* end key_get_instantiation_authkey() */ +}
security/keys/user_defined.c +8 -24
@@ -35,7 +35,6 @@ struct key_type key_type_user = {EXPORT_SYMBOL_GPL (key_type_user); -/*****************************************************************************/ /* * instantiate a user defined key */
@@ -65,12 +64,10 @@ int user_instantiate(struct key *key, const void *data, size_t datalen) error:return ret; - -}/* end user_instantiate() */ +}EXPORT_SYMBOL_GPL (user_instantiate); -/*****************************************************************************/ /* * dispose of the old data from an updated user defined key */
@@ -81,10 +78,8 @@ static void user_update_rcu_disposal(struct rcu_head *rcu) upayload = container_of(rcu, struct user_key_payload, rcu);kfree (upayload); +} -}/* end user_update_rcu_disposal() */ - -/*****************************************************************************/ /* * update a user defined key * - the key's semaphore is write-locked
@@ -123,24 +118,20 @@ int user_update(struct key *key, const void *data, size_t datalen) error:return ret; - -}/* end user_update() */ +}EXPORT_SYMBOL_GPL (user_update); -/*****************************************************************************/ /* * match users on their name */ int user_match (const struct key *key,const void *description) {return strcmp (key->description, description) ==0 ; - -}/* end user_match() */ +}EXPORT_SYMBOL_GPL (user_match); -/*****************************************************************************/ /* * dispose of the links from a revoked keyring * - called with the key sem write-locked
@@ -156,12 +147,10 @@ void user_revoke(struct key *key)rcu_assign_pointer (key->payload.data,NULL );call_rcu (&upayload->rcu, user_update_rcu_disposal); } - -}/* end user_revoke() */ +}EXPORT_SYMBOL (user_revoke); -/*****************************************************************************/ /* * dispose of the data dangling from the corpse of a user key */
@@ -170,12 +159,10 @@ void user_destroy(struct key *key)struct user_key_payload *upayload = key->payload.data;kfree (upayload); - -}/* end user_destroy() */ +}EXPORT_SYMBOL_GPL (user_destroy); -/*****************************************************************************/ /* * describe the user key */
@@ -184,12 +171,10 @@ void user_describe(const struct key *key, struct seq_file *m)seq_puts (m, key->description);seq_printf (m,": %u" , key->datalen); - -}/* end user_describe() */ +}EXPORT_SYMBOL_GPL (user_describe); -/*****************************************************************************/ /* * read the key data * - the key's semaphore is read-locked
@@ -213,7 +198,6 @@ long user_read(const struct key *key, char __user *buffer, size_t buflen) }return ret; - -}/* end user_read() */ +}EXPORT_SYMBOL_GPL (user_read);
David Howells
maintainerPATCH 2/2 KEYS: Fix up comments in key management code
Fix up comments in the key management code. No functional changes.
---
security/keys/compat.c | 13 +- security/keys/gc.c | 14 +- security/keys/internal.h | 26 ++-- security/keys/key.c | 240 ++++++++++++++++++++++++--------- security/keys/keyctl.c | 278 +++++++++++++++++++++++++------------- security/keys/keyring.c | 231 ++++++++++++++++++++++---------- security/keys/permission.c | 25 ++- security/keys/proc.c | 10 + security/keys/process_keys.c | 112 ++++++++++----- security/keys/request_key.c | 164 +++++++++++++++++----- security/keys/request_key_auth.c | 30 ++-- 11 files changed, 777 insertions(+), 366 deletions(-)
security/keys/compat.c +7 -6
@@ -1,4 +1,4 @@ -/* compat.c: 32-bit compatibility syscall for 64-bit systems +/* 32-bit compatibility syscall for 64-bit systems * * Copyright (C) 2004-5 Red Hat, Inc. All Rights Reserved. * Written by David Howells ([email protected])
@@ -15,11 +15,12 @@#include "internal.h" /* -* the key control system call, 32-bit compatibility version for 64-bit archs -* - this should only be called if the 64-bit arch uses weird pointers in -* 32-bit mode or doesn't guarantee that the top 32-bits of the argument -* registers on taking a 32-bit syscall are zero -* - if you can, you should call sys_keyctl directly +* The key control system call, 32-bit compatibility version for 64-bit archs +* +* This should only be called if the 64-bit arch uses weird pointers in 32-bit +* mode or doesn't guarantee that the top 32-bits of the argument registers on +* taking a 32-bit syscall are zero. If you can, you should call sys_keyctl() +* directly. */ asmlinkage long compat_sys_keyctl (u32 option,u32 arg2,u32 arg3,u32 arg4,u32 arg5)
security/keys/gc.c +7 -7
@@ -32,8 +32,8 @@ static time_t key_gc_next_run = LONG_MAX;static time_t key_gc_new_timer;/* -* Schedule a garbage collection run -* - precision isn't particularly important +* Schedule a garbage collection run. +* - time precision isn't particularly important */ void key_schedule_gc (time_t gc_at) {
@@ -61,8 +61,9 @@ static void key_gc_timer_func(unsigned long data) }/* -* Garbage collect pointers from a keyring -* - return true if we altered the keyring +* Garbage collect pointers from a keyring. +* +* Return true if we altered the keyring. */ static bool key_gc_keyring(struct key *keyring, time_t limit) __releases(key_serial_lock)
@@ -107,9 +108,8 @@ do_gc: }/* -* Garbage collector for keys -* - this involves scanning the keyrings for dead, expired and revoked keys -* that have overstayed their welcome +* Garbage collector for keys. This involves scanning the keyrings for dead, +* expired and revoked keys that have overstayed their welcome */ static void key_garbage_collector (struct work_struct *work) {
security/keys/internal.h +14 -12
@@ -1,4 +1,4 @@ -/* internal.h: authentication token and access key management internal defs +/* Authentication token and access key management internal defs * * Copyright (C) 2003-5, 2007 Red Hat, Inc. All Rights Reserved. * Written by David Howells ([email protected])
@@ -35,10 +35,12 @@ extern struct key_type key_type_user;/*****************************************************************************/ /* -* keep track of keys for a user -* - this needs to be separate to user_struct to avoid a refcount-loop -* (user_struct pins some keyrings which pin this struct) -* - this also keeps track of keys under request from userspace for this UID +* Keep track of keys for a user. +* +* This needs to be separate to user_struct to avoid a refcount-loop +* (user_struct pins some keyrings which pin this struct). +* +* We also keep track of keys under request from userspace for this UID here. */ struct key_user {struct rb_node node;
@@ -62,7 +64,7 @@ extern struct key_user *key_user_lookup(uid_t uid,extern void key_user_put (struct key_user *user);/* -* key quota limits +* Key quota limits. * - root has its own separate limits to everyone else */ extern unsigned key_quota_root_maxkeys;
@@ -146,13 +148,13 @@ extern unsigned key_gc_delay;extern void keyring_gc (struct key *keyring,time_t limit);extern void key_schedule_gc (time_t expiry_at); -/* -* check to see whether permission is granted to use a key in the desired way -*/ extern int key_task_permission (const key_ref_t key_ref,const struct cred *cred,key_perm_t perm); +/* +* Check to see whether permission is granted to use a key in the desired way. +*/ static inline int key_permission (const key_ref_t key_ref,key_perm_t perm) {return key_task_permission (key_ref,current_cred (), perm);
@@ -168,7 +170,7 @@ static inline int key_permission(const key_ref_t key_ref, key_perm_t perm)#define KEY_ALL 0x3f/* all the above permissions */ /* -* request_key authorisation +* Authorisation record for request_key(). */ struct request_key_auth {struct key *target_key;
@@ -188,7 +190,7 @@ extern struct key *request_key_auth_new(struct key *target,extern struct key *key_get_instantiation_authkey (key_serial_t target_id);/* -* keyctl functions +* keyctl() functions */ extern long keyctl_get_keyring_ID (key_serial_t ,int );extern long keyctl_join_session_keyring (const char __user *);
@@ -214,7 +216,7 @@ extern long keyctl_get_security(key_serial_t keyid, char __user *buffer,extern long keyctl_session_to_parent (void );/* -* debugging key validation +* Debugging key validation */ #ifdef KEY_DEBUGGING extern void __key_check (const struct key *);
security/keys/key.c +173 -67
433 lines not on this page · raw message
security/keys/keyctl.c +186 -92
439 lines not on this page · raw message
security/keys/keyring.c +159 -72
409 lines not on this page · raw message
security/keys/permission.c +15 -10
@@ -1,4 +1,4 @@ -/* permission.c: key permission determination +/* Key permission checking * * Copyright (C) 2005 Red Hat, Inc. All Rights Reserved. * Written by David Howells ([email protected])
@@ -15,15 +15,17 @@/** * key_task_permission - Check a key can be used -* @key_ref: The key to check -* @cred: The credentials to use -* @perm: The permissions to check for +* @key_ref: The key to check. +* @cred: The credentials to use. +* @perm: The permissions to check for. * * Check to see whether permission is granted to use a key in the desired way, * but permit the security modules to override. * -* The caller must hold either a ref on cred or must hold the RCU readlock or a -* spinlock. +* The caller must hold either a ref on cred or must hold the RCU readlock. +* +* Returns 0 if successful, -EACCES if access is denied based on the +* permissions bits or the LSM check. */ int key_task_permission (const key_ref_t key_ref,const struct cred *cred,key_perm_t perm)
@@ -79,11 +81,15 @@ use_these_perms:/* let LSM be the final arbiter */ return security_key_permission (key_ref, cred, perm); } -EXPORT_SYMBOL (key_task_permission); -/* -* validate a key +/** +* key_validate - Validate a key. +* @key: The key to be validated. +* +* Check that a key is valid, returning 0 if the key is okay, -EKEYREVOKED if +* the key's type has been removed or if the key has been revoked or +* -EKEYEXPIRED if the key has expired. */ int key_validate (struct key *key) {
@@ -109,5 +115,4 @@ int key_validate(struct key *key) error:return ret; } -EXPORT_SYMBOL (key_validate);
security/keys/proc.c +6 -4
@@ -1,4 +1,4 @@ -/* proc.c: proc files for key database enumeration +/* procfs files for key database enumeration * * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved. * Written by David Howells ([email protected])
@@ -61,7 +61,7 @@ static const struct file_operations proc_key_users_fops = { };/* -* declare the /proc files +* Declare the /proc files. */ static int __init key_proc_init (void ) {
@@ -83,7 +83,8 @@ static int __init key_proc_init(void)__initcall (key_proc_init);/* -* implement "/proc/keys" to provides a list of the keys on the system +* Implement "/proc/keys" to provide a list of the keys on the system that +* grant View permission to the caller. */ #ifdef CONFIG_KEYS_DEBUG_PROC_KEYS
@@ -291,7 +292,8 @@ static struct rb_node *key_user_first(struct rb_root *r) }/* -* implement "/proc/key-users" to provides a list of the key users +* Implement "/proc/key-users" to provides a list of the key users and their +* quotas. */ static int proc_key_users_open (struct inode *inode,struct file *file) {
security/keys/process_keys.c +75 -37
215 lines not on this page · raw message
security/keys/request_key.c +121 -43
255 lines not on this page · raw message
security/keys/request_key_auth.c +14 -16
@@ -1,4 +1,4 @@ -/* request_key_auth.c: request key authorisation controlling key def +/* Request key authorisation token key definition. * * Copyright (C) 2005 Red Hat, Inc. All Rights Reserved. * Written by David Howells ([email protected])
@@ -26,7 +26,7 @@ static void request_key_auth_destroy(struct key *);static long request_key_auth_read (const struct key *,char __user *,size_t );/* -* the request-key authorisation key type definition +* The request-key authorisation key type definition. */ struct key_type key_type_request_key_auth = { .name =".request_key_auth" ,
@@ -39,7 +39,7 @@ struct key_type key_type_request_key_auth = { };/* -* instantiate a request-key authorisation key +* Instantiate a request-key authorisation key. */ static int request_key_auth_instantiate(struct key *key, const void *data,
@@ -50,7 +50,7 @@ static int request_key_auth_instantiate(struct key *key, }/* -* reading a request-key authorisation key retrieves the callout information +* Describe an authorisation token. */ static void request_key_auth_describe (const struct key *key,struct seq_file *m)
@@ -63,7 +63,7 @@ static void request_key_auth_describe(const struct key *key, }/* -* read the callout_info data +* Read the callout_info data (retrieves the callout information). * - the key's semaphore is read-locked */ static long request_key_auth_read(const struct key *key,
@@ -89,8 +89,9 @@ static long request_key_auth_read(const struct key *key, }/* -* handle revocation of an authorisation token key -* - called with the key sem write-locked +* Handle revocation of an authorisation token key. +* +* Called with the key sem write-locked. */ static void request_key_auth_revoke (struct key *key) {
@@ -105,7 +106,7 @@ static void request_key_auth_revoke(struct key *key) }/* -* destroy an instantiation authorisation token key +* Destroy an instantiation authorisation token key. */ static void request_key_auth_destroy (struct key *key) {
@@ -125,8 +126,8 @@ static void request_key_auth_destroy(struct key *key) }/* -* create an authorisation token for /sbin/request-key or whoever to gain -* access to the caller's security data +* Create an authorisation token for /sbin/request-key or whoever to gain +* access to the caller's security data. */ struct key *request_key_auth_new (struct key *target,const void *callout_info,size_t callout_len,struct key *dest_keyring)
@@ -220,7 +221,7 @@ error_alloc: }/* -* see if an authorisation key is associated with a particular key +* See if an authorisation key is associated with a particular key. */ static int key_get_instantiation_authkey_match (const struct key *key,const void *_id)
@@ -232,11 +233,8 @@ static int key_get_instantiation_authkey_match(const struct key *key, }/* -* get the authorisation key for instantiation of a specific key if attached to -* the current process's keyrings -* - this key is inserted into a keyring and that is set as /sbin/request-key's -* session keyring -* - a target_id of zero specifies any valid token +* Search the current process's keyrings for the authorisation key for +* instantiation of a key. */ struct key *key_get_instantiation_authkey (key_serial_t target_id) {