blob: 386c3143278995745cc7dc6e6df4607187eac276 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
David Howells2aa349f62005-10-30 15:02:42 -08002/* user-type.h: User-defined key type
3 *
4 * Copyright (C) 2005 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
David Howells2aa349f62005-10-30 15:02:42 -08006 */
7
8#ifndef _KEYS_USER_TYPE_H
9#define _KEYS_USER_TYPE_H
10
11#include <linux/key.h>
12#include <linux/rcupdate.h>
13
David Howells146aa8b2015-10-21 14:04:48 +010014#ifdef CONFIG_KEYS
15
David Howells2aa349f62005-10-30 15:02:42 -080016/*****************************************************************************/
17/*
Jeff Layton9f6ed2c2012-01-17 16:09:11 -050018 * the payload for a key of type "user" or "logon"
David Howells2aa349f62005-10-30 15:02:42 -080019 * - once filled in and attached to a key:
20 * - the payload struct is invariant may not be changed, only replaced
21 * - the payload must be read with RCU procedures or with the key semaphore
22 * held
23 * - the payload may only be replaced with the key semaphore write-locked
24 * - the key's data length is the size of the actual data, not including the
25 * payload wrapper
26 */
27struct user_key_payload {
28 struct rcu_head rcu; /* RCU destructor */
29 unsigned short datalen; /* length of this data */
Gustavo A. R. Silva2ce113f2020-05-07 13:57:10 -050030 char data[] __aligned(__alignof__(u64)); /* actual data */
David Howells2aa349f62005-10-30 15:02:42 -080031};
32
33extern struct key_type key_type_user;
Jeff Layton9f6ed2c2012-01-17 16:09:11 -050034extern struct key_type key_type_logon;
David Howells2aa349f62005-10-30 15:02:42 -080035
David Howellscf7f6012012-09-13 13:06:29 +010036struct key_preparsed_payload;
37
David Howellsf9167782014-07-18 18:56:35 +010038extern int user_preparse(struct key_preparsed_payload *prep);
39extern void user_free_preparse(struct key_preparsed_payload *prep);
David Howellscf7f6012012-09-13 13:06:29 +010040extern int user_update(struct key *key, struct key_preparsed_payload *prep);
David Howells31204ed2006-06-26 00:24:51 -070041extern void user_revoke(struct key *key);
David Howells2aa349f62005-10-30 15:02:42 -080042extern void user_destroy(struct key *key);
43extern void user_describe(const struct key *user, struct seq_file *m);
Waiman Longd3ec10a2020-03-21 21:11:24 -040044extern long user_read(const struct key *key, char *buffer, size_t buflen);
David Howells2aa349f62005-10-30 15:02:42 -080045
David Howells0837e492017-03-01 15:11:23 +000046static inline const struct user_key_payload *user_key_payload_rcu(const struct key *key)
David Howells146aa8b2015-10-21 14:04:48 +010047{
David Howells0837e492017-03-01 15:11:23 +000048 return (struct user_key_payload *)dereference_key_rcu(key);
49}
50
51static inline struct user_key_payload *user_key_payload_locked(const struct key *key)
52{
53 return (struct user_key_payload *)dereference_key_locked((struct key *)key);
David Howells146aa8b2015-10-21 14:04:48 +010054}
55
56#endif /* CONFIG_KEYS */
David Howells2aa349f62005-10-30 15:02:42 -080057
58#endif /* _KEYS_USER_TYPE_H */