Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Implementations of the security context functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Author: Ondrej Mosnacek <omosnacek@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  * Copyright (C) 2020 Red Hat, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/jhash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "context.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "mls.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) u32 context_compute_hash(const struct context *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 	u32 hash = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	 * If a context is invalid, it will always be represented by a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 	 * context struct with only the len & str set (and vice versa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 	 * under a given policy. Since context structs from different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	 * policies should never meet, it is safe to hash valid and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	 * invalid contexts differently. The context_cmp() function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	 * already operates under the same assumption.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	if (c->len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 		return full_name_hash(NULL, c->str, c->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	hash = jhash_3words(c->user, c->role, c->type, hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	hash = mls_range_hash(&c->range, hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	return hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }