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-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  NSA Security-Enhanced Linux (SELinux) security module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  This file contains the SELinux security data structures for kernel objects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Author(s):  Stephen Smalley, <sds@tycho.nsa.gov>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *		Chris Vance, <cvance@nai.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *		Wayne Salamon, <wsalamon@nai.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *		James Morris <jmorris@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *  Copyright (C) 2001,2002 Networks Associates Technology, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *  Copyright (C) 2003 Red Hat, Inc., James Morris <jmorris@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *  Copyright (C) 2016 Mellanox Technologies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #ifndef _SELINUX_OBJSEC_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define _SELINUX_OBJSEC_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/binfmts.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/lsm_hooks.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/msg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include "flask.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include "avc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) struct task_security_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	u32 osid;		/* SID prior to last execve */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	u32 sid;		/* current SID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	u32 exec_sid;		/* exec SID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	u32 create_sid;		/* fscreate SID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	u32 keycreate_sid;	/* keycreate SID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	u32 sockcreate_sid;	/* fscreate SID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) } __randomize_layout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) enum label_initialized {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	LABEL_INVALID,		/* invalid or not initialized */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	LABEL_INITIALIZED,	/* initialized */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	LABEL_PENDING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) struct inode_security_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct inode *inode;	/* back pointer to inode object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct list_head list;	/* list of inode_security_struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	u32 task_sid;		/* SID of creating task */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	u32 sid;		/* SID of this object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	u16 sclass;		/* security class of this object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	unsigned char initialized;	/* initialization flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) struct file_security_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	u32 sid;		/* SID of open file description */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	u32 fown_sid;		/* SID of file owner (for SIGIO) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	u32 isid;		/* SID of inode at the time of file open */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	u32 pseqno;		/* Policy seqno at the time of file open */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) struct superblock_security_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct super_block *sb;		/* back pointer to sb object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	u32 sid;			/* SID of file system superblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	u32 def_sid;			/* default SID for labeling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	u32 mntpoint_sid;		/* SECURITY_FS_USE_MNTPOINT context for files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	unsigned short behavior;	/* labeling behavior */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	unsigned short flags;		/* which mount options were specified */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct mutex lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	struct list_head isec_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	spinlock_t isec_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) struct msg_security_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	u32 sid;	/* SID of message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) struct ipc_security_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	u16 sclass;	/* security class of this object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	u32 sid;	/* SID of IPC resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) struct netif_security_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct net *ns;			/* network namespace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	int ifindex;			/* device index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	u32 sid;			/* SID for this interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) struct netnode_security_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		__be32 ipv4;		/* IPv4 node address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		struct in6_addr ipv6;	/* IPv6 node address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	} addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	u32 sid;			/* SID for this node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	u16 family;			/* address family */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) struct netport_security_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	u32 sid;			/* SID for this node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	u16 port;			/* port number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	u8 protocol;			/* transport protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct sk_security_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #ifdef CONFIG_NETLABEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	enum {				/* NetLabel state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		NLBL_UNSET = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		NLBL_REQUIRE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		NLBL_LABELED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		NLBL_REQSKB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		NLBL_CONNLABELED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	} nlbl_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct netlbl_lsm_secattr *nlbl_secattr; /* NetLabel sec attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	u32 sid;			/* SID of this object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	u32 peer_sid;			/* SID of peer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	u16 sclass;			/* sock security class */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	enum {				/* SCTP association state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		SCTP_ASSOC_UNSET = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		SCTP_ASSOC_SET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	} sctp_assoc_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct tun_security_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	u32 sid;			/* SID for the tun device sockets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct key_security_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	u32 sid;	/* SID of key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct ib_security_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	u32 sid;        /* SID of the queue pair or MAD agent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct pkey_security_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	u64	subnet_prefix; /* Port subnet prefix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	u16	pkey;	/* PKey number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	u32	sid;	/* SID of pkey */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct bpf_security_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	u32 sid;  /* SID of bpf obj creator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct perf_event_security_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	u32 sid;  /* SID of perf_event obj creator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) extern struct lsm_blob_sizes selinux_blob_sizes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static inline struct task_security_struct *selinux_cred(const struct cred *cred)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	return cred->security + selinux_blob_sizes.lbs_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static inline struct file_security_struct *selinux_file(const struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	return file->f_security + selinux_blob_sizes.lbs_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static inline struct inode_security_struct *selinux_inode(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 						const struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	if (unlikely(!inode->i_security))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	return inode->i_security + selinux_blob_sizes.lbs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static inline struct msg_security_struct *selinux_msg_msg(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 						const struct msg_msg *msg_msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	return msg_msg->security + selinux_blob_sizes.lbs_msg_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static inline struct ipc_security_struct *selinux_ipc(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 						const struct kern_ipc_perm *ipc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	return ipc->security + selinux_blob_sizes.lbs_ipc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * get the subjective security ID of the current task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static inline u32 current_sid(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	const struct task_security_struct *tsec = selinux_cred(current_cred());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	return tsec->sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #endif /* _SELINUX_OBJSEC_H_ */