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)  * SafeSetID Linux Security Module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Author: Micah Morton <mortonm@chromium.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  * Copyright (C) 2018 The Chromium OS Authors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9)  * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)  * it under the terms of the GNU General Public License version 2, as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)  * published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #ifndef _SAFESETID_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define _SAFESETID_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/uidgid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/hashtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /* Flag indicating whether initialization completed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) extern int safesetid_initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) enum sid_policy_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	SIDPOL_DEFAULT, /* source ID is unaffected by policy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	SIDPOL_CONSTRAINED, /* source ID is affected by policy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 	SIDPOL_ALLOWED /* target ID explicitly allowed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) typedef union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	kuid_t uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	kgid_t gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) } kid_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) enum setid_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	UID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	GID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)  * Hash table entry to store safesetid policy signifying that 'src_id'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)  * can set*id to 'dst_id'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct setid_rule {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	struct hlist_node next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	kid_t src_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	kid_t dst_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	/* Flag to signal if rule is for UID's or GID's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	enum setid_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define SETID_HASH_BITS 8 /* 256 buckets in hash table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* Extension of INVALID_UID/INVALID_GID for kid_t type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define INVALID_ID (kid_t){.uid = INVALID_UID}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct setid_ruleset {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	DECLARE_HASHTABLE(rules, SETID_HASH_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	char *policy_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	struct rcu_head rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	//Flag to signal if ruleset is for UID's or GID's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	enum setid_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) enum sid_policy_type _setid_policy_lookup(struct setid_ruleset *policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 		kid_t src, kid_t dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) extern struct setid_ruleset __rcu *safesetid_setuid_rules;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) extern struct setid_ruleset __rcu *safesetid_setgid_rules;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #endif /* _SAFESETID_H */