security/tomoyo/common.c

Source file repositories/reference/linux-study-clean/security/tomoyo/common.c

File Facts

System
Linux kernel
Corpus path
security/tomoyo/common.c
Extension
.c
Size
82079 bytes
Lines
3026
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 tomoyo_query {
	struct list_head list;
	struct tomoyo_domain_info *domain;
	char *query;
	size_t query_len;
	unsigned int serial;
	u8 timer;
	u8 answer;
	u8 retry;
};

/* The list for "struct tomoyo_query". */
static LIST_HEAD(tomoyo_query_list);

/* Lock for manipulating tomoyo_query_list. */
static DEFINE_SPINLOCK(tomoyo_query_list_lock);

/*
 * Number of "struct file" referring /sys/kernel/security/tomoyo/query
 * interface.
 */
static atomic_t tomoyo_query_observers = ATOMIC_INIT(0);

/**
 * tomoyo_truncate - Truncate a line.
 *
 * @str: String to truncate.
 *
 * Returns length of truncated @str.
 */
static int tomoyo_truncate(char *str)
{
	char *start = str;

	while (*(unsigned char *) str > (unsigned char) ' ')
		str++;
	*str = '\0';
	return strlen(start) + 1;
}

/**
 * tomoyo_numscan - sscanf() which stores the length of a decimal integer value.
 *
 * @str:   String to scan.
 * @head:  Leading string that must start with.
 * @width: Pointer to "int" for storing length of a decimal integer value after @head.
 * @tail:  Optional character that must match after a decimal integer value.
 *
 * Returns whether @str starts with @head and a decimal value follows @head.
 */
static bool tomoyo_numscan(const char *str, const char *head, int *width, const char tail)
{
	const char *cp;
	const int n = strlen(head);

	if (!strncmp(str, head, n)) {
		cp = str + n;
		while (*cp && *cp >= '0' && *cp <= '9')
			cp++;
		if (*cp == tail || !tail) {
			*width = cp - (str + n);
			return *width != 0;
		}
	}
	*width = 0;
	return 0;
}

/**
 * tomoyo_patternize_path - Make patterns for file path. Used by learning mode.
 *
 * @buffer: Destination buffer.
 * @len:    Size of @buffer.
 * @entry:  Original line.
 *
 * Returns nothing.
 */
static void tomoyo_patternize_path(char *buffer, const int len, char *entry)
{
	int width;
	char *cp = entry;

	/* Nothing to do if this line is not for "file" related entry. */
	if (strncmp(entry, "file ", 5))
		goto flush;
	/*
	 * Nothing to do if there is no colon in this line, for this rewriting
	 * applies to only filesystems where numeric values in the path are volatile.
	 */
	cp = strchr(entry + 5, ':');

Annotation

Implementation Notes