2010-07-30 04:48:02 +07:00
|
|
|
/*
|
|
|
|
* AppArmor security module
|
|
|
|
*
|
|
|
|
* This file contains AppArmor policy loading interface function definitions.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998-2008 Novell/SUSE
|
|
|
|
* Copyright 2009-2010 Canonical Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation, version 2 of the
|
|
|
|
* License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __POLICY_INTERFACE_H
|
|
|
|
#define __POLICY_INTERFACE_H
|
|
|
|
|
2013-07-11 11:05:43 +07:00
|
|
|
#include <linux/list.h>
|
2017-01-16 15:42:55 +07:00
|
|
|
#include <linux/kref.h>
|
2017-05-09 14:08:41 +07:00
|
|
|
#include <linux/dcache.h>
|
|
|
|
#include <linux/workqueue.h>
|
2013-07-11 11:05:43 +07:00
|
|
|
|
|
|
|
struct aa_load_ent {
|
|
|
|
struct list_head list;
|
|
|
|
struct aa_profile *new;
|
|
|
|
struct aa_profile *old;
|
|
|
|
struct aa_profile *rename;
|
2017-01-16 15:42:56 +07:00
|
|
|
const char *ns_name;
|
2013-07-11 11:05:43 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
void aa_load_ent_free(struct aa_load_ent *ent);
|
|
|
|
struct aa_load_ent *aa_load_ent_alloc(void);
|
|
|
|
|
2013-07-11 11:12:43 +07:00
|
|
|
#define PACKED_FLAG_HAT 1
|
|
|
|
|
|
|
|
#define PACKED_MODE_ENFORCE 0
|
|
|
|
#define PACKED_MODE_COMPLAIN 1
|
|
|
|
#define PACKED_MODE_KILL 2
|
|
|
|
#define PACKED_MODE_UNCONFINED 3
|
|
|
|
|
2017-05-09 14:08:41 +07:00
|
|
|
struct aa_ns;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
AAFS_LOADDATA_ABI = 0,
|
|
|
|
AAFS_LOADDATA_REVISION,
|
|
|
|
AAFS_LOADDATA_HASH,
|
|
|
|
AAFS_LOADDATA_DATA,
|
|
|
|
AAFS_LOADDATA_DIR, /* must be last actual entry */
|
|
|
|
AAFS_LOADDATA_NDENTS /* count of entries */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* struct aa_loaddata - buffer of policy raw_data set
|
|
|
|
*
|
|
|
|
* there is no loaddata ref for being on ns list, nor a ref from
|
|
|
|
* d_inode(@dentry) when grab a ref from these, @ns->lock must be held
|
|
|
|
* && __aa_get_loaddata() needs to be used, and the return value
|
|
|
|
* checked, if NULL the loaddata is already being reaped and should be
|
|
|
|
* considered dead.
|
|
|
|
*/
|
2017-01-16 15:42:55 +07:00
|
|
|
struct aa_loaddata {
|
|
|
|
struct kref count;
|
2017-05-09 14:08:41 +07:00
|
|
|
struct list_head list;
|
|
|
|
struct work_struct work;
|
|
|
|
struct dentry *dents[AAFS_LOADDATA_NDENTS];
|
|
|
|
struct aa_ns *ns;
|
|
|
|
char *name;
|
2017-01-16 15:42:55 +07:00
|
|
|
size_t size;
|
2017-05-09 14:08:41 +07:00
|
|
|
long revision; /* the ns policy revision this caused */
|
2017-01-16 15:42:55 +07:00
|
|
|
int abi;
|
|
|
|
unsigned char *hash;
|
2017-05-09 14:08:41 +07:00
|
|
|
|
2018-02-04 02:08:28 +07:00
|
|
|
char *data;
|
2017-01-16 15:42:55 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
int aa_unpack(struct aa_loaddata *udata, struct list_head *lh, const char **ns);
|
|
|
|
|
2017-05-09 14:08:41 +07:00
|
|
|
/**
|
|
|
|
* __aa_get_loaddata - get a reference count to uncounted data reference
|
|
|
|
* @data: reference to get a count on
|
|
|
|
*
|
|
|
|
* Returns: pointer to reference OR NULL if race is lost and reference is
|
|
|
|
* being repeated.
|
|
|
|
* Requires: @data->ns->lock held, and the return code MUST be checked
|
|
|
|
*
|
|
|
|
* Use only from inode->i_private and @data->list found references
|
|
|
|
*/
|
|
|
|
static inline struct aa_loaddata *
|
|
|
|
__aa_get_loaddata(struct aa_loaddata *data)
|
|
|
|
{
|
|
|
|
if (data && kref_get_unless_zero(&(data->count)))
|
|
|
|
return data;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* aa_get_loaddata - get a reference count from a counted data reference
|
|
|
|
* @data: reference to get a count on
|
|
|
|
*
|
|
|
|
* Returns: point to reference
|
|
|
|
* Requires: @data to have a valid reference count on it. It is a bug
|
|
|
|
* if the race to reap can be encountered when it is used.
|
|
|
|
*/
|
2017-01-16 15:42:55 +07:00
|
|
|
static inline struct aa_loaddata *
|
|
|
|
aa_get_loaddata(struct aa_loaddata *data)
|
|
|
|
{
|
2017-05-09 14:08:41 +07:00
|
|
|
struct aa_loaddata *tmp = __aa_get_loaddata(data);
|
|
|
|
|
|
|
|
AA_BUG(data && !tmp);
|
|
|
|
|
|
|
|
return tmp;
|
2017-01-16 15:42:55 +07:00
|
|
|
}
|
|
|
|
|
2017-05-09 14:08:41 +07:00
|
|
|
void __aa_loaddata_update(struct aa_loaddata *data, long revision);
|
|
|
|
bool aa_rawdata_eq(struct aa_loaddata *l, struct aa_loaddata *r);
|
2017-01-16 15:42:55 +07:00
|
|
|
void aa_loaddata_kref(struct kref *kref);
|
2017-05-09 14:08:41 +07:00
|
|
|
struct aa_loaddata *aa_loaddata_alloc(size_t size);
|
2017-01-16 15:42:55 +07:00
|
|
|
static inline void aa_put_loaddata(struct aa_loaddata *data)
|
|
|
|
{
|
|
|
|
if (data)
|
|
|
|
kref_put(&data->count, aa_loaddata_kref);
|
|
|
|
}
|
2010-07-30 04:48:02 +07:00
|
|
|
|
|
|
|
#endif /* __POLICY_INTERFACE_H */
|