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