Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a8b17ed0 authored by David Howells's avatar David Howells Committed by Linus Torvalds
Browse files

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.

Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 9093ba53
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -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() */
}
+0 −1
Original line number Diff line number Diff line
@@ -888,7 +888,6 @@ static int __init init_encrypted(void)
out:
	encrypted_shash_release();
	return ret;

}

static void __exit cleanup_encrypted(void)
+20 −60
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@ void __key_check(const struct key *key)
}
#endif

/*****************************************************************************/
/*
 * get the key quota record for a user, allocating a new record if one doesn't
 * already exist
@@ -130,10 +129,8 @@ struct key_user *key_user_lookup(uid_t uid, struct user_namespace *user_ns)
	kfree(candidate);
 out:
	return user;
}

} /* end key_user_lookup() */

/*****************************************************************************/
/*
 * dispose of a user structure
 */
@@ -146,10 +143,8 @@ void key_user_put(struct key_user *user)

		kfree(user);
	}
}

} /* end key_user_put() */

/*****************************************************************************/
/*
 * assign a key the next unique serial number
 * - these are assigned randomly to avoid security issues through covert
@@ -211,10 +206,8 @@ static inline void key_alloc_serial(struct key *key)
		if (key->serial < xkey->serial)
			goto attempt_insertion;
	}
}

} /* end key_alloc_serial() */

/*****************************************************************************/
/*
 * allocate a key of the specified type
 * - update the user's quota to reflect the existence of the key
@@ -344,12 +337,10 @@ struct key *key_alloc(struct key_type *type, const char *desc,
	key_user_put(user);
	key = ERR_PTR(-EDQUOT);
	goto error;

} /* end key_alloc() */
}

EXPORT_SYMBOL(key_alloc);

/*****************************************************************************/
/*
 * reserve an amount of quota for the key's payload
 */
@@ -384,12 +375,10 @@ int key_payload_reserve(struct key *key, size_t datalen)
		key->datalen = datalen;

	return ret;

} /* end key_payload_reserve() */
}

EXPORT_SYMBOL(key_payload_reserve);

/*****************************************************************************/
/*
 * instantiate a key and link it into the target keyring atomically
 * - called with the target keyring's semaphore writelocked
@@ -441,10 +430,8 @@ static int __key_instantiate_and_link(struct key *key,
		wake_up_bit(&key->flags, KEY_FLAG_USER_CONSTRUCT);

	return ret;
}

} /* end __key_instantiate_and_link() */

/*****************************************************************************/
/*
 * instantiate a key and link it into the target keyring atomically
 */
@@ -471,12 +458,10 @@ int key_instantiate_and_link(struct key *key,
		__key_link_end(keyring, key->type, prealloc);

	return ret;

} /* end key_instantiate_and_link() */
}

EXPORT_SYMBOL(key_instantiate_and_link);

/*****************************************************************************/
/*
 * negatively instantiate a key and link it into the target keyring atomically
 */
@@ -535,12 +520,10 @@ int key_negate_and_link(struct key *key,
		wake_up_bit(&key->flags, KEY_FLAG_USER_CONSTRUCT);

	return ret == 0 ? link_ret : ret;

} /* end key_negate_and_link() */
}

EXPORT_SYMBOL(key_negate_and_link);

/*****************************************************************************/
/*
 * do cleaning up in process context so that we don't have to disable
 * interrupts all over the place
@@ -601,10 +584,8 @@ static void key_cleanup(struct work_struct *work)

	/* there may, of course, be more than one key to destroy */
	goto go_again;
}

} /* end key_cleanup() */

/*****************************************************************************/
/*
 * dispose of a reference to a key
 * - when all the references are gone, we schedule the cleanup task to come and
@@ -618,12 +599,10 @@ void key_put(struct key *key)
		if (atomic_dec_and_test(&key->usage))
			schedule_work(&key_cleanup_task);
	}

} /* end key_put() */
}

EXPORT_SYMBOL(key_put);

/*****************************************************************************/
/*
 * find a key by its serial number
 */
@@ -664,10 +643,8 @@ struct key *key_lookup(key_serial_t id)
 error:
	spin_unlock(&key_serial_lock);
	return key;
}

} /* end key_lookup() */

/*****************************************************************************/
/*
 * find and lock the specified key type against removal
 * - we return with the sem readlocked
@@ -690,20 +667,16 @@ struct key_type *key_type_lookup(const char *type)

 found_kernel_type:
	return ktype;
}

} /* end key_type_lookup() */

/*****************************************************************************/
/*
 * unlock a key type
 */
void key_type_put(struct key_type *ktype)
{
	up_read(&key_types_sem);
}

} /* end key_type_put() */

