blob: d946c9dc3c9ca6b2569ecd7624c3bd12f7789c77 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * An access vector table (avtab) is a hash table
3 * of access vectors and transition types indexed
4 * by a type pair and a class. An access vector
5 * table is used to represent the type enforcement
6 * tables.
7 *
8 * Author : Stephen Smalley, <sds@epoch.ncsc.mil>
9 */
10
11/* Updated: Frank Mayer <mayerf@tresys.com> and Karl MacMillan <kmacmillan@tresys.com>
12 *
13 * Added conditional policy language extensions
14 *
15 * Copyright (C) 2003 Tresys Technology, LLC
16 * This program is free software; you can redistribute it and/or modify
Eric Paris652bb9b2011-02-01 11:05:40 -050017 * it under the terms of the GNU General Public License as published by
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * the Free Software Foundation, version 2.
Yuichi Nakamura3232c112007-08-24 11:55:11 +090019 *
20 * Updated: Yuichi Nakamura <ynakam@hitachisoft.jp>
21 * Tuned number of hash slots for avtab to reduce memory usage
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 */
23#ifndef _SS_AVTAB_H_
24#define _SS_AVTAB_H_
25
Jeff Vander Stoepfa1aa142015-07-10 17:19:56 -040026#include "security.h"
Stephen Smalleyba39db62015-03-24 16:54:16 -040027#include <linux/flex_array.h>
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029struct avtab_key {
Stephen Smalley782ebb92005-09-03 15:55:16 -070030 u16 source_type; /* source type */
31 u16 target_type; /* target type */
32 u16 target_class; /* target object class */
Eric Paris652bb9b2011-02-01 11:05:40 -050033#define AVTAB_ALLOWED 0x0001
34#define AVTAB_AUDITALLOW 0x0002
35#define AVTAB_AUDITDENY 0x0004
36#define AVTAB_AV (AVTAB_ALLOWED | AVTAB_AUDITALLOW | AVTAB_AUDITDENY)
37#define AVTAB_TRANSITION 0x0010
38#define AVTAB_MEMBER 0x0020
39#define AVTAB_CHANGE 0x0040
40#define AVTAB_TYPE (AVTAB_TRANSITION | AVTAB_MEMBER | AVTAB_CHANGE)
Jeff Vander Stoepfa1aa142015-07-10 17:19:56 -040041/* extended permissions */
42#define AVTAB_XPERMS_ALLOWED 0x0100
43#define AVTAB_XPERMS_AUDITALLOW 0x0200
44#define AVTAB_XPERMS_DONTAUDIT 0x0400
45#define AVTAB_XPERMS (AVTAB_XPERMS_ALLOWED | \
46 AVTAB_XPERMS_AUDITALLOW | \
47 AVTAB_XPERMS_DONTAUDIT)
Eric Paris652bb9b2011-02-01 11:05:40 -050048#define AVTAB_ENABLED_OLD 0x80000000 /* reserved for used in cond_avtab */
49#define AVTAB_ENABLED 0x8000 /* reserved for used in cond_avtab */
Stephen Smalley782ebb92005-09-03 15:55:16 -070050 u16 specified; /* what field is specified */
51};
52
Jeff Vander Stoepfa1aa142015-07-10 17:19:56 -040053/*
54 * For operations that require more than the 32 permissions provided by the avc
55 * extended permissions may be used to provide 256 bits of permissions.
56 */
57struct avtab_extended_perms {
58/* These are not flags. All 256 values may be used */
59#define AVTAB_XPERMS_IOCTLFUNCTION 0x01
60#define AVTAB_XPERMS_IOCTLDRIVER 0x02
61 /* extension of the avtab_key specified */
62 u8 specified; /* ioctl, netfilter, ... */
63 /*
64 * if 256 bits is not adequate as is often the case with ioctls, then
65 * multiple extended perms may be used and the driver field
66 * specifies which permissions are included.
67 */
68 u8 driver;
69 /* 256 bits of permissions */
70 struct extended_perms_data perms;
71};
72
Stephen Smalley782ebb92005-09-03 15:55:16 -070073struct avtab_datum {
Jeff Vander Stoepfa1aa142015-07-10 17:19:56 -040074 union {
75 u32 data; /* access vector or type value */
76 struct avtab_extended_perms *xperms;
77 } u;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078};
79
80struct avtab_node {
81 struct avtab_key key;
82 struct avtab_datum datum;
83 struct avtab_node *next;
84};
85
86struct avtab {
Stephen Smalleyba39db62015-03-24 16:54:16 -040087 struct flex_array *htable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 u32 nel; /* number of elements */
Yuichi Nakamura3232c112007-08-24 11:55:11 +090089 u32 nslot; /* number of hash slots */
John Brooks33ebc1932015-03-24 16:54:17 -040090 u32 mask; /* mask to compute hash func */
Yuichi Nakamura3232c112007-08-24 11:55:11 +090091
Linus Torvalds1da177e2005-04-16 15:20:36 -070092};
93
94int avtab_init(struct avtab *);
Yuichi Nakamura3232c112007-08-24 11:55:11 +090095int avtab_alloc(struct avtab *, u32);
Stephen Smalley782ebb92005-09-03 15:55:16 -070096struct avtab_datum *avtab_search(struct avtab *h, struct avtab_key *k);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097void avtab_destroy(struct avtab *h);
98void avtab_hash_eval(struct avtab *h, char *tag);
99
Stephen Smalley45e54212007-11-07 10:08:00 -0500100struct policydb;
101int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
Stephen Smalley782ebb92005-09-03 15:55:16 -0700102 int (*insert)(struct avtab *a, struct avtab_key *k,
103 struct avtab_datum *d, void *p),
104 void *p);
105
Stephen Smalley45e54212007-11-07 10:08:00 -0500106int avtab_read(struct avtab *a, void *fp, struct policydb *pol);
Eric Pariscee74f42010-10-13 17:50:25 -0400107int avtab_write_item(struct policydb *p, struct avtab_node *cur, void *fp);
108int avtab_write(struct policydb *p, struct avtab *a, void *fp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110struct avtab_node *avtab_insert_nonunique(struct avtab *h, struct avtab_key *key,
111 struct avtab_datum *datum);
112
Stephen Smalley782ebb92005-09-03 15:55:16 -0700113struct avtab_node *avtab_search_node(struct avtab *h, struct avtab_key *key);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115struct avtab_node *avtab_search_node_next(struct avtab_node *node, int specified);
116
117void avtab_cache_init(void);
118void avtab_cache_destroy(void);
119
Stephen Smalleycf7b6c02015-03-24 16:54:18 -0400120#define MAX_AVTAB_HASH_BITS 16
Yuichi Nakamura3232c112007-08-24 11:55:11 +0900121#define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123#endif /* _SS_AVTAB_H_ */
124