| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * NSA Security-Enhanced Linux (SELinux) security module |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 11 | 12 | * Copyright (C) 2001,2002 Networks Associates Technology, Inc. |
|---|
| 12 | 13 | * Copyright (C) 2003 Red Hat, Inc., James Morris <jmorris@redhat.com> |
|---|
| 13 | 14 | * Copyright (C) 2016 Mellanox Technologies |
|---|
| 14 | | - * |
|---|
| 15 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 16 | | - * it under the terms of the GNU General Public License version 2, |
|---|
| 17 | | - * as published by the Free Software Foundation. |
|---|
| 18 | 15 | */ |
|---|
| 19 | 16 | #ifndef _SELINUX_OBJSEC_H_ |
|---|
| 20 | 17 | #define _SELINUX_OBJSEC_H_ |
|---|
| .. | .. |
|---|
| 25 | 22 | #include <linux/binfmts.h> |
|---|
| 26 | 23 | #include <linux/in.h> |
|---|
| 27 | 24 | #include <linux/spinlock.h> |
|---|
| 25 | +#include <linux/lsm_hooks.h> |
|---|
| 26 | +#include <linux/msg.h> |
|---|
| 28 | 27 | #include <net/net_namespace.h> |
|---|
| 29 | 28 | #include "flask.h" |
|---|
| 30 | 29 | #include "avc.h" |
|---|
| .. | .. |
|---|
| 36 | 35 | u32 create_sid; /* fscreate SID */ |
|---|
| 37 | 36 | u32 keycreate_sid; /* keycreate SID */ |
|---|
| 38 | 37 | u32 sockcreate_sid; /* fscreate SID */ |
|---|
| 39 | | -}; |
|---|
| 40 | | - |
|---|
| 41 | | -/* |
|---|
| 42 | | - * get the subjective security ID of the current task |
|---|
| 43 | | - */ |
|---|
| 44 | | -static inline u32 current_sid(void) |
|---|
| 45 | | -{ |
|---|
| 46 | | - const struct task_security_struct *tsec = current_security(); |
|---|
| 47 | | - |
|---|
| 48 | | - return tsec->sid; |
|---|
| 49 | | -} |
|---|
| 38 | +} __randomize_layout; |
|---|
| 50 | 39 | |
|---|
| 51 | 40 | enum label_initialized { |
|---|
| 52 | 41 | LABEL_INVALID, /* invalid or not initialized */ |
|---|
| .. | .. |
|---|
| 56 | 45 | |
|---|
| 57 | 46 | struct inode_security_struct { |
|---|
| 58 | 47 | struct inode *inode; /* back pointer to inode object */ |
|---|
| 59 | | - union { |
|---|
| 60 | | - struct list_head list; /* list of inode_security_struct */ |
|---|
| 61 | | - struct rcu_head rcu; /* for freeing the inode_security_struct */ |
|---|
| 62 | | - }; |
|---|
| 48 | + struct list_head list; /* list of inode_security_struct */ |
|---|
| 63 | 49 | u32 task_sid; /* SID of creating task */ |
|---|
| 64 | 50 | u32 sid; /* SID of this object */ |
|---|
| 65 | 51 | u16 sclass; /* security class of this object */ |
|---|
| .. | .. |
|---|
| 162 | 148 | u32 sid; /* SID of perf_event obj creator */ |
|---|
| 163 | 149 | }; |
|---|
| 164 | 150 | |
|---|
| 151 | +extern struct lsm_blob_sizes selinux_blob_sizes; |
|---|
| 152 | +static inline struct task_security_struct *selinux_cred(const struct cred *cred) |
|---|
| 153 | +{ |
|---|
| 154 | + return cred->security + selinux_blob_sizes.lbs_cred; |
|---|
| 155 | +} |
|---|
| 156 | + |
|---|
| 157 | +static inline struct file_security_struct *selinux_file(const struct file *file) |
|---|
| 158 | +{ |
|---|
| 159 | + return file->f_security + selinux_blob_sizes.lbs_file; |
|---|
| 160 | +} |
|---|
| 161 | + |
|---|
| 162 | +static inline struct inode_security_struct *selinux_inode( |
|---|
| 163 | + const struct inode *inode) |
|---|
| 164 | +{ |
|---|
| 165 | + if (unlikely(!inode->i_security)) |
|---|
| 166 | + return NULL; |
|---|
| 167 | + return inode->i_security + selinux_blob_sizes.lbs_inode; |
|---|
| 168 | +} |
|---|
| 169 | + |
|---|
| 170 | +static inline struct msg_security_struct *selinux_msg_msg( |
|---|
| 171 | + const struct msg_msg *msg_msg) |
|---|
| 172 | +{ |
|---|
| 173 | + return msg_msg->security + selinux_blob_sizes.lbs_msg_msg; |
|---|
| 174 | +} |
|---|
| 175 | + |
|---|
| 176 | +static inline struct ipc_security_struct *selinux_ipc( |
|---|
| 177 | + const struct kern_ipc_perm *ipc) |
|---|
| 178 | +{ |
|---|
| 179 | + return ipc->security + selinux_blob_sizes.lbs_ipc; |
|---|
| 180 | +} |
|---|
| 181 | + |
|---|
| 182 | +/* |
|---|
| 183 | + * get the subjective security ID of the current task |
|---|
| 184 | + */ |
|---|
| 185 | +static inline u32 current_sid(void) |
|---|
| 186 | +{ |
|---|
| 187 | + const struct task_security_struct *tsec = selinux_cred(current_cred()); |
|---|
| 188 | + |
|---|
| 189 | + return tsec->sid; |
|---|
| 190 | +} |
|---|
| 191 | + |
|---|
| 165 | 192 | #endif /* _SELINUX_OBJSEC_H_ */ |
|---|