4 * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
5 * Copyright (C) 2001 Greg Kroah-Hartman <greg@kroah.com>
6 * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
7 * Copyright (C) 2001 James Morris <jmorris@intercode.com.au>
8 * Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group)
9 * Copyright (C) 2016 Mellanox Techonologies
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * Due to this file being licensed under the GPL there is controversy over
17 * whether this permits you to write a module that #includes this file
18 * without placing your module under the GPL. Please consult a lawyer for
19 * advice before doing this.
23 #ifndef __LINUX_SECURITY_H
24 #define __LINUX_SECURITY_H
26 #include <linux/key.h>
27 #include <linux/capability.h>
29 #include <linux/slab.h>
30 #include <linux/err.h>
31 #include <linux/string.h>
52 struct file_operations;
60 /* If capable should audit the security request */
61 #define SECURITY_CAP_NOAUDIT 0
62 #define SECURITY_CAP_AUDIT 1
64 /* LSM Agnostic defines for sb_set_mnt_opts */
65 #define SECURITY_LSM_NATIVE_LABELS 1
69 struct user_namespace;
76 /* These functions are in security/commoncap.c */
77 extern int cap_capable(const struct cred *cred, struct user_namespace *ns,
79 extern int cap_settime(const struct timespec64 *ts, const struct timezone *tz);
80 extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode);
81 extern int cap_ptrace_traceme(struct task_struct *parent);
82 extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
83 extern int cap_capset(struct cred *new, const struct cred *old,
84 const kernel_cap_t *effective,
85 const kernel_cap_t *inheritable,
86 const kernel_cap_t *permitted);
87 extern int cap_bprm_set_creds(struct linux_binprm *bprm);
88 extern int cap_inode_setxattr(struct dentry *dentry, const char *name,
89 const void *value, size_t size, int flags);
90 extern int cap_inode_removexattr(struct dentry *dentry, const char *name);
91 extern int cap_inode_need_killpriv(struct dentry *dentry);
92 extern int cap_inode_killpriv(struct dentry *dentry);
93 extern int cap_inode_getsecurity(struct inode *inode, const char *name,
94 void **buffer, bool alloc);
95 extern int cap_mmap_addr(unsigned long addr);
96 extern int cap_mmap_file(struct file *file, unsigned long reqprot,
97 unsigned long prot, unsigned long flags);
98 extern int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags);
99 extern int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
100 unsigned long arg4, unsigned long arg5);
101 extern int cap_task_setscheduler(struct task_struct *p);
102 extern int cap_task_setioprio(struct task_struct *p, int ioprio);
103 extern int cap_task_setnice(struct task_struct *p, int nice);
104 extern int cap_vm_enough_memory(struct mm_struct *mm, long pages);
113 struct xfrm_selector;
116 struct xfrm_user_sec_ctx;
120 extern unsigned long mmap_min_addr;
121 extern unsigned long dac_mmap_min_addr;
123 #define mmap_min_addr 0UL
124 #define dac_mmap_min_addr 0UL
128 * Values used in the task_security_ops calls
130 /* setuid or setgid, id0 == uid or gid */
131 #define LSM_SETID_ID 1
133 /* setreuid or setregid, id0 == real, id1 == eff */
134 #define LSM_SETID_RE 2
136 /* setresuid or setresgid, id0 == real, id1 == eff, uid2 == saved */
137 #define LSM_SETID_RES 4
139 /* setfsuid or setfsgid, id0 == fsuid or fsgid */
140 #define LSM_SETID_FS 8
142 /* Flags for security_task_prlimit(). */
143 #define LSM_PRLIMIT_READ 1
144 #define LSM_PRLIMIT_WRITE 2
146 /* forward declares to avoid warnings */
150 /* bprm->unsafe reasons */
151 #define LSM_UNSAFE_SHARE 1
152 #define LSM_UNSAFE_PTRACE 2
153 #define LSM_UNSAFE_NO_NEW_PRIVS 4
156 extern int mmap_min_addr_handler(struct ctl_table *table, int write,
157 void __user *buffer, size_t *lenp, loff_t *ppos);
160 /* security_inode_init_security callback function to write xattrs */
161 typedef int (*initxattrs) (struct inode *inode,
162 const struct xattr *xattr_array, void *fs_data);
164 #ifdef CONFIG_SECURITY
166 struct security_mnt_opts {
172 int call_lsm_notifier(enum lsm_event event, void *data);
173 int register_lsm_notifier(struct notifier_block *nb);
174 int unregister_lsm_notifier(struct notifier_block *nb);
176 static inline void security_init_mnt_opts(struct security_mnt_opts *opts)
178 opts->mnt_opts = NULL;
179 opts->mnt_opts_flags = NULL;
180 opts->num_mnt_opts = 0;
183 static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
187 for (i = 0; i < opts->num_mnt_opts; i++)
188 kfree(opts->mnt_opts[i]);
189 kfree(opts->mnt_opts);
190 opts->mnt_opts = NULL;
191 kfree(opts->mnt_opts_flags);
192 opts->mnt_opts_flags = NULL;
193 opts->num_mnt_opts = 0;
197 extern int security_init(void);
199 /* Security operations */
200 int security_binder_set_context_mgr(struct task_struct *mgr);
201 int security_binder_transaction(struct task_struct *from,
202 struct task_struct *to);
203 int security_binder_transfer_binder(struct task_struct *from,
204 struct task_struct *to);
205 int security_binder_transfer_file(struct task_struct *from,
206 struct task_struct *to, struct file *file);
207 int security_ptrace_access_check(struct task_struct *child, unsigned int mode);
208 int security_ptrace_traceme(struct task_struct *parent);
209 int security_capget(struct task_struct *target,
210 kernel_cap_t *effective,
211 kernel_cap_t *inheritable,
212 kernel_cap_t *permitted);
213 int security_capset(struct cred *new, const struct cred *old,
214 const kernel_cap_t *effective,
215 const kernel_cap_t *inheritable,
216 const kernel_cap_t *permitted);
217 int security_capable(const struct cred *cred, struct user_namespace *ns,
219 int security_capable_noaudit(const struct cred *cred, struct user_namespace *ns,
221 int security_quotactl(int cmds, int type, int id, struct super_block *sb);
222 int security_quota_on(struct dentry *dentry);
223 int security_syslog(int type);
224 int security_settime64(const struct timespec64 *ts, const struct timezone *tz);
225 int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
226 int security_bprm_set_creds(struct linux_binprm *bprm);
227 int security_bprm_check(struct linux_binprm *bprm);
228 void security_bprm_committing_creds(struct linux_binprm *bprm);
229 void security_bprm_committed_creds(struct linux_binprm *bprm);
230 int security_sb_alloc(struct super_block *sb);
231 void security_sb_free(struct super_block *sb);
232 int security_sb_copy_data(char *orig, char *copy);
233 int security_sb_remount(struct super_block *sb, void *data);
234 int security_sb_kern_mount(struct super_block *sb, int flags, void *data);
235 int security_sb_show_options(struct seq_file *m, struct super_block *sb);
236 int security_sb_statfs(struct dentry *dentry);
237 int security_sb_mount(const char *dev_name, const struct path *path,
238 const char *type, unsigned long flags, void *data);
239 int security_sb_umount(struct vfsmount *mnt, int flags);
240 int security_sb_pivotroot(const struct path *old_path, const struct path *new_path);
241 int security_sb_set_mnt_opts(struct super_block *sb,
242 struct security_mnt_opts *opts,
243 unsigned long kern_flags,
244 unsigned long *set_kern_flags);
245 int security_sb_clone_mnt_opts(const struct super_block *oldsb,
246 struct super_block *newsb,
247 unsigned long kern_flags,
248 unsigned long *set_kern_flags);
249 int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts);
250 int security_dentry_init_security(struct dentry *dentry, int mode,
251 const struct qstr *name, void **ctx,
253 int security_dentry_create_files_as(struct dentry *dentry, int mode,
255 const struct cred *old,
258 int security_inode_alloc(struct inode *inode);
259 void security_inode_free(struct inode *inode);
260 int security_inode_init_security(struct inode *inode, struct inode *dir,
261 const struct qstr *qstr,
262 initxattrs initxattrs, void *fs_data);
263 int security_old_inode_init_security(struct inode *inode, struct inode *dir,
264 const struct qstr *qstr, const char **name,
265 void **value, size_t *len);
266 int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode);
267 int security_inode_link(struct dentry *old_dentry, struct inode *dir,
268 struct dentry *new_dentry);
269 int security_inode_unlink(struct inode *dir, struct dentry *dentry);
270 int security_inode_symlink(struct inode *dir, struct dentry *dentry,
271 const char *old_name);
272 int security_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
273 int security_inode_rmdir(struct inode *dir, struct dentry *dentry);
274 int security_inode_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev);
275 int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
276 struct inode *new_dir, struct dentry *new_dentry,
278 int security_inode_readlink(struct dentry *dentry);
279 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
281 int security_inode_permission(struct inode *inode, int mask);
282 int security_inode_setattr(struct dentry *dentry, struct iattr *attr);
283 int security_inode_getattr(const struct path *path);
284 int security_inode_setxattr(struct dentry *dentry, const char *name,
285 const void *value, size_t size, int flags);
286 void security_inode_post_setxattr(struct dentry *dentry, const char *name,
287 const void *value, size_t size, int flags);
288 int security_inode_getxattr(struct dentry *dentry, const char *name);
289 int security_inode_listxattr(struct dentry *dentry);
290 int security_inode_removexattr(struct dentry *dentry, const char *name);
291 int security_inode_need_killpriv(struct dentry *dentry);
292 int security_inode_killpriv(struct dentry *dentry);
293 int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc);
294 int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags);
295 int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size);
296 void security_inode_getsecid(struct inode *inode, u32 *secid);
297 int security_inode_copy_up(struct dentry *src, struct cred **new);
298 int security_inode_copy_up_xattr(const char *name);
299 int security_file_permission(struct file *file, int mask);
300 int security_file_alloc(struct file *file);
301 void security_file_free(struct file *file);
302 int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
303 int security_mmap_file(struct file *file, unsigned long prot,
304 unsigned long flags);
305 int security_mmap_addr(unsigned long addr);
306 int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
308 int security_file_lock(struct file *file, unsigned int cmd);
309 int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg);
310 void security_file_set_fowner(struct file *file);
311 int security_file_send_sigiotask(struct task_struct *tsk,
312 struct fown_struct *fown, int sig);
313 int security_file_receive(struct file *file);
314 int security_file_open(struct file *file, const struct cred *cred);
315 int security_task_alloc(struct task_struct *task, unsigned long clone_flags);
316 void security_task_free(struct task_struct *task);
317 int security_cred_alloc_blank(struct cred *cred, gfp_t gfp);
318 void security_cred_free(struct cred *cred);
319 int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp);
320 void security_transfer_creds(struct cred *new, const struct cred *old);
321 int security_kernel_act_as(struct cred *new, u32 secid);
322 int security_kernel_create_files_as(struct cred *new, struct inode *inode);
323 int security_kernel_module_request(char *kmod_name);
324 int security_kernel_read_file(struct file *file, enum kernel_read_file_id id);
325 int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
326 enum kernel_read_file_id id);
327 int security_task_fix_setuid(struct cred *new, const struct cred *old,
329 int security_task_setpgid(struct task_struct *p, pid_t pgid);
330 int security_task_getpgid(struct task_struct *p);
331 int security_task_getsid(struct task_struct *p);
332 void security_task_getsecid(struct task_struct *p, u32 *secid);
333 int security_task_setnice(struct task_struct *p, int nice);
334 int security_task_setioprio(struct task_struct *p, int ioprio);
335 int security_task_getioprio(struct task_struct *p);
336 int security_task_prlimit(const struct cred *cred, const struct cred *tcred,
338 int security_task_setrlimit(struct task_struct *p, unsigned int resource,
339 struct rlimit *new_rlim);
340 int security_task_setscheduler(struct task_struct *p);
341 int security_task_getscheduler(struct task_struct *p);
342 int security_task_movememory(struct task_struct *p);
343 int security_task_kill(struct task_struct *p, struct siginfo *info,
344 int sig, const struct cred *cred);
345 int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
346 unsigned long arg4, unsigned long arg5);
347 void security_task_to_inode(struct task_struct *p, struct inode *inode);
348 int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag);
349 void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid);
350 int security_msg_msg_alloc(struct msg_msg *msg);
351 void security_msg_msg_free(struct msg_msg *msg);
352 int security_msg_queue_alloc(struct msg_queue *msq);
353 void security_msg_queue_free(struct msg_queue *msq);
354 int security_msg_queue_associate(struct msg_queue *msq, int msqflg);
355 int security_msg_queue_msgctl(struct msg_queue *msq, int cmd);
356 int security_msg_queue_msgsnd(struct msg_queue *msq,
357 struct msg_msg *msg, int msqflg);
358 int security_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
359 struct task_struct *target, long type, int mode);
360 int security_shm_alloc(struct shmid_kernel *shp);
361 void security_shm_free(struct shmid_kernel *shp);
362 int security_shm_associate(struct shmid_kernel *shp, int shmflg);
363 int security_shm_shmctl(struct shmid_kernel *shp, int cmd);
364 int security_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr, int shmflg);
365 int security_sem_alloc(struct sem_array *sma);
366 void security_sem_free(struct sem_array *sma);
367 int security_sem_associate(struct sem_array *sma, int semflg);
368 int security_sem_semctl(struct sem_array *sma, int cmd);
369 int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
370 unsigned nsops, int alter);
371 void security_d_instantiate(struct dentry *dentry, struct inode *inode);
372 int security_getprocattr(struct task_struct *p, char *name, char **value);
373 int security_setprocattr(const char *name, void *value, size_t size);
374 int security_netlink_send(struct sock *sk, struct sk_buff *skb);
375 int security_ismaclabel(const char *name);
376 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);
377 int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid);
378 void security_release_secctx(char *secdata, u32 seclen);
380 void security_inode_invalidate_secctx(struct inode *inode);
381 int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen);
382 int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen);
383 int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen);
384 #else /* CONFIG_SECURITY */
385 struct security_mnt_opts {
388 static inline int call_lsm_notifier(enum lsm_event event, void *data)
393 static inline int register_lsm_notifier(struct notifier_block *nb)
398 static inline int unregister_lsm_notifier(struct notifier_block *nb)
403 static inline void security_init_mnt_opts(struct security_mnt_opts *opts)
407 static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
412 * This is the default capabilities functionality. Most of these functions
413 * are just stubbed out, but a few must call the proper capable code.
416 static inline int security_init(void)
421 static inline int security_binder_set_context_mgr(struct task_struct *mgr)
426 static inline int security_binder_transaction(struct task_struct *from,
427 struct task_struct *to)
432 static inline int security_binder_transfer_binder(struct task_struct *from,
433 struct task_struct *to)
438 static inline int security_binder_transfer_file(struct task_struct *from,
439 struct task_struct *to,
445 static inline int security_ptrace_access_check(struct task_struct *child,
448 return cap_ptrace_access_check(child, mode);
451 static inline int security_ptrace_traceme(struct task_struct *parent)
453 return cap_ptrace_traceme(parent);
456 static inline int security_capget(struct task_struct *target,
457 kernel_cap_t *effective,
458 kernel_cap_t *inheritable,
459 kernel_cap_t *permitted)
461 return cap_capget(target, effective, inheritable, permitted);
464 static inline int security_capset(struct cred *new,
465 const struct cred *old,
466 const kernel_cap_t *effective,
467 const kernel_cap_t *inheritable,
468 const kernel_cap_t *permitted)
470 return cap_capset(new, old, effective, inheritable, permitted);
473 static inline int security_capable(const struct cred *cred,
474 struct user_namespace *ns, int cap)
476 return cap_capable(cred, ns, cap, SECURITY_CAP_AUDIT);
479 static inline int security_capable_noaudit(const struct cred *cred,
480 struct user_namespace *ns, int cap) {
481 return cap_capable(cred, ns, cap, SECURITY_CAP_NOAUDIT);
484 static inline int security_quotactl(int cmds, int type, int id,
485 struct super_block *sb)
490 static inline int security_quota_on(struct dentry *dentry)
495 static inline int security_syslog(int type)
500 static inline int security_settime64(const struct timespec64 *ts,
501 const struct timezone *tz)
503 return cap_settime(ts, tz);
506 static inline int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
508 return __vm_enough_memory(mm, pages, cap_vm_enough_memory(mm, pages));
511 static inline int security_bprm_set_creds(struct linux_binprm *bprm)
513 return cap_bprm_set_creds(bprm);
516 static inline int security_bprm_check(struct linux_binprm *bprm)
521 static inline void security_bprm_committing_creds(struct linux_binprm *bprm)
525 static inline void security_bprm_committed_creds(struct linux_binprm *bprm)
529 static inline int security_sb_alloc(struct super_block *sb)
534 static inline void security_sb_free(struct super_block *sb)
537 static inline int security_sb_copy_data(char *orig, char *copy)
542 static inline int security_sb_remount(struct super_block *sb, void *data)
547 static inline int security_sb_kern_mount(struct super_block *sb, int flags, void *data)
552 static inline int security_sb_show_options(struct seq_file *m,
553 struct super_block *sb)
558 static inline int security_sb_statfs(struct dentry *dentry)
563 static inline int security_sb_mount(const char *dev_name, const struct path *path,
564 const char *type, unsigned long flags,
570 static inline int security_sb_umount(struct vfsmount *mnt, int flags)
575 static inline int security_sb_pivotroot(const struct path *old_path,
576 const struct path *new_path)
581 static inline int security_sb_set_mnt_opts(struct super_block *sb,
582 struct security_mnt_opts *opts,
583 unsigned long kern_flags,
584 unsigned long *set_kern_flags)
589 static inline int security_sb_clone_mnt_opts(const struct super_block *oldsb,
590 struct super_block *newsb,
591 unsigned long kern_flags,
592 unsigned long *set_kern_flags)
597 static inline int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts)
602 static inline int security_inode_alloc(struct inode *inode)
607 static inline void security_inode_free(struct inode *inode)
610 static inline int security_dentry_init_security(struct dentry *dentry,
612 const struct qstr *name,
619 static inline int security_dentry_create_files_as(struct dentry *dentry,
620 int mode, struct qstr *name,
621 const struct cred *old,
628 static inline int security_inode_init_security(struct inode *inode,
630 const struct qstr *qstr,
631 const initxattrs xattrs,
637 static inline int security_old_inode_init_security(struct inode *inode,
639 const struct qstr *qstr,
641 void **value, size_t *len)
646 static inline int security_inode_create(struct inode *dir,
647 struct dentry *dentry,
653 static inline int security_inode_link(struct dentry *old_dentry,
655 struct dentry *new_dentry)
660 static inline int security_inode_unlink(struct inode *dir,
661 struct dentry *dentry)
666 static inline int security_inode_symlink(struct inode *dir,
667 struct dentry *dentry,
668 const char *old_name)
673 static inline int security_inode_mkdir(struct inode *dir,
674 struct dentry *dentry,
680 static inline int security_inode_rmdir(struct inode *dir,
681 struct dentry *dentry)
686 static inline int security_inode_mknod(struct inode *dir,
687 struct dentry *dentry,
693 static inline int security_inode_rename(struct inode *old_dir,
694 struct dentry *old_dentry,
695 struct inode *new_dir,
696 struct dentry *new_dentry,
702 static inline int security_inode_readlink(struct dentry *dentry)
707 static inline int security_inode_follow_link(struct dentry *dentry,
714 static inline int security_inode_permission(struct inode *inode, int mask)
719 static inline int security_inode_setattr(struct dentry *dentry,
725 static inline int security_inode_getattr(const struct path *path)
730 static inline int security_inode_setxattr(struct dentry *dentry,
731 const char *name, const void *value, size_t size, int flags)
733 return cap_inode_setxattr(dentry, name, value, size, flags);
736 static inline void security_inode_post_setxattr(struct dentry *dentry,
737 const char *name, const void *value, size_t size, int flags)
740 static inline int security_inode_getxattr(struct dentry *dentry,
746 static inline int security_inode_listxattr(struct dentry *dentry)
751 static inline int security_inode_removexattr(struct dentry *dentry,
754 return cap_inode_removexattr(dentry, name);
757 static inline int security_inode_need_killpriv(struct dentry *dentry)
759 return cap_inode_need_killpriv(dentry);
762 static inline int security_inode_killpriv(struct dentry *dentry)
764 return cap_inode_killpriv(dentry);
767 static inline int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc)
772 static inline int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
777 static inline int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
782 static inline void security_inode_getsecid(struct inode *inode, u32 *secid)
787 static inline int security_inode_copy_up(struct dentry *src, struct cred **new)
792 static inline int security_inode_copy_up_xattr(const char *name)
797 static inline int security_file_permission(struct file *file, int mask)
802 static inline int security_file_alloc(struct file *file)
807 static inline void security_file_free(struct file *file)
810 static inline int security_file_ioctl(struct file *file, unsigned int cmd,
816 static inline int security_mmap_file(struct file *file, unsigned long prot,
822 static inline int security_mmap_addr(unsigned long addr)
824 return cap_mmap_addr(addr);
827 static inline int security_file_mprotect(struct vm_area_struct *vma,
828 unsigned long reqprot,
834 static inline int security_file_lock(struct file *file, unsigned int cmd)
839 static inline int security_file_fcntl(struct file *file, unsigned int cmd,
845 static inline void security_file_set_fowner(struct file *file)
850 static inline int security_file_send_sigiotask(struct task_struct *tsk,
851 struct fown_struct *fown,
857 static inline int security_file_receive(struct file *file)
862 static inline int security_file_open(struct file *file,
863 const struct cred *cred)
868 static inline int security_task_alloc(struct task_struct *task,
869 unsigned long clone_flags)
874 static inline void security_task_free(struct task_struct *task)
877 static inline int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
882 static inline void security_cred_free(struct cred *cred)
885 static inline int security_prepare_creds(struct cred *new,
886 const struct cred *old,
892 static inline void security_transfer_creds(struct cred *new,
893 const struct cred *old)
897 static inline int security_kernel_act_as(struct cred *cred, u32 secid)
902 static inline int security_kernel_create_files_as(struct cred *cred,
908 static inline int security_kernel_module_request(char *kmod_name)
913 static inline int security_kernel_read_file(struct file *file,
914 enum kernel_read_file_id id)
919 static inline int security_kernel_post_read_file(struct file *file,
920 char *buf, loff_t size,
921 enum kernel_read_file_id id)
926 static inline int security_task_fix_setuid(struct cred *new,
927 const struct cred *old,
930 return cap_task_fix_setuid(new, old, flags);
933 static inline int security_task_setpgid(struct task_struct *p, pid_t pgid)
938 static inline int security_task_getpgid(struct task_struct *p)
943 static inline int security_task_getsid(struct task_struct *p)
948 static inline void security_task_getsecid(struct task_struct *p, u32 *secid)
953 static inline int security_task_setnice(struct task_struct *p, int nice)
955 return cap_task_setnice(p, nice);
958 static inline int security_task_setioprio(struct task_struct *p, int ioprio)
960 return cap_task_setioprio(p, ioprio);
963 static inline int security_task_getioprio(struct task_struct *p)
968 static inline int security_task_prlimit(const struct cred *cred,
969 const struct cred *tcred,
975 static inline int security_task_setrlimit(struct task_struct *p,
976 unsigned int resource,
977 struct rlimit *new_rlim)
982 static inline int security_task_setscheduler(struct task_struct *p)
984 return cap_task_setscheduler(p);
987 static inline int security_task_getscheduler(struct task_struct *p)
992 static inline int security_task_movememory(struct task_struct *p)
997 static inline int security_task_kill(struct task_struct *p,
998 struct siginfo *info, int sig,
999 const struct cred *cred)
1004 static inline int security_task_prctl(int option, unsigned long arg2,
1009 return cap_task_prctl(option, arg2, arg3, arg4, arg5);
1012 static inline void security_task_to_inode(struct task_struct *p, struct inode *inode)
1015 static inline int security_ipc_permission(struct kern_ipc_perm *ipcp,
1021 static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
1026 static inline int security_msg_msg_alloc(struct msg_msg *msg)
1031 static inline void security_msg_msg_free(struct msg_msg *msg)
1034 static inline int security_msg_queue_alloc(struct msg_queue *msq)
1039 static inline void security_msg_queue_free(struct msg_queue *msq)
1042 static inline int security_msg_queue_associate(struct msg_queue *msq,
1048 static inline int security_msg_queue_msgctl(struct msg_queue *msq, int cmd)
1053 static inline int security_msg_queue_msgsnd(struct msg_queue *msq,
1054 struct msg_msg *msg, int msqflg)
1059 static inline int security_msg_queue_msgrcv(struct msg_queue *msq,
1060 struct msg_msg *msg,
1061 struct task_struct *target,
1062 long type, int mode)
1067 static inline int security_shm_alloc(struct shmid_kernel *shp)
1072 static inline void security_shm_free(struct shmid_kernel *shp)
1075 static inline int security_shm_associate(struct shmid_kernel *shp,
1081 static inline int security_shm_shmctl(struct shmid_kernel *shp, int cmd)
1086 static inline int security_shm_shmat(struct shmid_kernel *shp,
1087 char __user *shmaddr, int shmflg)
1092 static inline int security_sem_alloc(struct sem_array *sma)
1097 static inline void security_sem_free(struct sem_array *sma)
1100 static inline int security_sem_associate(struct sem_array *sma, int semflg)
1105 static inline int security_sem_semctl(struct sem_array *sma, int cmd)
1110 static inline int security_sem_semop(struct sem_array *sma,
1111 struct sembuf *sops, unsigned nsops,
1117 static inline void security_d_instantiate(struct dentry *dentry, struct inode *inode)
1120 static inline int security_getprocattr(struct task_struct *p, char *name, char **value)
1125 static inline int security_setprocattr(char *name, void *value, size_t size)
1130 static inline int security_netlink_send(struct sock *sk, struct sk_buff *skb)
1135 static inline int security_ismaclabel(const char *name)
1140 static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
1145 static inline int security_secctx_to_secid(const char *secdata,
1152 static inline void security_release_secctx(char *secdata, u32 seclen)
1156 static inline void security_inode_invalidate_secctx(struct inode *inode)
1160 static inline int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
1164 static inline int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
1168 static inline int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
1172 #endif /* CONFIG_SECURITY */
1174 #ifdef CONFIG_SECURITY_NETWORK
1176 int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk);
1177 int security_unix_may_send(struct socket *sock, struct socket *other);
1178 int security_socket_create(int family, int type, int protocol, int kern);
1179 int security_socket_post_create(struct socket *sock, int family,
1180 int type, int protocol, int kern);
1181 int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen);
1182 int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen);
1183 int security_socket_listen(struct socket *sock, int backlog);
1184 int security_socket_accept(struct socket *sock, struct socket *newsock);
1185 int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size);
1186 int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,
1187 int size, int flags);
1188 int security_socket_getsockname(struct socket *sock);
1189 int security_socket_getpeername(struct socket *sock);
1190 int security_socket_getsockopt(struct socket *sock, int level, int optname);
1191 int security_socket_setsockopt(struct socket *sock, int level, int optname);
1192 int security_socket_shutdown(struct socket *sock, int how);
1193 int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb);
1194 int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
1195 int __user *optlen, unsigned len);
1196 int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid);
1197 int security_sk_alloc(struct sock *sk, int family, gfp_t priority);
1198 void security_sk_free(struct sock *sk);
1199 void security_sk_clone(const struct sock *sk, struct sock *newsk);
1200 void security_sk_classify_flow(struct sock *sk, struct flowi *fl);
1201 void security_req_classify_flow(const struct request_sock *req, struct flowi *fl);
1202 void security_sock_graft(struct sock*sk, struct socket *parent);
1203 int security_inet_conn_request(struct sock *sk,
1204 struct sk_buff *skb, struct request_sock *req);
1205 void security_inet_csk_clone(struct sock *newsk,
1206 const struct request_sock *req);
1207 void security_inet_conn_established(struct sock *sk,
1208 struct sk_buff *skb);
1209 int security_secmark_relabel_packet(u32 secid);
1210 void security_secmark_refcount_inc(void);
1211 void security_secmark_refcount_dec(void);
1212 int security_tun_dev_alloc_security(void **security);
1213 void security_tun_dev_free_security(void *security);
1214 int security_tun_dev_create(void);
1215 int security_tun_dev_attach_queue(void *security);
1216 int security_tun_dev_attach(struct sock *sk, void *security);
1217 int security_tun_dev_open(void *security);
1219 #else /* CONFIG_SECURITY_NETWORK */
1220 static inline int security_unix_stream_connect(struct sock *sock,
1227 static inline int security_unix_may_send(struct socket *sock,
1228 struct socket *other)
1233 static inline int security_socket_create(int family, int type,
1234 int protocol, int kern)
1239 static inline int security_socket_post_create(struct socket *sock,
1242 int protocol, int kern)
1247 static inline int security_socket_bind(struct socket *sock,
1248 struct sockaddr *address,
1254 static inline int security_socket_connect(struct socket *sock,
1255 struct sockaddr *address,
1261 static inline int security_socket_listen(struct socket *sock, int backlog)
1266 static inline int security_socket_accept(struct socket *sock,
1267 struct socket *newsock)
1272 static inline int security_socket_sendmsg(struct socket *sock,
1273 struct msghdr *msg, int size)
1278 static inline int security_socket_recvmsg(struct socket *sock,
1279 struct msghdr *msg, int size,
1285 static inline int security_socket_getsockname(struct socket *sock)
1290 static inline int security_socket_getpeername(struct socket *sock)
1295 static inline int security_socket_getsockopt(struct socket *sock,
1296 int level, int optname)
1301 static inline int security_socket_setsockopt(struct socket *sock,
1302 int level, int optname)
1307 static inline int security_socket_shutdown(struct socket *sock, int how)
1311 static inline int security_sock_rcv_skb(struct sock *sk,
1312 struct sk_buff *skb)
1317 static inline int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
1318 int __user *optlen, unsigned len)
1320 return -ENOPROTOOPT;
1323 static inline int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
1325 return -ENOPROTOOPT;
1328 static inline int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
1333 static inline void security_sk_free(struct sock *sk)
1337 static inline void security_sk_clone(const struct sock *sk, struct sock *newsk)
1341 static inline void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
1345 static inline void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
1349 static inline void security_sock_graft(struct sock *sk, struct socket *parent)
1353 static inline int security_inet_conn_request(struct sock *sk,
1354 struct sk_buff *skb, struct request_sock *req)
1359 static inline void security_inet_csk_clone(struct sock *newsk,
1360 const struct request_sock *req)
1364 static inline void security_inet_conn_established(struct sock *sk,
1365 struct sk_buff *skb)
1369 static inline int security_secmark_relabel_packet(u32 secid)
1374 static inline void security_secmark_refcount_inc(void)
1378 static inline void security_secmark_refcount_dec(void)
1382 static inline int security_tun_dev_alloc_security(void **security)
1387 static inline void security_tun_dev_free_security(void *security)
1391 static inline int security_tun_dev_create(void)
1396 static inline int security_tun_dev_attach_queue(void *security)
1401 static inline int security_tun_dev_attach(struct sock *sk, void *security)
1406 static inline int security_tun_dev_open(void *security)
1410 #endif /* CONFIG_SECURITY_NETWORK */
1412 #ifdef CONFIG_SECURITY_INFINIBAND
1413 int security_ib_pkey_access(void *sec, u64 subnet_prefix, u16 pkey);
1414 int security_ib_endport_manage_subnet(void *sec, const char *name, u8 port_num);
1415 int security_ib_alloc_security(void **sec);
1416 void security_ib_free_security(void *sec);
1417 #else /* CONFIG_SECURITY_INFINIBAND */
1418 static inline int security_ib_pkey_access(void *sec, u64 subnet_prefix, u16 pkey)
1423 static inline int security_ib_endport_manage_subnet(void *sec, const char *dev_name, u8 port_num)
1428 static inline int security_ib_alloc_security(void **sec)
1433 static inline void security_ib_free_security(void *sec)
1436 #endif /* CONFIG_SECURITY_INFINIBAND */
1438 #ifdef CONFIG_SECURITY_NETWORK_XFRM
1440 int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
1441 struct xfrm_user_sec_ctx *sec_ctx, gfp_t gfp);
1442 int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, struct xfrm_sec_ctx **new_ctxp);
1443 void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx);
1444 int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx);
1445 int security_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *sec_ctx);
1446 int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
1447 struct xfrm_sec_ctx *polsec, u32 secid);
1448 int security_xfrm_state_delete(struct xfrm_state *x);
1449 void security_xfrm_state_free(struct xfrm_state *x);
1450 int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir);
1451 int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
1452 struct xfrm_policy *xp,
1453 const struct flowi *fl);
1454 int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid);
1455 void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl);
1457 #else /* CONFIG_SECURITY_NETWORK_XFRM */
1459 static inline int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
1460 struct xfrm_user_sec_ctx *sec_ctx,
1466 static inline int security_xfrm_policy_clone(struct xfrm_sec_ctx *old, struct xfrm_sec_ctx **new_ctxp)
1471 static inline void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
1475 static inline int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
1480 static inline int security_xfrm_state_alloc(struct xfrm_state *x,
1481 struct xfrm_user_sec_ctx *sec_ctx)
1486 static inline int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
1487 struct xfrm_sec_ctx *polsec, u32 secid)
1492 static inline void security_xfrm_state_free(struct xfrm_state *x)
1496 static inline int security_xfrm_state_delete(struct xfrm_state *x)
1501 static inline int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir)
1506 static inline int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
1507 struct xfrm_policy *xp, const struct flowi *fl)
1512 static inline int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
1517 static inline void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
1521 #endif /* CONFIG_SECURITY_NETWORK_XFRM */
1523 #ifdef CONFIG_SECURITY_PATH
1524 int security_path_unlink(const struct path *dir, struct dentry *dentry);
1525 int security_path_mkdir(const struct path *dir, struct dentry *dentry, umode_t mode);
1526 int security_path_rmdir(const struct path *dir, struct dentry *dentry);
1527 int security_path_mknod(const struct path *dir, struct dentry *dentry, umode_t mode,
1529 int security_path_truncate(const struct path *path);
1530 int security_path_symlink(const struct path *dir, struct dentry *dentry,
1531 const char *old_name);
1532 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1533 struct dentry *new_dentry);
1534 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1535 const struct path *new_dir, struct dentry *new_dentry,
1536 unsigned int flags);
1537 int security_path_chmod(const struct path *path, umode_t mode);
1538 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid);
1539 int security_path_chroot(const struct path *path);
1540 #else /* CONFIG_SECURITY_PATH */
1541 static inline int security_path_unlink(const struct path *dir, struct dentry *dentry)
1546 static inline int security_path_mkdir(const struct path *dir, struct dentry *dentry,
1552 static inline int security_path_rmdir(const struct path *dir, struct dentry *dentry)
1557 static inline int security_path_mknod(const struct path *dir, struct dentry *dentry,
1558 umode_t mode, unsigned int dev)
1563 static inline int security_path_truncate(const struct path *path)
1568 static inline int security_path_symlink(const struct path *dir, struct dentry *dentry,
1569 const char *old_name)
1574 static inline int security_path_link(struct dentry *old_dentry,
1575 const struct path *new_dir,
1576 struct dentry *new_dentry)
1581 static inline int security_path_rename(const struct path *old_dir,
1582 struct dentry *old_dentry,
1583 const struct path *new_dir,
1584 struct dentry *new_dentry,
1590 static inline int security_path_chmod(const struct path *path, umode_t mode)
1595 static inline int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1600 static inline int security_path_chroot(const struct path *path)
1604 #endif /* CONFIG_SECURITY_PATH */
1607 #ifdef CONFIG_SECURITY
1609 int security_key_alloc(struct key *key, const struct cred *cred, unsigned long flags);
1610 void security_key_free(struct key *key);
1611 int security_key_permission(key_ref_t key_ref,
1612 const struct cred *cred, unsigned perm);
1613 int security_key_getsecurity(struct key *key, char **_buffer);
1617 static inline int security_key_alloc(struct key *key,
1618 const struct cred *cred,
1619 unsigned long flags)
1624 static inline void security_key_free(struct key *key)
1628 static inline int security_key_permission(key_ref_t key_ref,
1629 const struct cred *cred,
1635 static inline int security_key_getsecurity(struct key *key, char **_buffer)
1642 #endif /* CONFIG_KEYS */
1645 #ifdef CONFIG_SECURITY
1646 int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule);
1647 int security_audit_rule_known(struct audit_krule *krule);
1648 int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule,
1649 struct audit_context *actx);
1650 void security_audit_rule_free(void *lsmrule);
1654 static inline int security_audit_rule_init(u32 field, u32 op, char *rulestr,
1660 static inline int security_audit_rule_known(struct audit_krule *krule)
1665 static inline int security_audit_rule_match(u32 secid, u32 field, u32 op,
1666 void *lsmrule, struct audit_context *actx)
1671 static inline void security_audit_rule_free(void *lsmrule)
1674 #endif /* CONFIG_SECURITY */
1675 #endif /* CONFIG_AUDIT */
1677 #ifdef CONFIG_SECURITYFS
1679 extern struct dentry *securityfs_create_file(const char *name, umode_t mode,
1680 struct dentry *parent, void *data,
1681 const struct file_operations *fops);
1682 extern struct dentry *securityfs_create_dir(const char *name, struct dentry *parent);
1683 struct dentry *securityfs_create_symlink(const char *name,
1684 struct dentry *parent,
1686 const struct inode_operations *iops);
1687 extern void securityfs_remove(struct dentry *dentry);
1689 #else /* CONFIG_SECURITYFS */
1691 static inline struct dentry *securityfs_create_dir(const char *name,
1692 struct dentry *parent)
1694 return ERR_PTR(-ENODEV);
1697 static inline struct dentry *securityfs_create_file(const char *name,
1699 struct dentry *parent,
1701 const struct file_operations *fops)
1703 return ERR_PTR(-ENODEV);
1706 static inline struct dentry *securityfs_create_symlink(const char *name,
1707 struct dentry *parent,
1709 const struct inode_operations *iops)
1711 return ERR_PTR(-ENODEV);
1714 static inline void securityfs_remove(struct dentry *dentry)
1719 #ifdef CONFIG_BPF_SYSCALL
1723 struct bpf_prog_aux;
1724 #ifdef CONFIG_SECURITY
1725 extern int security_bpf(int cmd, union bpf_attr *attr, unsigned int size);
1726 extern int security_bpf_map(struct bpf_map *map, fmode_t fmode);
1727 extern int security_bpf_prog(struct bpf_prog *prog);
1728 extern int security_bpf_map_alloc(struct bpf_map *map);
1729 extern void security_bpf_map_free(struct bpf_map *map);
1730 extern int security_bpf_prog_alloc(struct bpf_prog_aux *aux);
1731 extern void security_bpf_prog_free(struct bpf_prog_aux *aux);
1733 static inline int security_bpf(int cmd, union bpf_attr *attr,
1739 static inline int security_bpf_map(struct bpf_map *map, fmode_t fmode)
1744 static inline int security_bpf_prog(struct bpf_prog *prog)
1749 static inline int security_bpf_map_alloc(struct bpf_map *map)
1754 static inline void security_bpf_map_free(struct bpf_map *map)
1757 static inline int security_bpf_prog_alloc(struct bpf_prog_aux *aux)
1762 static inline void security_bpf_prog_free(struct bpf_prog_aux *aux)
1764 #endif /* CONFIG_SECURITY */
1765 #endif /* CONFIG_BPF_SYSCALL */
1767 #ifdef CONFIG_SECURITY
1769 static inline char *alloc_secdata(void)
1771 return (char *)get_zeroed_page(GFP_KERNEL);
1774 static inline void free_secdata(void *secdata)
1776 free_page((unsigned long)secdata);
1781 static inline char *alloc_secdata(void)
1786 static inline void free_secdata(void *secdata)
1788 #endif /* CONFIG_SECURITY */
1790 #endif /* ! __LINUX_SECURITY_H */