security/selinux/ss/avtab.h

Source file repositories/reference/linux-study-clean/security/selinux/ss/avtab.h

File Facts

System
Linux kernel
Corpus path
security/selinux/ss/avtab.h
Extension
.h
Size
4410 bytes
Lines
142
Domain
Core OS
Bucket
Security And Isolation
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct avtab_key {
	u16 source_type; /* source type */
	u16 target_type; /* target type */
	u16 target_class; /* target object class */
#define AVTAB_ALLOWED	 0x0001
#define AVTAB_AUDITALLOW 0x0002
#define AVTAB_AUDITDENY	 0x0004
#define AVTAB_AV	 (AVTAB_ALLOWED | AVTAB_AUDITALLOW | AVTAB_AUDITDENY)
#define AVTAB_TRANSITION 0x0010
#define AVTAB_MEMBER	 0x0020
#define AVTAB_CHANGE	 0x0040
#define AVTAB_TYPE	 (AVTAB_TRANSITION | AVTAB_MEMBER | AVTAB_CHANGE)
/* extended permissions */
#define AVTAB_XPERMS_ALLOWED	0x0100
#define AVTAB_XPERMS_AUDITALLOW 0x0200
#define AVTAB_XPERMS_DONTAUDIT	0x0400
#define AVTAB_XPERMS                                      \
	(AVTAB_XPERMS_ALLOWED | AVTAB_XPERMS_AUDITALLOW | \
	 AVTAB_XPERMS_DONTAUDIT)
#define AVTAB_ENABLED_OLD 0x80000000 /* reserved for used in cond_avtab */
#define AVTAB_ENABLED	  0x8000 /* reserved for used in cond_avtab */
#define AVTAB_SPECIFIER_MASK (AVTAB_AV | AVTAB_TYPE | AVTAB_XPERMS | AVTAB_ENABLED)
	u16 specified; /* what field is specified */
};

/*
 * For operations that require more than the 32 permissions provided by the avc
 * extended permissions may be used to provide 256 bits of permissions.
 */
struct avtab_extended_perms {
/* These are not flags. All 256 values may be used */
#define AVTAB_XPERMS_IOCTLFUNCTION	0x01
#define AVTAB_XPERMS_IOCTLDRIVER	0x02
#define AVTAB_XPERMS_NLMSG		0x03
	/* extension of the avtab_key specified */
	u8 specified; /* ioctl, netfilter, ... */
	/*
	 * if 256 bits is not adequate as is often the case with ioctls, then
	 * multiple extended perms may be used and the driver field
	 * specifies which permissions are included.
	 */
	u8 driver;
	/* 256 bits of permissions */
	struct extended_perms_data perms;
};

static inline bool avtab_is_valid_xperm_specified(u8 specified)
{
	switch (specified) {
	case AVTAB_XPERMS_IOCTLFUNCTION:
	case AVTAB_XPERMS_IOCTLDRIVER:
	case AVTAB_XPERMS_NLMSG:
		return true;
	default:
		return false;
	}
}

struct avtab_datum {
	union {
		u32 data; /* access vector or type value */
		struct avtab_extended_perms *xperms;
	} u;
};

struct avtab_node {
	struct avtab_key key;
	struct avtab_datum datum;
	struct avtab_node *next;
};

struct avtab {
	struct avtab_node **htable;
	u32 nel; /* number of elements */
	u32 nslot; /* number of hash slots */
	u32 mask; /* mask to compute hash func */
};

void avtab_init(struct avtab *h);
int avtab_alloc(struct avtab *h, u32 nrules);
int avtab_alloc_dup(struct avtab *new, const struct avtab *orig);
void avtab_destroy(struct avtab *h);

#define MAX_AVTAB_HASH_BITS    16
#define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS)

#ifdef CONFIG_SECURITY_SELINUX_DEBUG
void avtab_hash_eval(struct avtab *h, const char *tag);
#else
static inline void avtab_hash_eval(struct avtab *h, const char *tag)

Annotation

Implementation Notes