xref: /openbmc/linux/security/keys/internal.h (revision dcf49dbc)
1973c9f4fSDavid Howells /* Authentication token and access key management internal defs
21da177e4SLinus Torvalds  *
376181c13SDavid Howells  * Copyright (C) 2003-5, 2007 Red Hat, Inc. All Rights Reserved.
41da177e4SLinus Torvalds  * Written by David Howells (dhowells@redhat.com)
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or
71da177e4SLinus Torvalds  * modify it under the terms of the GNU General Public License
81da177e4SLinus Torvalds  * as published by the Free Software Foundation; either version
91da177e4SLinus Torvalds  * 2 of the License, or (at your option) any later version.
101da177e4SLinus Torvalds  */
111da177e4SLinus Torvalds 
121da177e4SLinus Torvalds #ifndef _INTERNAL_H
131da177e4SLinus Torvalds #define _INTERNAL_H
141da177e4SLinus Torvalds 
15d84f4f99SDavid Howells #include <linux/sched.h>
165dd43ce2SIngo Molnar #include <linux/wait_bit.h>
175b825c3aSIngo Molnar #include <linux/cred.h>
1876181c13SDavid Howells #include <linux/key-type.h>
19413cd3d9SOleg Nesterov #include <linux/task_work.h>
20ddbb4114SMat Martineau #include <linux/keyctl.h>
21ddb99e11SElena Reshetova #include <linux/refcount.h>
22f1c316a3SStephan Mueller #include <linux/compat.h>
231da177e4SLinus Torvalds 
24a27bb332SKent Overstreet struct iovec;
25a27bb332SKent Overstreet 
2676181c13SDavid Howells #ifdef __KDEBUG
2776181c13SDavid Howells #define kenter(FMT, ...) \
28dd6f953aSHarvey Harrison 	printk(KERN_DEBUG "==> %s("FMT")\n", __func__, ##__VA_ARGS__)
2976181c13SDavid Howells #define kleave(FMT, ...) \
30dd6f953aSHarvey Harrison 	printk(KERN_DEBUG "<== %s()"FMT"\n", __func__, ##__VA_ARGS__)
3176181c13SDavid Howells #define kdebug(FMT, ...) \
32d84f4f99SDavid Howells 	printk(KERN_DEBUG "   "FMT"\n", ##__VA_ARGS__)
333e30148cSDavid Howells #else
3476181c13SDavid Howells #define kenter(FMT, ...) \
35dd6f953aSHarvey Harrison 	no_printk(KERN_DEBUG "==> %s("FMT")\n", __func__, ##__VA_ARGS__)
3676181c13SDavid Howells #define kleave(FMT, ...) \
37dd6f953aSHarvey Harrison 	no_printk(KERN_DEBUG "<== %s()"FMT"\n", __func__, ##__VA_ARGS__)
3876181c13SDavid Howells #define kdebug(FMT, ...) \
3976181c13SDavid Howells 	no_printk(KERN_DEBUG FMT"\n", ##__VA_ARGS__)
403e30148cSDavid Howells #endif
413e30148cSDavid Howells 
420c061b57SDavid Howells extern struct key_type key_type_dead;
431da177e4SLinus Torvalds extern struct key_type key_type_user;
449f6ed2caSJeff Layton extern struct key_type key_type_logon;
451da177e4SLinus Torvalds 
461da177e4SLinus Torvalds /*****************************************************************************/
471da177e4SLinus Torvalds /*
48973c9f4fSDavid Howells  * Keep track of keys for a user.
49973c9f4fSDavid Howells  *
50973c9f4fSDavid Howells  * This needs to be separate to user_struct to avoid a refcount-loop
51973c9f4fSDavid Howells  * (user_struct pins some keyrings which pin this struct).
52973c9f4fSDavid Howells  *
53973c9f4fSDavid Howells  * We also keep track of keys under request from userspace for this UID here.
541da177e4SLinus Torvalds  */
551da177e4SLinus Torvalds struct key_user {
561da177e4SLinus Torvalds 	struct rb_node		node;
5776181c13SDavid Howells 	struct mutex		cons_lock;	/* construction initiation lock */
581da177e4SLinus Torvalds 	spinlock_t		lock;
59ddb99e11SElena Reshetova 	refcount_t		usage;		/* for accessing qnkeys & qnbytes */
601da177e4SLinus Torvalds 	atomic_t		nkeys;		/* number of keys */
611da177e4SLinus Torvalds 	atomic_t		nikeys;		/* number of instantiated keys */
629a56c2dbSEric W. Biederman 	kuid_t			uid;
631da177e4SLinus Torvalds 	int			qnkeys;		/* number of keys allocated to this user */
641da177e4SLinus Torvalds 	int			qnbytes;	/* number of bytes allocated to this user */
651da177e4SLinus Torvalds };
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds extern struct rb_root	key_user_tree;
681da177e4SLinus Torvalds extern spinlock_t	key_user_lock;
691da177e4SLinus Torvalds extern struct key_user	root_key_user;
701da177e4SLinus Torvalds 
719a56c2dbSEric W. Biederman extern struct key_user *key_user_lookup(kuid_t uid);
721da177e4SLinus Torvalds extern void key_user_put(struct key_user *user);
731da177e4SLinus Torvalds 
740b77f5bfSDavid Howells /*
75973c9f4fSDavid Howells  * Key quota limits.
760b77f5bfSDavid Howells  * - root has its own separate limits to everyone else
770b77f5bfSDavid Howells  */
780b77f5bfSDavid Howells extern unsigned key_quota_root_maxkeys;
790b77f5bfSDavid Howells extern unsigned key_quota_root_maxbytes;
800b77f5bfSDavid Howells extern unsigned key_quota_maxkeys;
810b77f5bfSDavid Howells extern unsigned key_quota_maxbytes;
820b77f5bfSDavid Howells 
830b77f5bfSDavid Howells #define KEYQUOTA_LINK_BYTES	4		/* a link in a keyring is worth 4 bytes */
841da177e4SLinus Torvalds 
851da177e4SLinus Torvalds 
868bc16deaSDavid Howells extern struct kmem_cache *key_jar;
871da177e4SLinus Torvalds extern struct rb_root key_serial_tree;
881da177e4SLinus Torvalds extern spinlock_t key_serial_lock;
8976181c13SDavid Howells extern struct mutex key_construction_mutex;
901da177e4SLinus Torvalds extern wait_queue_head_t request_key_conswq;
911da177e4SLinus Torvalds 
92355ef8e1SDavid Howells extern void key_set_index_key(struct keyring_index_key *index_key);
93e9e349b0SDavid Howells extern struct key_type *key_type_lookup(const char *type);
94e9e349b0SDavid Howells extern void key_type_put(struct key_type *ktype);
95e9e349b0SDavid Howells 
96df593ee2SDavid Howells extern int __key_link_lock(struct key *keyring,
97df593ee2SDavid Howells 			   const struct keyring_index_key *index_key);
98ed0ac5c7SDavid Howells extern int __key_move_lock(struct key *l_keyring, struct key *u_keyring,
99ed0ac5c7SDavid Howells 			   const struct keyring_index_key *index_key);
100f70e2e06SDavid Howells extern int __key_link_begin(struct key *keyring,
10116feef43SDavid Howells 			    const struct keyring_index_key *index_key,
102b2a4df20SDavid Howells 			    struct assoc_array_edit **_edit);
103f70e2e06SDavid Howells extern int __key_link_check_live_key(struct key *keyring, struct key *key);
104b2a4df20SDavid Howells extern void __key_link(struct key *key, struct assoc_array_edit **_edit);
105f70e2e06SDavid Howells extern void __key_link_end(struct key *keyring,
10616feef43SDavid Howells 			   const struct keyring_index_key *index_key,
107b2a4df20SDavid Howells 			   struct assoc_array_edit *edit);
1081da177e4SLinus Torvalds 
109b2a4df20SDavid Howells extern key_ref_t find_key_to_update(key_ref_t keyring_ref,
110e57e8669SDavid Howells 				    const struct keyring_index_key *index_key);
1111da177e4SLinus Torvalds 
1123e30148cSDavid Howells extern struct key *keyring_search_instkey(struct key *keyring,
1133e30148cSDavid Howells 					  key_serial_t target_id);
1143e30148cSDavid Howells 
115b2a4df20SDavid Howells extern int iterate_over_keyring(const struct key *keyring,
116b2a4df20SDavid Howells 				int (*func)(const struct key *key, void *data),
117b2a4df20SDavid Howells 				void *data);
118b2a4df20SDavid Howells 
1194bdf0bc3SDavid Howells struct keyring_search_context {
1204bdf0bc3SDavid Howells 	struct keyring_index_key index_key;
1214bdf0bc3SDavid Howells 	const struct cred	*cred;
12246291959SDavid Howells 	struct key_match_data	match_data;
1234bdf0bc3SDavid Howells 	unsigned		flags;
124614d8c39SDavid Howells #define KEYRING_SEARCH_NO_STATE_CHECK	0x0001	/* Skip state checks */
125614d8c39SDavid Howells #define KEYRING_SEARCH_DO_STATE_CHECK	0x0002	/* Override NO_STATE_CHECK */
126614d8c39SDavid Howells #define KEYRING_SEARCH_NO_UPDATE_TIME	0x0004	/* Don't update times */
127614d8c39SDavid Howells #define KEYRING_SEARCH_NO_CHECK_PERM	0x0008	/* Don't check permissions */
128614d8c39SDavid Howells #define KEYRING_SEARCH_DETECT_TOO_DEEP	0x0010	/* Give an error on excessive depth */
1290b0a8415SDavid Howells #define KEYRING_SEARCH_SKIP_EXPIRED	0x0020	/* Ignore expired keys (intention to replace) */
130dcf49dbcSDavid Howells #define KEYRING_SEARCH_RECURSE		0x0040	/* Search child keyrings also */
1311da177e4SLinus Torvalds 
132b2a4df20SDavid Howells 	int (*iterator)(const void *object, void *iterator_data);
133b2a4df20SDavid Howells 
1344bdf0bc3SDavid Howells 	/* Internal stuff */
1354bdf0bc3SDavid Howells 	int			skipped_ret;
1364bdf0bc3SDavid Howells 	bool			possessed;
1374bdf0bc3SDavid Howells 	key_ref_t		result;
138074d5898SBaolin Wang 	time64_t		now;
1394bdf0bc3SDavid Howells };
1404bdf0bc3SDavid Howells 
1410c903ab6SDavid Howells extern bool key_default_cmp(const struct key *key,
142c06cfb08SDavid Howells 			    const struct key_match_data *match_data);
143e59428f7SDavid Howells extern key_ref_t keyring_search_rcu(key_ref_t keyring_ref,
1444bdf0bc3SDavid Howells 				    struct keyring_search_context *ctx);
1454bdf0bc3SDavid Howells 
146e59428f7SDavid Howells extern key_ref_t search_cred_keyrings_rcu(struct keyring_search_context *ctx);
147e59428f7SDavid Howells extern key_ref_t search_process_keyrings_rcu(struct keyring_search_context *ctx);
1481da177e4SLinus Torvalds 
149237bbd29SEric Biggers extern struct key *find_keyring_by_name(const char *name, bool uid_keyring);
1501da177e4SLinus Torvalds 
1518bbf4976SDavid Howells extern int install_user_keyrings(void);
152d84f4f99SDavid Howells extern int install_thread_keyring_to_cred(struct cred *);
153d84f4f99SDavid Howells extern int install_process_keyring_to_cred(struct cred *);
154685bfd2cSOleg Nesterov extern int install_session_keyring_to_cred(struct cred *, struct key *);
1553e30148cSDavid Howells 
1563e30148cSDavid Howells extern struct key *request_key_and_link(struct key_type *type,
1573e30148cSDavid Howells 					const char *description,
1584a38e122SDavid Howells 					const void *callout_info,
1594a38e122SDavid Howells 					size_t callout_len,
1604e54f085SDavid Howells 					void *aux,
1617e047ef5SDavid Howells 					struct key *dest_keyring,
1627e047ef5SDavid Howells 					unsigned long flags);
1633e30148cSDavid Howells 
1640c903ab6SDavid Howells extern bool lookup_user_key_possessed(const struct key *key,
16546291959SDavid Howells 				      const struct key_match_data *match_data);
1665593122eSDavid Howells #define KEY_LOOKUP_CREATE	0x01
1675593122eSDavid Howells #define KEY_LOOKUP_PARTIAL	0x02
1685593122eSDavid Howells #define KEY_LOOKUP_FOR_UNLINK	0x04
169e9e349b0SDavid Howells 
170e9e349b0SDavid Howells extern long join_session_keyring(const char *name);
17167d12145SAl Viro extern void key_change_session_keyring(struct callback_head *twork);
172e9e349b0SDavid Howells 
1730c061b57SDavid Howells extern struct work_struct key_gc_work;
1745d135440SDavid Howells extern unsigned key_gc_delay;
175074d5898SBaolin Wang extern void keyring_gc(struct key *keyring, time64_t limit);
1762b6aa412SMat Martineau extern void keyring_restriction_gc(struct key *keyring,
1772b6aa412SMat Martineau 				   struct key_type *dead_type);
178074d5898SBaolin Wang extern void key_schedule_gc(time64_t gc_at);
179fd75815fSDavid Howells extern void key_schedule_gc_links(void);
1800c061b57SDavid Howells extern void key_gc_keytype(struct key_type *ktype);
1815d135440SDavid Howells 
182e9e349b0SDavid Howells extern int key_task_permission(const key_ref_t key_ref,
183d84f4f99SDavid Howells 			       const struct cred *cred,
184e9e349b0SDavid Howells 			       key_perm_t perm);
185e9e349b0SDavid Howells 
186973c9f4fSDavid Howells /*
187973c9f4fSDavid Howells  * Check to see whether permission is granted to use a key in the desired way.
188973c9f4fSDavid Howells  */
189f5895943SDavid Howells static inline int key_permission(const key_ref_t key_ref, unsigned perm)
190e9e349b0SDavid Howells {
191d84f4f99SDavid Howells 	return key_task_permission(key_ref, current_cred(), perm);
192e9e349b0SDavid Howells }
193e9e349b0SDavid Howells 
1943e30148cSDavid Howells extern struct key_type key_type_request_key_auth;
1953e30148cSDavid Howells extern struct key *request_key_auth_new(struct key *target,
196822ad64dSDavid Howells 					const char *op,
1974a38e122SDavid Howells 					const void *callout_info,
1988bbf4976SDavid Howells 					size_t callout_len,
1998bbf4976SDavid Howells 					struct key *dest_keyring);
2003e30148cSDavid Howells 
2013e30148cSDavid Howells extern struct key *key_get_instantiation_authkey(key_serial_t target_id);
2021da177e4SLinus Torvalds 
2031da177e4SLinus Torvalds /*
204fd75815fSDavid Howells  * Determine whether a key is dead.
205fd75815fSDavid Howells  */
206074d5898SBaolin Wang static inline bool key_is_dead(const struct key *key, time64_t limit)
207fd75815fSDavid Howells {
208fd75815fSDavid Howells 	return
209fd75815fSDavid Howells 		key->flags & ((1 << KEY_FLAG_DEAD) |
210fd75815fSDavid Howells 			      (1 << KEY_FLAG_INVALIDATED)) ||
211fd75815fSDavid Howells 		(key->expiry > 0 && key->expiry <= limit);
212fd75815fSDavid Howells }
213fd75815fSDavid Howells 
214fd75815fSDavid Howells /*
215973c9f4fSDavid Howells  * keyctl() functions
2161da177e4SLinus Torvalds  */
2171da177e4SLinus Torvalds extern long keyctl_get_keyring_ID(key_serial_t, int);
2181da177e4SLinus Torvalds extern long keyctl_join_session_keyring(const char __user *);
2191da177e4SLinus Torvalds extern long keyctl_update_key(key_serial_t, const void __user *, size_t);
2201da177e4SLinus Torvalds extern long keyctl_revoke_key(key_serial_t);
2211da177e4SLinus Torvalds extern long keyctl_keyring_clear(key_serial_t);
2221da177e4SLinus Torvalds extern long keyctl_keyring_link(key_serial_t, key_serial_t);
223ed0ac5c7SDavid Howells extern long keyctl_keyring_move(key_serial_t, key_serial_t, key_serial_t, unsigned int);
2241da177e4SLinus Torvalds extern long keyctl_keyring_unlink(key_serial_t, key_serial_t);
2251da177e4SLinus Torvalds extern long keyctl_describe_key(key_serial_t, char __user *, size_t);
2261da177e4SLinus Torvalds extern long keyctl_keyring_search(key_serial_t, const char __user *,
2271da177e4SLinus Torvalds 				  const char __user *, key_serial_t);
2281da177e4SLinus Torvalds extern long keyctl_read_key(key_serial_t, char __user *, size_t);
2291da177e4SLinus Torvalds extern long keyctl_chown_key(key_serial_t, uid_t, gid_t);
2301da177e4SLinus Torvalds extern long keyctl_setperm_key(key_serial_t, key_perm_t);
2311da177e4SLinus Torvalds extern long keyctl_instantiate_key(key_serial_t, const void __user *,
2321da177e4SLinus Torvalds 				   size_t, key_serial_t);
2331da177e4SLinus Torvalds extern long keyctl_negate_key(key_serial_t, unsigned, key_serial_t);
2343e30148cSDavid Howells extern long keyctl_set_reqkey_keyring(int);
235017679c4SDavid Howells extern long keyctl_set_timeout(key_serial_t, unsigned);
236b5f545c8SDavid Howells extern long keyctl_assume_authority(key_serial_t);
23770a5bb72SDavid Howells extern long keyctl_get_security(key_serial_t keyid, char __user *buffer,
23870a5bb72SDavid Howells 				size_t buflen);
239ee18d64cSDavid Howells extern long keyctl_session_to_parent(void);
240fdd1b945SDavid Howells extern long keyctl_reject_key(key_serial_t, unsigned, unsigned, key_serial_t);
241ee009e4aSDavid Howells extern long keyctl_instantiate_key_iov(key_serial_t,
242ee009e4aSDavid Howells 				       const struct iovec __user *,
243ee009e4aSDavid Howells 				       unsigned, key_serial_t);
244fd75815fSDavid Howells extern long keyctl_invalidate_key(key_serial_t);
245ee009e4aSDavid Howells 
246b353a1f7SAl Viro struct iov_iter;
247ee009e4aSDavid Howells extern long keyctl_instantiate_key_common(key_serial_t,
248b353a1f7SAl Viro 					  struct iov_iter *,
249b353a1f7SAl Viro 					  key_serial_t);
2506563c91fSMat Martineau extern long keyctl_restrict_keyring(key_serial_t id,
2516563c91fSMat Martineau 				    const char __user *_type,
2526563c91fSMat Martineau 				    const char __user *_restriction);
253f36f8c75SDavid Howells #ifdef CONFIG_PERSISTENT_KEYRINGS
254f36f8c75SDavid Howells extern long keyctl_get_persistent(uid_t, key_serial_t);
255f36f8c75SDavid Howells extern unsigned persistent_keyring_expiry;
256f36f8c75SDavid Howells #else
257f36f8c75SDavid Howells static inline long keyctl_get_persistent(uid_t uid, key_serial_t destring)
258f36f8c75SDavid Howells {
259f36f8c75SDavid Howells 	return -EOPNOTSUPP;
260f36f8c75SDavid Howells }
261f36f8c75SDavid Howells #endif
2621da177e4SLinus Torvalds 
263ddbb4114SMat Martineau #ifdef CONFIG_KEY_DH_OPERATIONS
264ddbb4114SMat Martineau extern long keyctl_dh_compute(struct keyctl_dh_params __user *, char __user *,
265f1c316a3SStephan Mueller 			      size_t, struct keyctl_kdf_params __user *);
266f1c316a3SStephan Mueller extern long __keyctl_dh_compute(struct keyctl_dh_params __user *, char __user *,
267f1c316a3SStephan Mueller 				size_t, struct keyctl_kdf_params *);
268f1c316a3SStephan Mueller #ifdef CONFIG_KEYS_COMPAT
269f1c316a3SStephan Mueller extern long compat_keyctl_dh_compute(struct keyctl_dh_params __user *params,
270f1c316a3SStephan Mueller 				char __user *buffer, size_t buflen,
271f1c316a3SStephan Mueller 				struct compat_keyctl_kdf_params __user *kdf);
272f1c316a3SStephan Mueller #endif
273f1c316a3SStephan Mueller #define KEYCTL_KDF_MAX_OUTPUT_LEN	1024	/* max length of KDF output */
274f1c316a3SStephan Mueller #define KEYCTL_KDF_MAX_OI_LEN		64	/* max length of otherinfo */
275ddbb4114SMat Martineau #else
276ddbb4114SMat Martineau static inline long keyctl_dh_compute(struct keyctl_dh_params __user *params,
2774693fc73SStephan Mueller 				     char __user *buffer, size_t buflen,
278f1c316a3SStephan Mueller 				     struct keyctl_kdf_params __user *kdf)
279ddbb4114SMat Martineau {
280ddbb4114SMat Martineau 	return -EOPNOTSUPP;
281ddbb4114SMat Martineau }
282f1c316a3SStephan Mueller 
283f1c316a3SStephan Mueller #ifdef CONFIG_KEYS_COMPAT
284f1c316a3SStephan Mueller static inline long compat_keyctl_dh_compute(
285f1c316a3SStephan Mueller 				struct keyctl_dh_params __user *params,
286f1c316a3SStephan Mueller 				char __user *buffer, size_t buflen,
287f1c316a3SStephan Mueller 				struct keyctl_kdf_params __user *kdf)
288f1c316a3SStephan Mueller {
289f1c316a3SStephan Mueller 	return -EOPNOTSUPP;
290f1c316a3SStephan Mueller }
291f1c316a3SStephan Mueller #endif
292ddbb4114SMat Martineau #endif
293ddbb4114SMat Martineau 
29400d60fd3SDavid Howells #ifdef CONFIG_ASYMMETRIC_KEY_TYPE
29500d60fd3SDavid Howells extern long keyctl_pkey_query(key_serial_t,
29600d60fd3SDavid Howells 			      const char __user *,
29700d60fd3SDavid Howells 			      struct keyctl_pkey_query __user *);
29800d60fd3SDavid Howells 
29900d60fd3SDavid Howells extern long keyctl_pkey_verify(const struct keyctl_pkey_params __user *,
30000d60fd3SDavid Howells 			       const char __user *,
30100d60fd3SDavid Howells 			       const void __user *, const void __user *);
30200d60fd3SDavid Howells 
30300d60fd3SDavid Howells extern long keyctl_pkey_e_d_s(int,
30400d60fd3SDavid Howells 			      const struct keyctl_pkey_params __user *,
30500d60fd3SDavid Howells 			      const char __user *,
30600d60fd3SDavid Howells 			      const void __user *, void __user *);
30700d60fd3SDavid Howells #else
30800d60fd3SDavid Howells static inline long keyctl_pkey_query(key_serial_t id,
30900d60fd3SDavid Howells 				     const char __user *_info,
31000d60fd3SDavid Howells 				     struct keyctl_pkey_query __user *_res)
31100d60fd3SDavid Howells {
31200d60fd3SDavid Howells 	return -EOPNOTSUPP;
31300d60fd3SDavid Howells }
31400d60fd3SDavid Howells 
31500d60fd3SDavid Howells static inline long keyctl_pkey_verify(const struct keyctl_pkey_params __user *params,
31600d60fd3SDavid Howells 				      const char __user *_info,
31700d60fd3SDavid Howells 				      const void __user *_in,
31800d60fd3SDavid Howells 				      const void __user *_in2)
31900d60fd3SDavid Howells {
32000d60fd3SDavid Howells 	return -EOPNOTSUPP;
32100d60fd3SDavid Howells }
32200d60fd3SDavid Howells 
32300d60fd3SDavid Howells static inline long keyctl_pkey_e_d_s(int op,
32400d60fd3SDavid Howells 				     const struct keyctl_pkey_params __user *params,
32500d60fd3SDavid Howells 				     const char __user *_info,
32600d60fd3SDavid Howells 				     const void __user *_in,
32700d60fd3SDavid Howells 				     void __user *_out)
32800d60fd3SDavid Howells {
32900d60fd3SDavid Howells 	return -EOPNOTSUPP;
33000d60fd3SDavid Howells }
33100d60fd3SDavid Howells #endif
33200d60fd3SDavid Howells 
33345e0f30cSDavid Howells extern long keyctl_capabilities(unsigned char __user *_buffer, size_t buflen);
33445e0f30cSDavid Howells 
3351da177e4SLinus Torvalds /*
336973c9f4fSDavid Howells  * Debugging key validation
3371da177e4SLinus Torvalds  */
3381da177e4SLinus Torvalds #ifdef KEY_DEBUGGING
3391da177e4SLinus Torvalds extern void __key_check(const struct key *);
3401da177e4SLinus Torvalds 
3411da177e4SLinus Torvalds static inline void key_check(const struct key *key)
3421da177e4SLinus Torvalds {
3431da177e4SLinus Torvalds 	if (key && (IS_ERR(key) || key->magic != KEY_DEBUG_MAGIC))
3441da177e4SLinus Torvalds 		__key_check(key);
3451da177e4SLinus Torvalds }
3461da177e4SLinus Torvalds 
3471da177e4SLinus Torvalds #else
3481da177e4SLinus Torvalds 
3491da177e4SLinus Torvalds #define key_check(key) do {} while(0)
3501da177e4SLinus Torvalds 
3511da177e4SLinus Torvalds #endif
3521da177e4SLinus Torvalds 
3531da177e4SLinus Torvalds #endif /* _INTERNAL_H */
354