14 #include <linux/capability.h>
15 #include <linux/module.h>
17 #include <linux/kernel.h>
23 #include <linux/mman.h>
25 #include <linux/personality.h>
29 #define MAX_LSM_EVM_XATTR 2
33 CONFIG_DEFAULT_SECURITY;
35 static struct security_operations *security_ops;
36 static struct security_operations default_security_ops = {
40 static inline int __init verify(
struct security_operations *ops)
49 static void __init do_security_initcalls(
void)
53 while (call < __security_initcall_end) {
69 security_ops = &default_security_ops;
70 do_security_initcalls();
77 security_ops = &default_security_ops;
86 __setup(
"security=", choose_lsm);
104 return !
strcmp(ops->name, chosen_lsm);
123 "security_operations structure.\n", __func__);
127 if (security_ops != &default_security_ops)
139 #ifdef CONFIG_SECURITY_YAMA_STACKED
145 return security_ops->ptrace_access_check(child, mode);
150 #ifdef CONFIG_SECURITY_YAMA_STACKED
156 return security_ops->ptrace_traceme(parent);
164 return security_ops->capget(target, effective, inheritable, permitted);
172 return security_ops->capset(
new, old,
173 effective, inheritable, permitted);
190 return security_ops->quotactl(cmds, type,
id, sb);
195 return security_ops->quota_on(dentry);
200 return security_ops->syslog(type);
205 return security_ops->settime(ts, tz);
210 return security_ops->vm_enough_memory(mm, pages);
215 return security_ops->bprm_set_creds(bprm);
222 ret = security_ops->bprm_check_security(bprm);
230 security_ops->bprm_committing_creds(bprm);
235 security_ops->bprm_committed_creds(bprm);
240 return security_ops->bprm_secureexec(bprm);
245 return security_ops->sb_alloc_security(sb);
250 security_ops->sb_free_security(sb);
255 return security_ops->sb_copy_data(orig, copy);
261 return security_ops->sb_remount(sb, data);
266 return security_ops->sb_kern_mount(sb, flags, data);
271 return security_ops->sb_show_options(m, sb);
276 return security_ops->sb_statfs(dentry);
282 return security_ops->sb_mount(dev_name, path, type, flags, data);
287 return security_ops->sb_umount(mnt, flags);
292 return security_ops->sb_pivotroot(old_path, new_path);
298 return security_ops->sb_set_mnt_opts(sb, opts);
305 security_ops->sb_clone_mnt_opts(oldsb, newsb);
311 return security_ops->sb_parse_opts_str(options, opts);
317 inode->i_security =
NULL;
318 return security_ops->inode_alloc_security(inode);
324 security_ops->inode_free_security(inode);
331 struct xattr new_xattrs[MAX_LSM_EVM_XATTR + 1];
338 memset(new_xattrs, 0,
sizeof new_xattrs);
340 return security_ops->inode_init_security(inode, dir, qstr,
342 lsm_xattr = new_xattrs;
343 ret = security_ops->inode_init_security(inode, dir, qstr,
350 evm_xattr = lsm_xattr + 1;
356 for (xattr = new_xattrs; xattr->
name !=
NULL; xattr++) {
366 void **
value,
size_t *len)
370 return security_ops->inode_init_security(inode, dir, qstr, name, value,
375 #ifdef CONFIG_SECURITY_PATH
381 return security_ops->path_mknod(dir, dentry, mode, dev);
385 int security_path_mkdir(
struct path *dir,
struct dentry *dentry,
umode_t mode)
389 return security_ops->path_mkdir(dir, dentry, mode);
393 int security_path_rmdir(
struct path *dir,
struct dentry *dentry)
397 return security_ops->path_rmdir(dir, dentry);
400 int security_path_unlink(
struct path *dir,
struct dentry *dentry)
404 return security_ops->path_unlink(dir, dentry);
408 int security_path_symlink(
struct path *dir,
struct dentry *dentry,
409 const char *old_name)
413 return security_ops->path_symlink(dir, dentry, old_name);
416 int security_path_link(
struct dentry *old_dentry,
struct path *new_dir,
417 struct dentry *new_dentry)
421 return security_ops->path_link(old_dentry, new_dir, new_dentry);
424 int security_path_rename(
struct path *old_dir,
struct dentry *old_dentry,
425 struct path *new_dir,
struct dentry *new_dentry)
430 return security_ops->path_rename(old_dir, old_dentry, new_dir,
435 int security_path_truncate(
struct path *
path)
439 return security_ops->path_truncate(path);
442 int security_path_chmod(
struct path *path,
umode_t mode)
446 return security_ops->path_chmod(path, mode);
453 return security_ops->path_chown(path, uid, gid);
456 int security_path_chroot(
struct path *path)
458 return security_ops->path_chroot(path);
466 return security_ops->inode_create(dir, dentry, mode);
471 struct dentry *new_dentry)
475 return security_ops->inode_link(old_dentry, dir, new_dentry);
482 return security_ops->inode_unlink(dir, dentry);
486 const char *old_name)
490 return security_ops->inode_symlink(dir, dentry, old_name);
497 return security_ops->inode_mkdir(dir, dentry, mode);
505 return security_ops->inode_rmdir(dir, dentry);
512 return security_ops->inode_mknod(dir, dentry, mode, dev);
516 struct inode *new_dir,
struct dentry *new_dentry)
521 return security_ops->inode_rename(old_dir, old_dentry,
522 new_dir, new_dentry);
529 return security_ops->inode_readlink(dentry);
536 return security_ops->inode_follow_link(dentry, nd);
543 return security_ops->inode_permission(inode, mask);
552 ret = security_ops->inode_setattr(dentry, attr);
563 return security_ops->inode_getattr(mnt, dentry);
573 ret = security_ops->inode_setxattr(dentry, name, value, size, flags);
587 security_ops->inode_post_setxattr(dentry, name, value, size, flags);
595 return security_ops->inode_getxattr(dentry, name);
602 return security_ops->inode_listxattr(dentry);
611 ret = security_ops->inode_removexattr(dentry, name);
622 return security_ops->inode_need_killpriv(dentry);
627 return security_ops->inode_killpriv(dentry);
634 return security_ops->inode_getsecurity(inode, name, buffer, alloc);
641 return security_ops->inode_setsecurity(inode, name, value, size, flags);
648 return security_ops->inode_listsecurity(inode, buffer, buffer_size);
653 security_ops->inode_getsecid(inode, secid);
660 ret = security_ops->file_permission(file, mask);
664 return fsnotify_perm(file, mask);
669 return security_ops->file_alloc_security(file);
674 security_ops->file_free_security(file);
679 return security_ops->file_ioctl(file, cmd, arg);
682 static inline unsigned long mmap_prot(
struct file *
file,
unsigned long prot)
703 unsigned long caps = 0;
720 ret = security_ops->mmap_file(file, prot,
721 mmap_prot(file, prot), flags);
729 return security_ops->mmap_addr(addr);
735 return security_ops->file_mprotect(vma, reqprot, prot);
740 return security_ops->file_lock(file, cmd);
745 return security_ops->file_fcntl(file, cmd, arg);
750 return security_ops->file_set_fowner(file);
756 return security_ops->file_send_sigiotask(tsk, fown, sig);
761 return security_ops->file_receive(file);
768 ret = security_ops->file_open(file, cred);
772 return fsnotify_perm(file,
MAY_OPEN);
777 return security_ops->task_create(clone_flags);
782 #ifdef CONFIG_SECURITY_YAMA_STACKED
785 security_ops->task_free(task);
790 return security_ops->cred_alloc_blank(cred, gfp);
795 security_ops->cred_free(cred);
800 return security_ops->cred_prepare(
new, old, gfp);
805 security_ops->cred_transfer(
new, old);
810 return security_ops->kernel_act_as(
new, secid);
815 return security_ops->kernel_create_files_as(
new, inode);
820 return security_ops->kernel_module_request(kmod_name);
826 return security_ops->task_fix_setuid(
new, old, flags);
831 return security_ops->task_setpgid(p, pgid);
836 return security_ops->task_getpgid(p);
841 return security_ops->task_getsid(p);
846 security_ops->task_getsecid(p, secid);
852 return security_ops->task_setnice(p, nice);
857 return security_ops->task_setioprio(p, ioprio);
862 return security_ops->task_getioprio(p);
868 return security_ops->task_setrlimit(p, resource, new_rlim);
873 return security_ops->task_setscheduler(p);
878 return security_ops->task_getscheduler(p);
883 return security_ops->task_movememory(p);
889 return security_ops->task_kill(p, info, sig, secid);
894 return security_ops->task_wait(p);
898 unsigned long arg4,
unsigned long arg5)
900 #ifdef CONFIG_SECURITY_YAMA_STACKED
906 return security_ops->task_prctl(option, arg2, arg3, arg4, arg5);
911 security_ops->task_to_inode(p, inode);
916 return security_ops->ipc_permission(ipcp, flag);
921 security_ops->ipc_getsecid(ipcp, secid);
926 return security_ops->msg_msg_alloc_security(msg);
931 security_ops->msg_msg_free_security(msg);
936 return security_ops->msg_queue_alloc_security(msq);
941 security_ops->msg_queue_free_security(msq);
946 return security_ops->msg_queue_associate(msq, msqflg);
951 return security_ops->msg_queue_msgctl(msq, cmd);
957 return security_ops->msg_queue_msgsnd(msq, msg, msqflg);
963 return security_ops->msg_queue_msgrcv(msq, msg, target, type, mode);
968 return security_ops->shm_alloc_security(shp);
973 security_ops->shm_free_security(shp);
978 return security_ops->shm_associate(shp, shmflg);
983 return security_ops->shm_shmctl(shp, cmd);
988 return security_ops->shm_shmat(shp, shmaddr, shmflg);
993 return security_ops->sem_alloc_security(sma);
998 security_ops->sem_free_security(sma);
1003 return security_ops->sem_associate(sma, semflg);
1008 return security_ops->sem_semctl(sma, cmd);
1012 unsigned nsops,
int alter)
1014 return security_ops->sem_semop(sma, sops, nsops, alter);
1021 security_ops->d_instantiate(dentry, inode);
1027 return security_ops->getprocattr(p, name, value);
1032 return security_ops->setprocattr(p, name, value, size);
1037 return security_ops->netlink_send(sk, skb);
1042 return security_ops->secid_to_secctx(secid, secdata, seclen);
1048 return security_ops->secctx_to_secid(secdata, seclen, secid);
1054 security_ops->release_secctx(secdata, seclen);
1060 return security_ops->inode_notifysecctx(inode, ctx, ctxlen);
1066 return security_ops->inode_setsecctx(dentry, ctx, ctxlen);
1072 return security_ops->inode_getsecctx(inode, ctx, ctxlen);
1076 #ifdef CONFIG_SECURITY_NETWORK
1078 int security_unix_stream_connect(
struct sock *
sock,
struct sock *
other,
struct sock *newsk)
1080 return security_ops->unix_stream_connect(sock, other, newsk);
1084 int security_unix_may_send(
struct socket *sock,
struct socket *other)
1086 return security_ops->unix_may_send(sock, other);
1092 return security_ops->socket_create(family, type, protocol, kern);
1095 int security_socket_post_create(
struct socket *sock,
int family,
1096 int type,
int protocol,
int kern)
1098 return security_ops->socket_post_create(sock, family, type,
1104 return security_ops->socket_bind(sock, address, addrlen);
1107 int security_socket_connect(
struct socket *sock,
struct sockaddr *address,
int addrlen)
1109 return security_ops->socket_connect(sock, address, addrlen);
1112 int security_socket_listen(
struct socket *sock,
int backlog)
1114 return security_ops->socket_listen(sock, backlog);
1117 int security_socket_accept(
struct socket *sock,
struct socket *newsock)
1119 return security_ops->socket_accept(sock, newsock);
1124 return security_ops->socket_sendmsg(sock, msg, size);
1127 int security_socket_recvmsg(
struct socket *sock,
struct msghdr *msg,
1128 int size,
int flags)
1130 return security_ops->socket_recvmsg(sock, msg, size, flags);
1133 int security_socket_getsockname(
struct socket *sock)
1135 return security_ops->socket_getsockname(sock);
1138 int security_socket_getpeername(
struct socket *sock)
1140 return security_ops->socket_getpeername(sock);
1143 int security_socket_getsockopt(
struct socket *sock,
int level,
int optname)
1145 return security_ops->socket_getsockopt(sock, level, optname);
1148 int security_socket_setsockopt(
struct socket *sock,
int level,
int optname)
1150 return security_ops->socket_setsockopt(sock, level, optname);
1153 int security_socket_shutdown(
struct socket *sock,
int how)
1155 return security_ops->socket_shutdown(sock, how);
1158 int security_sock_rcv_skb(
struct sock *
sk,
struct sk_buff *
skb)
1160 return security_ops->socket_sock_rcv_skb(sk, skb);
1164 int security_socket_getpeersec_stream(
struct socket *sock,
char __user *optval,
1165 int __user *optlen,
unsigned len)
1167 return security_ops->socket_getpeersec_stream(sock, optval, optlen, len);
1170 int security_socket_getpeersec_dgram(
struct socket *sock,
struct sk_buff *skb,
u32 *secid)
1172 return security_ops->socket_getpeersec_dgram(sock, skb, secid);
1176 int security_sk_alloc(
struct sock *sk,
int family,
gfp_t priority)
1178 return security_ops->sk_alloc_security(sk, family, priority);
1181 void security_sk_free(
struct sock *sk)
1183 security_ops->sk_free_security(sk);
1186 void security_sk_clone(
const struct sock *sk,
struct sock *newsk)
1188 security_ops->sk_clone_security(sk, newsk);
1192 void security_sk_classify_flow(
struct sock *sk,
struct flowi *
fl)
1194 security_ops->sk_getsecid(sk, &fl->flowi_secid);
1200 security_ops->req_classify_flow(req, fl);
1204 void security_sock_graft(
struct sock *sk,
struct socket *parent)
1206 security_ops->sock_graft(sk, parent);
1210 int security_inet_conn_request(
struct sock *sk,
1213 return security_ops->inet_conn_request(sk, skb, req);
1217 void security_inet_csk_clone(
struct sock *newsk,
1220 security_ops->inet_csk_clone(newsk, req);
1223 void security_inet_conn_established(
struct sock *sk,
1226 security_ops->inet_conn_established(sk, skb);
1229 int security_secmark_relabel_packet(
u32 secid)
1231 return security_ops->secmark_relabel_packet(secid);
1235 void security_secmark_refcount_inc(
void)
1237 security_ops->secmark_refcount_inc();
1241 void security_secmark_refcount_dec(
void)
1243 security_ops->secmark_refcount_dec();
1247 int security_tun_dev_create(
void)
1249 return security_ops->tun_dev_create();
1253 void security_tun_dev_post_create(
struct sock *sk)
1255 return security_ops->tun_dev_post_create(sk);
1259 int security_tun_dev_attach(
struct sock *sk)
1261 return security_ops->tun_dev_attach(sk);
1267 #ifdef CONFIG_SECURITY_NETWORK_XFRM
1271 return security_ops->xfrm_policy_alloc_security(ctxp, sec_ctx);
1275 int security_xfrm_policy_clone(
struct xfrm_sec_ctx *old_ctx,
1278 return security_ops->xfrm_policy_clone_security(old_ctx, new_ctxp);
1283 security_ops->xfrm_policy_free_security(ctx);
1287 int security_xfrm_policy_delete(
struct xfrm_sec_ctx *ctx)
1289 return security_ops->xfrm_policy_delete_security(ctx);
1294 return security_ops->xfrm_state_alloc_security(x, sec_ctx, 0);
1298 int security_xfrm_state_alloc_acquire(
struct xfrm_state *x,
1307 return security_ops->xfrm_state_alloc_security(x,
NULL, secid);
1310 int security_xfrm_state_delete(
struct xfrm_state *x)
1312 return security_ops->xfrm_state_delete_security(x);
1316 void security_xfrm_state_free(
struct xfrm_state *x)
1318 security_ops->xfrm_state_free_security(x);
1323 return security_ops->xfrm_policy_lookup(ctx, fl_secid, dir);
1326 int security_xfrm_state_pol_flow_match(
struct xfrm_state *x,
1328 const struct flowi *fl)
1330 return security_ops->xfrm_state_pol_flow_match(x, xp, fl);
1333 int security_xfrm_decode_session(
struct sk_buff *skb,
u32 *secid)
1335 return security_ops->xfrm_decode_session(skb, secid, 1);
1338 void security_skb_classify_flow(
struct sk_buff *skb,
struct flowi *fl)
1340 int rc = security_ops->xfrm_decode_session(skb, &fl->flowi_secid, 0);
1351 unsigned long flags)
1353 return security_ops->key_alloc(key, cred, flags);
1356 void security_key_free(
struct key *key)
1358 security_ops->key_free(key);
1361 int security_key_permission(key_ref_t key_ref,
1362 const struct cred *cred, key_perm_t
perm)
1364 return security_ops->key_permission(key_ref, cred, perm);
1367 int security_key_getsecurity(
struct key *key,
char **
_buffer)
1369 return security_ops->key_getsecurity(key, _buffer);
1376 int security_audit_rule_init(
u32 field,
u32 op,
char *rulestr,
void **lsmrule)
1378 return security_ops->audit_rule_init(field, op, rulestr, lsmrule);
1381 int security_audit_rule_known(
struct audit_krule *krule)
1383 return security_ops->audit_rule_known(krule);
1386 void security_audit_rule_free(
void *lsmrule)
1388 security_ops->audit_rule_free(lsmrule);
1391 int security_audit_rule_match(
u32 secid,
u32 field,
u32 op,
void *lsmrule,
1394 return security_ops->audit_rule_match(secid, field, op, lsmrule, actx);