Thomas Gleixner | b886d83 | 2019-06-01 10:08:55 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
John Johansen | 736ec752 | 2010-07-29 14:48:02 -0700 | [diff] [blame] | 2 | /* |
| 3 | * AppArmor security module |
| 4 | * |
| 5 | * This file contains AppArmor policy loading interface function definitions. |
| 6 | * |
| 7 | * Copyright (C) 1998-2008 Novell/SUSE |
| 8 | * Copyright 2009-2010 Canonical Ltd. |
John Johansen | 736ec752 | 2010-07-29 14:48:02 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #ifndef __POLICY_INTERFACE_H |
| 12 | #define __POLICY_INTERFACE_H |
| 13 | |
John Johansen | dd51c848 | 2013-07-10 21:05:43 -0700 | [diff] [blame] | 14 | #include <linux/list.h> |
John Johansen | 5ac8c35 | 2017-01-16 00:42:55 -0800 | [diff] [blame] | 15 | #include <linux/kref.h> |
John Johansen | 5d5182ca | 2017-05-09 00:08:41 -0700 | [diff] [blame] | 16 | #include <linux/dcache.h> |
| 17 | #include <linux/workqueue.h> |
John Johansen | dd51c848 | 2013-07-10 21:05:43 -0700 | [diff] [blame] | 18 | |
| 19 | struct aa_load_ent { |
| 20 | struct list_head list; |
| 21 | struct aa_profile *new; |
| 22 | struct aa_profile *old; |
| 23 | struct aa_profile *rename; |
John Johansen | 04dc715 | 2017-01-16 00:42:56 -0800 | [diff] [blame] | 24 | const char *ns_name; |
John Johansen | dd51c848 | 2013-07-10 21:05:43 -0700 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | void aa_load_ent_free(struct aa_load_ent *ent); |
| 28 | struct aa_load_ent *aa_load_ent_alloc(void); |
| 29 | |
John Johansen | 0381650 | 2013-07-10 21:12:43 -0700 | [diff] [blame] | 30 | #define PACKED_FLAG_HAT 1 |
| 31 | |
| 32 | #define PACKED_MODE_ENFORCE 0 |
| 33 | #define PACKED_MODE_COMPLAIN 1 |
| 34 | #define PACKED_MODE_KILL 2 |
| 35 | #define PACKED_MODE_UNCONFINED 3 |
| 36 | |
John Johansen | 5d5182ca | 2017-05-09 00:08:41 -0700 | [diff] [blame] | 37 | struct aa_ns; |
| 38 | |
| 39 | enum { |
| 40 | AAFS_LOADDATA_ABI = 0, |
| 41 | AAFS_LOADDATA_REVISION, |
| 42 | AAFS_LOADDATA_HASH, |
| 43 | AAFS_LOADDATA_DATA, |
| 44 | AAFS_LOADDATA_DIR, /* must be last actual entry */ |
| 45 | AAFS_LOADDATA_NDENTS /* count of entries */ |
| 46 | }; |
| 47 | |
| 48 | /* |
| 49 | * struct aa_loaddata - buffer of policy raw_data set |
| 50 | * |
| 51 | * there is no loaddata ref for being on ns list, nor a ref from |
| 52 | * d_inode(@dentry) when grab a ref from these, @ns->lock must be held |
| 53 | * && __aa_get_loaddata() needs to be used, and the return value |
| 54 | * checked, if NULL the loaddata is already being reaped and should be |
| 55 | * considered dead. |
| 56 | */ |
John Johansen | 5ac8c35 | 2017-01-16 00:42:55 -0800 | [diff] [blame] | 57 | struct aa_loaddata { |
| 58 | struct kref count; |
John Johansen | 5d5182ca | 2017-05-09 00:08:41 -0700 | [diff] [blame] | 59 | struct list_head list; |
| 60 | struct work_struct work; |
| 61 | struct dentry *dents[AAFS_LOADDATA_NDENTS]; |
| 62 | struct aa_ns *ns; |
| 63 | char *name; |
John Johansen | 5ac8c35 | 2017-01-16 00:42:55 -0800 | [diff] [blame] | 64 | size_t size; |
John Johansen | 5d5182ca | 2017-05-09 00:08:41 -0700 | [diff] [blame] | 65 | long revision; /* the ns policy revision this caused */ |
John Johansen | 5ac8c35 | 2017-01-16 00:42:55 -0800 | [diff] [blame] | 66 | int abi; |
| 67 | unsigned char *hash; |
John Johansen | 5d5182ca | 2017-05-09 00:08:41 -0700 | [diff] [blame] | 68 | |
John Johansen | a6a5257 | 2018-02-03 20:08:28 +0100 | [diff] [blame] | 69 | char *data; |
John Johansen | 5ac8c35 | 2017-01-16 00:42:55 -0800 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | int aa_unpack(struct aa_loaddata *udata, struct list_head *lh, const char **ns); |
| 73 | |
John Johansen | 5d5182ca | 2017-05-09 00:08:41 -0700 | [diff] [blame] | 74 | /** |
| 75 | * __aa_get_loaddata - get a reference count to uncounted data reference |
| 76 | * @data: reference to get a count on |
| 77 | * |
| 78 | * Returns: pointer to reference OR NULL if race is lost and reference is |
| 79 | * being repeated. |
| 80 | * Requires: @data->ns->lock held, and the return code MUST be checked |
| 81 | * |
| 82 | * Use only from inode->i_private and @data->list found references |
| 83 | */ |
| 84 | static inline struct aa_loaddata * |
| 85 | __aa_get_loaddata(struct aa_loaddata *data) |
| 86 | { |
| 87 | if (data && kref_get_unless_zero(&(data->count))) |
| 88 | return data; |
| 89 | |
| 90 | return NULL; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * aa_get_loaddata - get a reference count from a counted data reference |
| 95 | * @data: reference to get a count on |
| 96 | * |
| 97 | * Returns: point to reference |
| 98 | * Requires: @data to have a valid reference count on it. It is a bug |
| 99 | * if the race to reap can be encountered when it is used. |
| 100 | */ |
John Johansen | 5ac8c35 | 2017-01-16 00:42:55 -0800 | [diff] [blame] | 101 | static inline struct aa_loaddata * |
| 102 | aa_get_loaddata(struct aa_loaddata *data) |
| 103 | { |
John Johansen | 5d5182ca | 2017-05-09 00:08:41 -0700 | [diff] [blame] | 104 | struct aa_loaddata *tmp = __aa_get_loaddata(data); |
| 105 | |
| 106 | AA_BUG(data && !tmp); |
| 107 | |
| 108 | return tmp; |
John Johansen | 5ac8c35 | 2017-01-16 00:42:55 -0800 | [diff] [blame] | 109 | } |
| 110 | |
John Johansen | 5d5182ca | 2017-05-09 00:08:41 -0700 | [diff] [blame] | 111 | void __aa_loaddata_update(struct aa_loaddata *data, long revision); |
| 112 | bool aa_rawdata_eq(struct aa_loaddata *l, struct aa_loaddata *r); |
John Johansen | 5ac8c35 | 2017-01-16 00:42:55 -0800 | [diff] [blame] | 113 | void aa_loaddata_kref(struct kref *kref); |
John Johansen | 5d5182ca | 2017-05-09 00:08:41 -0700 | [diff] [blame] | 114 | struct aa_loaddata *aa_loaddata_alloc(size_t size); |
John Johansen | 5ac8c35 | 2017-01-16 00:42:55 -0800 | [diff] [blame] | 115 | static inline void aa_put_loaddata(struct aa_loaddata *data) |
| 116 | { |
| 117 | if (data) |
| 118 | kref_put(&data->count, aa_loaddata_kref); |
| 119 | } |
John Johansen | 736ec752 | 2010-07-29 14:48:02 -0700 | [diff] [blame] | 120 | |
| 121 | #endif /* __POLICY_INTERFACE_H */ |