/*****************************************************************************/
/*
 * attempt to update an existing key
 * - the key has an incremented refcount
@@ -742,10 +715,8 @@ static inline key_ref_t __key_update(key_ref_t key_ref,
	key_put(key);
	key_ref = ERR_PTR(ret);
	goto out;
}

} /* end __key_update() */

/*****************************************************************************/
/*
 * search the specified keyring for a key of the same description; if one is
 * found, update it, otherwise add a new one
@@ -855,12 +826,10 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,

	key_ref = __key_update(key_ref, payload, plen);
	goto error;

} /* end key_create_or_update() */
}

EXPORT_SYMBOL(key_create_or_update);

/*****************************************************************************/
/*
 * update a key
 */
@@ -891,12 +860,10 @@ int key_update(key_ref_t key_ref, const void *payload, size_t plen)

 error:
	return ret;

} /* end key_update() */
}

EXPORT_SYMBOL(key_update);

/*****************************************************************************/
/*
 * revoke a key
 */
@@ -926,12 +893,10 @@ void key_revoke(struct key *key)
	}

	up_write(&key->sem);

} /* end key_revoke() */
}

EXPORT_SYMBOL(key_revoke);

/*****************************************************************************/
/*
 * register a type of key
 */
@@ -956,12 +921,10 @@ int register_key_type(struct key_type *ktype)
 out:
	up_write(&key_types_sem);
	return ret;

} /* end register_key_type() */
}

EXPORT_SYMBOL(register_key_type);

/*****************************************************************************/
/*
 * unregister a type of key
 */
@@ -1010,12 +973,10 @@ void unregister_key_type(struct key_type *ktype)
	up_write(&key_types_sem);

	key_schedule_gc(0);

} /* end unregister_key_type() */
}

EXPORT_SYMBOL(unregister_key_type);

/*****************************************************************************/
/*
 * initialise the key management stuff
 */
@@ -1037,5 +998,4 @@ void __init key_init(void)

	rb_insert_color(&root_key_user.node,
			&key_user_tree);

} /* end key_init() */
}
+19 −58
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ static int key_get_type_from_user(char *type,
	return 0;
}

/*****************************************************************************/
/*
 * extract the description of a new key from userspace and either add it as a
 * new key to the specified keyring or update a matching key in that keyring
@@ -132,10 +131,8 @@ SYSCALL_DEFINE5(add_key, const char __user *, _type,
	kfree(description);
 error:
	return ret;
}

} /* end sys_add_key() */

/*****************************************************************************/
/*
 * search the process keyrings for a matching key
 * - nested keyrings may also be searched if they have Search permission
@@ -222,10 +219,8 @@ SYSCALL_DEFINE4(request_key, const char __user *, _type,
	kfree(description);
error:
	return ret;
}

} /* end sys_request_key() */

/*****************************************************************************/
/*
 * get the ID of the specified process keyring
 * - the keyring must have search permission to be found
@@ -251,7 +246,6 @@ long keyctl_get_keyring_ID(key_serial_t id, int create)

} /* end keyctl_get_keyring_ID() */

/*****************************************************************************/
/*
 * join the session keyring
 * - implements keyctl(KEYCTL_JOIN_SESSION_KEYRING)
@@ -277,10 +271,8 @@ long keyctl_join_session_keyring(const char __user *_name)

error:
	return ret;
}

} /* end keyctl_join_session_keyring() */

/*****************************************************************************/
/*
 * update a key's data payload
 * - the key must be writable
@@ -326,10 +318,8 @@ long keyctl_update_key(key_serial_t id,
	kfree(payload);
error:
	return ret;
}

} /* end keyctl_update_key() */

/*****************************************************************************/
/*
 * revoke a key
 * - the key must be writable
@@ -358,10 +348,8 @@ long keyctl_revoke_key(key_serial_t id)
	key_ref_put(key_ref);
error:
	return ret;
}

} /* end keyctl_revoke_key() */

/*****************************************************************************/
/*
 * clear the specified process keyring
 * - the keyring must be writable
@@ -383,10 +371,8 @@ long keyctl_keyring_clear(key_serial_t ringid)
	key_ref_put(keyring_ref);
error:
	return ret;
}

} /* end keyctl_keyring_clear() */

/*****************************************************************************/
/*
 * link a key into a keyring
 * - the keyring must be writable
@@ -417,10 +403,8 @@ long keyctl_keyring_link(key_serial_t id, key_serial_t ringid)
	key_ref_put(keyring_ref);
error:
	return ret;
}

} /* end keyctl_keyring_link() */

/*****************************************************************************/
/*
 * unlink the first attachment of a key from a keyring
 * - the keyring must be writable
@@ -451,10 +435,8 @@ long keyctl_keyring_unlink(key_serial_t id, key_serial_t ringid)
	key_ref_put(keyring_ref);
error:
	return ret;
}

} /* end keyctl_keyring_unlink() */

