blob: e0e1ca7ebc380f1e9ddfc342cbc4d772f284f627 [file] [log] [blame]
Thomas Gleixnerb886d83c2019-06-01 10:08:55 +02001/* SPDX-License-Identifier: GPL-2.0-only */
John Johansen736ec7522010-07-29 14:48:02 -07002/*
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 Johansen736ec7522010-07-29 14:48:02 -07009 */
10
11#ifndef __POLICY_INTERFACE_H
12#define __POLICY_INTERFACE_H
13
John Johansendd51c8482013-07-10 21:05:43 -070014#include <linux/list.h>
John Johansen5ac8c352017-01-16 00:42:55 -080015#include <linux/kref.h>
John Johansen5d5182ca2017-05-09 00:08:41 -070016#include <linux/dcache.h>
17#include <linux/workqueue.h>
John Johansendd51c8482013-07-10 21:05:43 -070018
19struct aa_load_ent {
20 struct list_head list;
21 struct aa_profile *new;
22 struct aa_profile *old;
23 struct aa_profile *rename;
John Johansen04dc7152017-01-16 00:42:56 -080024 const char *ns_name;
John Johansendd51c8482013-07-10 21:05:43 -070025};
26
27void aa_load_ent_free(struct aa_load_ent *ent);
28struct aa_load_ent *aa_load_ent_alloc(void);
29
John Johansen03816502013-07-10 21:12:43 -070030#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 Johansen5d5182ca2017-05-09 00:08:41 -070037struct aa_ns;
38
39enum {
40 AAFS_LOADDATA_ABI = 0,
41 AAFS_LOADDATA_REVISION,
42 AAFS_LOADDATA_HASH,
43 AAFS_LOADDATA_DATA,
Chris Coulson63c16c32019-01-23 19:17:09 +000044 AAFS_LOADDATA_COMPRESSED_SIZE,
John Johansen5d5182ca2017-05-09 00:08:41 -070045 AAFS_LOADDATA_DIR, /* must be last actual entry */
46 AAFS_LOADDATA_NDENTS /* count of entries */
47};
48
49/*
50 * struct aa_loaddata - buffer of policy raw_data set
51 *
52 * there is no loaddata ref for being on ns list, nor a ref from
53 * d_inode(@dentry) when grab a ref from these, @ns->lock must be held
54 * && __aa_get_loaddata() needs to be used, and the return value
55 * checked, if NULL the loaddata is already being reaped and should be
56 * considered dead.
57 */
John Johansen5ac8c352017-01-16 00:42:55 -080058struct aa_loaddata {
59 struct kref count;
John Johansen5d5182ca2017-05-09 00:08:41 -070060 struct list_head list;
61 struct work_struct work;
62 struct dentry *dents[AAFS_LOADDATA_NDENTS];
63 struct aa_ns *ns;
64 char *name;
Chris Coulson63c16c32019-01-23 19:17:09 +000065 size_t size; /* the original size of the payload */
66 size_t compressed_size; /* the compressed size of the payload */
John Johansen5d5182ca2017-05-09 00:08:41 -070067 long revision; /* the ns policy revision this caused */
John Johansen5ac8c352017-01-16 00:42:55 -080068 int abi;
69 unsigned char *hash;
John Johansen5d5182ca2017-05-09 00:08:41 -070070
Chris Coulson63c16c32019-01-23 19:17:09 +000071 /* Pointer to payload. If @compressed_size > 0, then this is the
72 * compressed version of the payload, else it is the uncompressed
73 * version (with the size indicated by @size).
74 */
John Johansena6a52572018-02-03 20:08:28 +010075 char *data;
John Johansen5ac8c352017-01-16 00:42:55 -080076};
77
78int aa_unpack(struct aa_loaddata *udata, struct list_head *lh, const char **ns);
79
John Johansen5d5182ca2017-05-09 00:08:41 -070080/**
81 * __aa_get_loaddata - get a reference count to uncounted data reference
82 * @data: reference to get a count on
83 *
84 * Returns: pointer to reference OR NULL if race is lost and reference is
85 * being repeated.
86 * Requires: @data->ns->lock held, and the return code MUST be checked
87 *
88 * Use only from inode->i_private and @data->list found references
89 */
90static inline struct aa_loaddata *
91__aa_get_loaddata(struct aa_loaddata *data)
92{
93 if (data && kref_get_unless_zero(&(data->count)))
94 return data;
95
96 return NULL;
97}
98
99/**
100 * aa_get_loaddata - get a reference count from a counted data reference
101 * @data: reference to get a count on
102 *
103 * Returns: point to reference
104 * Requires: @data to have a valid reference count on it. It is a bug
105 * if the race to reap can be encountered when it is used.
106 */
John Johansen5ac8c352017-01-16 00:42:55 -0800107static inline struct aa_loaddata *
108aa_get_loaddata(struct aa_loaddata *data)
109{
John Johansen5d5182ca2017-05-09 00:08:41 -0700110 struct aa_loaddata *tmp = __aa_get_loaddata(data);
111
112 AA_BUG(data && !tmp);
113
114 return tmp;
John Johansen5ac8c352017-01-16 00:42:55 -0800115}
116
John Johansen5d5182ca2017-05-09 00:08:41 -0700117void __aa_loaddata_update(struct aa_loaddata *data, long revision);
118bool aa_rawdata_eq(struct aa_loaddata *l, struct aa_loaddata *r);
John Johansen5ac8c352017-01-16 00:42:55 -0800119void aa_loaddata_kref(struct kref *kref);
John Johansen5d5182ca2017-05-09 00:08:41 -0700120struct aa_loaddata *aa_loaddata_alloc(size_t size);
John Johansen5ac8c352017-01-16 00:42:55 -0800121static inline void aa_put_loaddata(struct aa_loaddata *data)
122{
123 if (data)
124 kref_put(&data->count, aa_loaddata_kref);
125}
John Johansen736ec7522010-07-29 14:48:02 -0700126
127#endif /* __POLICY_INTERFACE_H */