/*****************************************************************************/
/*
 * describe a user key
 * - the key must have view permission
@@ -531,10 +513,8 @@ long keyctl_describe_key(key_serial_t keyid,
	key_ref_put(key_ref);
error:
	return ret;
}

} /* end keyctl_describe_key() */

/*****************************************************************************/
/*
 * search the specified keyring for a matching key
 * - the start keyring must be searchable
@@ -626,10 +606,8 @@ long keyctl_keyring_search(key_serial_t ringid,
	kfree(description);
error:
	return ret;
}

} /* end keyctl_keyring_search() */

/*****************************************************************************/
/*
 * read a user key's payload
 * - the keyring must be readable or the key must be searchable from the
@@ -688,10 +666,8 @@ long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
	key_put(key);
error:
	return ret;
}

} /* end keyctl_read_key() */

/*****************************************************************************/
/*
 * change the ownership of a key
 * - the keyring owned by the changer
@@ -796,10 +772,8 @@ long keyctl_chown_key(key_serial_t id, uid_t uid, gid_t gid)
	zapowner = newowner;
	ret = -EDQUOT;
	goto error_put;
}

} /* end keyctl_chown_key() */

/*****************************************************************************/
/*
 * change the permission mask on a key
 * - the keyring owned by the changer
@@ -838,8 +812,7 @@ long keyctl_setperm_key(key_serial_t id, key_perm_t perm)
	key_put(key);
error:
	return ret;

} /* end keyctl_setperm_key() */
}

/*
 * get the destination keyring for instantiation
@@ -895,7 +868,6 @@ static int keyctl_change_reqkey_auth(struct key *key)
	return commit_creds(new);
}

/*****************************************************************************/
/*
 * instantiate the key with the specified payload, and, if one is given, link
 * the key into the keyring
@@ -973,10 +945,8 @@ long keyctl_instantiate_key(key_serial_t id,
		vfree(payload);
error:
	return ret;
}

} /* end keyctl_instantiate_key() */

/*****************************************************************************/
/*
 * negatively instantiate the key with the given timeout (in seconds), and, if
 * one is given, link the key into the keyring
@@ -1020,10 +990,8 @@ long keyctl_negate_key(key_serial_t id, unsigned timeout, key_serial_t ringid)

error:
	return ret;
}

} /* end keyctl_negate_key() */

/*****************************************************************************/
/*
 * set the default keyring in which request_key() will cache keys
 * - return the old setting
@@ -1079,10 +1047,8 @@ long keyctl_set_reqkey_keyring(int reqkey_defl)
error:
	abort_creds(new);
	return ret;
}

} /* end keyctl_set_reqkey_keyring() */

/*****************************************************************************/
/*
 * set or clear the timeout for a key
 */
@@ -1136,10 +1102,8 @@ long keyctl_set_timeout(key_serial_t id, unsigned timeout)
	ret = 0;
error:
	return ret;
}

} /* end keyctl_set_timeout() */

/*****************************************************************************/
/*
 * assume the authority to instantiate the specified key
 */
@@ -1178,8 +1142,7 @@ long keyctl_assume_authority(key_serial_t id)
	ret = authkey->serial;
error:
	return ret;

} /* end keyctl_assume_authority() */
}

/*
 * get the security label of a key
@@ -1348,7 +1311,6 @@ long keyctl_session_to_parent(void)
#endif /* !TIF_NOTIFY_RESUME */
}

/*****************************************************************************/
/*
 * the key control system call
 */
@@ -1439,5 +1401,4 @@ SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3,
	default:
		return -EOPNOTSUPP;
	}

} /* end sys_keyctl() */
}
+16 −48
Original line number Diff line number Diff line
@@ -80,7 +80,6 @@ EXPORT_SYMBOL(key_type_keyring);
 */
static DECLARE_RWSEM(keyring_serialise_link_sem);

/*****************************************************************************/
/*
 * publish the name of a keyring so that it can be found by name (if it has
 * one)
@@ -102,10 +101,8 @@ static void keyring_publish_name(struct key *keyring)

		write_unlock(&keyring_name_lock);
	}
}

} /* end keyring_publish_name() */

/*****************************************************************************/
/*
 * initialise a keyring
 * - we object if we were given any data
@@ -123,10 +120,8 @@ static int keyring_instantiate(struct key *keyring,
	}

	return ret;
}

} /* end keyring_instantiate() */

/*****************************************************************************/
/*
 * match keyrings on their name
 */
@@ -134,10 +129,8 @@ static int keyring_match(const struct key *keyring, const void *description)
{
	return keyring->description &&
		strcmp(keyring->description, description) == 0;
}

} /* end keyring_match() */

/*****************************************************************************/
/*
 * dispose of the data dangling from the corpse of a keyring
 */
@@ -164,10 +157,8 @@ static void keyring_destroy(struct key *keyring)
			key_put(klist->keys[loop]);
		kfree(klist);
	}
}

} /* end keyring_destroy() */

/*****************************************************************************/
/*
 * describe the keyring
 */
@@ -187,10 +178,8 @@ static void keyring_describe(const struct key *keyring, struct seq_file *m)
	else
		seq_puts(m, ": empty");
	rcu_read_unlock();
}

} /* end keyring_describe() */

/*****************************************************************************/
/*
 * read a list of key IDs from the keyring's contents
 * - the keyring's semaphore is read-locked
@@ -241,10 +230,8 @@ static long keyring_read(const struct key *keyring,

error:
	return ret;
}

} /* end keyring_read() */

/*****************************************************************************/
/*
 * allocate a keyring and link into the destination keyring
 */
@@ -269,10 +256,8 @@ struct key *keyring_alloc(const char *description, uid_t uid, gid_t gid,
	}

	return keyring;
}

} /* end keyring_alloc() */

/*****************************************************************************/
/*
 * search the supplied keyring tree for a key that matches the criterion
 * - perform a breadth-then-depth search up to the prescribed limit
@@ -444,10 +429,8 @@ key_ref_t keyring_search_aux(key_ref_t keyring_ref,
	rcu_read_unlock();
error:
	return key_ref;
}

} /* end keyring_search_aux() */

/*****************************************************************************/
/*
 * search the supplied keyring tree for a key that matches the criterion
 * - perform a breadth-then-depth search up to the prescribed limit
@@ -465,12 +448,10 @@ key_ref_t keyring_search(key_ref_t keyring,

	return keyring_search_aux(keyring, current->cred,
				  type, description, type->match);

} /* end keyring_search() */
}

EXPORT_SYMBOL(keyring_search);

/*****************************************************************************/
/*
 * search the given keyring only (no recursion)
 * - keyring must be locked by caller
@@ -514,10 +495,8 @@ key_ref_t __keyring_search_one(key_ref_t keyring_ref,
	atomic_inc(&key->usage);
	rcu_read_unlock();
	return make_key_ref(key, possessed);
}

} /* end __keyring_search_one() */

/*****************************************************************************/
/*
 * find a keyring with the specified name
 * - all named keyrings are searched
@@ -569,10 +548,8 @@ struct key *find_keyring_by_name(const char *name, bool skip_perm_check)
out:
	read_unlock(&keyring_name_lock);
	return keyring;
}

} /* end find_keyring_by_name() */

/*****************************************************************************/
/*
 * see if a cycle will will be created by inserting acyclic tree B in acyclic
 * tree A at the topmost level (ie: as a direct child of A)
@@ -657,8 +634,7 @@ static int keyring_detect_cycle(struct key *A, struct key *B)
cycle_detected:
	ret = -EDEADLK;
	goto error;

} /* end keyring_detect_cycle() */
}

/*
 * dispose of a keyring list after the RCU grace period, freeing the unlinked
@@ -898,7 +874,6 @@ int key_link(struct key *keyring, struct key *key)

EXPORT_SYMBOL(key_link);

/*****************************************************************************/
/*
 * unlink the first link to a key from a keyring
 */
@@ -968,12 +943,10 @@ int key_unlink(struct key *keyring, struct key *key)
	ret = -ENOMEM;
	up_write(&keyring->sem);
	goto error;

} /* end key_unlink() */
}

EXPORT_SYMBOL(key_unlink);

/*****************************************************************************/
/*
 * dispose of a keyring list after the RCU grace period, releasing the keys it
 * links to
@@ -989,10 +962,8 @@ static void keyring_clear_rcu_disposal(struct rcu_head *rcu)
		key_put(klist->keys[loop]);

	kfree(klist);
}

} /* end keyring_clear_rcu_disposal() */

/*****************************************************************************/
/*
 * clear the specified process keyring
 * - implements keyctl(KEYCTL_CLEAR)
@@ -1027,12 +998,10 @@ int keyring_clear(struct key *keyring)
	}

	return ret;

} /* end keyring_clear() */
}

EXPORT_SYMBOL(keyring_clear);

/*****************************************************************************/
/*
 * dispose of the links from a revoked keyring
 * - called with the key sem write-locked
@@ -1050,8 +1019,7 @@ static void keyring_revoke(struct key *keyring)
		rcu_assign_pointer(keyring->payload.subscriptions, NULL);
		call_rcu(&klist->rcu, keyring_clear_rcu_disposal);
	}

} /* end keyring_revoke() */
}

/*
 * Determine whether a key is dead
Loading