blob: 3e0cfdebee456082ac46affb366d9a83ea01f46f [file] [log] [blame]
John Johansenb5e95b42010-07-29 14:48:07 -07001/*
2 * AppArmor security module
3 *
4 * This file contains AppArmor LSM hooks.
5 *
6 * Copyright (C) 1998-2008 Novell/SUSE
7 * Copyright 2009-2010 Canonical Ltd.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation, version 2 of the
12 * License.
13 */
14
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -070015#include <linux/lsm_hooks.h>
John Johansenb5e95b42010-07-29 14:48:07 -070016#include <linux/moduleparam.h>
17#include <linux/mm.h>
18#include <linux/mman.h>
19#include <linux/mount.h>
20#include <linux/namei.h>
21#include <linux/ptrace.h>
22#include <linux/ctype.h>
23#include <linux/sysctl.h>
24#include <linux/audit.h>
Serge E. Hallyn34867402011-03-23 16:43:17 -070025#include <linux/user_namespace.h>
Matthew Garrettab9f2112018-05-24 13:27:47 -070026#include <linux/netfilter_ipv4.h>
27#include <linux/netfilter_ipv6.h>
Chris Coulson63c16c32019-01-23 19:17:09 +000028#include <linux/zlib.h>
John Johansenb5e95b42010-07-29 14:48:07 -070029#include <net/sock.h>
David Howellse262e32d2018-11-01 23:07:23 +000030#include <uapi/linux/mount.h>
John Johansenb5e95b42010-07-29 14:48:07 -070031
32#include "include/apparmor.h"
33#include "include/apparmorfs.h"
34#include "include/audit.h"
35#include "include/capability.h"
John Johansend8889d42017-10-11 01:04:48 -070036#include "include/cred.h"
John Johansenb5e95b42010-07-29 14:48:07 -070037#include "include/file.h"
38#include "include/ipc.h"
John Johansen56974a62017-07-18 23:18:33 -070039#include "include/net.h"
John Johansenb5e95b42010-07-29 14:48:07 -070040#include "include/path.h"
John Johansen637f6882017-06-09 08:14:28 -070041#include "include/label.h"
John Johansenb5e95b42010-07-29 14:48:07 -070042#include "include/policy.h"
John Johansencff281f2017-01-16 00:42:15 -080043#include "include/policy_ns.h"
John Johansenb5e95b42010-07-29 14:48:07 -070044#include "include/procattr.h"
John Johansen2ea3ffb2017-07-18 23:04:47 -070045#include "include/mount.h"
John Johansenc0929212017-07-31 17:36:45 -070046#include "include/secid.h"
John Johansenb5e95b42010-07-29 14:48:07 -070047
48/* Flag indicating whether initialization completed */
John Johansen545de8f2017-04-06 06:55:23 -070049int apparmor_initialized;
John Johansenb5e95b42010-07-29 14:48:07 -070050
Sebastian Andrzej Siewiordf323332019-05-03 16:12:21 +020051union aa_buffer {
52 struct list_head list;
53 char buffer[1];
54};
John Johansend4669f02017-01-16 00:43:10 -080055
Sebastian Andrzej Siewiordf323332019-05-03 16:12:21 +020056static LIST_HEAD(aa_global_buffers);
57static DEFINE_SPINLOCK(aa_buffers_lock);
John Johansend4669f02017-01-16 00:43:10 -080058
John Johansenb5e95b42010-07-29 14:48:07 -070059/*
60 * LSM hook functions
61 */
62
63/*
John Johansend9087c42017-01-27 03:53:53 -080064 * put the associated labels
John Johansenb5e95b42010-07-29 14:48:07 -070065 */
66static void apparmor_cred_free(struct cred *cred)
67{
John Johansend9087c42017-01-27 03:53:53 -080068 aa_put_label(cred_label(cred));
Casey Schaufler69b5a442018-09-21 17:17:59 -070069 set_cred_label(cred, NULL);
John Johansenb5e95b42010-07-29 14:48:07 -070070}
71
72/*
73 * allocate the apparmor part of blank credentials
74 */
75static int apparmor_cred_alloc_blank(struct cred *cred, gfp_t gfp)
76{
Casey Schaufler69b5a442018-09-21 17:17:59 -070077 set_cred_label(cred, NULL);
John Johansenb5e95b42010-07-29 14:48:07 -070078 return 0;
79}
80
81/*
John Johansend9087c42017-01-27 03:53:53 -080082 * prepare new cred label for modification by prepare_cred block
John Johansenb5e95b42010-07-29 14:48:07 -070083 */
84static int apparmor_cred_prepare(struct cred *new, const struct cred *old,
85 gfp_t gfp)
86{
Casey Schaufler69b5a442018-09-21 17:17:59 -070087 set_cred_label(new, aa_get_newest_label(cred_label(old)));
John Johansenb5e95b42010-07-29 14:48:07 -070088 return 0;
89}
90
91/*
92 * transfer the apparmor data to a blank set of creds
93 */
94static void apparmor_cred_transfer(struct cred *new, const struct cred *old)
95{
Casey Schaufler69b5a442018-09-21 17:17:59 -070096 set_cred_label(new, aa_get_newest_label(cred_label(old)));
John Johansenb5e95b42010-07-29 14:48:07 -070097}
John Johansenb5e95b42010-07-29 14:48:07 -070098
John Johansen3b529a72017-01-20 01:59:25 -080099static void apparmor_task_free(struct task_struct *task)
100{
101
102 aa_free_task_ctx(task_ctx(task));
John Johansen3b529a72017-01-20 01:59:25 -0800103}
104
105static int apparmor_task_alloc(struct task_struct *task,
106 unsigned long clone_flags)
107{
Casey Schauflerf4ad8f22018-09-21 17:19:37 -0700108 struct aa_task_ctx *new = task_ctx(task);
John Johansen3b529a72017-01-20 01:59:25 -0800109
John Johansende62de52017-10-08 00:43:02 -0700110 aa_dup_task_ctx(new, task_ctx(current));
John Johansen3b529a72017-01-20 01:59:25 -0800111
112 return 0;
John Johansenb5e95b42010-07-29 14:48:07 -0700113}
114
115static int apparmor_ptrace_access_check(struct task_struct *child,
116 unsigned int mode)
117{
John Johansenb2d09ae2017-06-09 14:22:14 -0700118 struct aa_label *tracer, *tracee;
119 int error;
120
Jann Horn1f8266f2018-09-13 18:12:09 +0200121 tracer = __begin_current_label_crit_section();
John Johansenb2d09ae2017-06-09 14:22:14 -0700122 tracee = aa_get_task_label(child);
123 error = aa_may_ptrace(tracer, tracee,
John Johansen338d0be2018-06-07 00:45:30 -0700124 (mode & PTRACE_MODE_READ) ? AA_PTRACE_READ
125 : AA_PTRACE_TRACE);
John Johansenb2d09ae2017-06-09 14:22:14 -0700126 aa_put_label(tracee);
Jann Horn1f8266f2018-09-13 18:12:09 +0200127 __end_current_label_crit_section(tracer);
John Johansenb2d09ae2017-06-09 14:22:14 -0700128
129 return error;
John Johansenb5e95b42010-07-29 14:48:07 -0700130}
131
132static int apparmor_ptrace_traceme(struct task_struct *parent)
133{
John Johansenb2d09ae2017-06-09 14:22:14 -0700134 struct aa_label *tracer, *tracee;
135 int error;
136
Jann Hornca3fde52018-09-29 03:49:26 +0200137 tracee = __begin_current_label_crit_section();
John Johansenb2d09ae2017-06-09 14:22:14 -0700138 tracer = aa_get_task_label(parent);
139 error = aa_may_ptrace(tracer, tracee, AA_PTRACE_TRACE);
140 aa_put_label(tracer);
Jann Hornca3fde52018-09-29 03:49:26 +0200141 __end_current_label_crit_section(tracee);
John Johansenb2d09ae2017-06-09 14:22:14 -0700142
143 return error;
John Johansenb5e95b42010-07-29 14:48:07 -0700144}
145
146/* Derived from security/commoncap.c:cap_capget */
147static int apparmor_capget(struct task_struct *target, kernel_cap_t *effective,
148 kernel_cap_t *inheritable, kernel_cap_t *permitted)
149{
John Johansen637f6882017-06-09 08:14:28 -0700150 struct aa_label *label;
John Johansenb5e95b42010-07-29 14:48:07 -0700151 const struct cred *cred;
152
153 rcu_read_lock();
154 cred = __task_cred(target);
John Johansen637f6882017-06-09 08:14:28 -0700155 label = aa_get_newest_cred_label(cred);
John Johansenc70c86c2017-06-09 14:07:02 -0700156
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -0700157 /*
158 * cap_capget is stacked ahead of this and will
159 * initialize effective and permitted.
160 */
John Johansenc70c86c2017-06-09 14:07:02 -0700161 if (!unconfined(label)) {
162 struct aa_profile *profile;
163 struct label_it i;
164
165 label_for_each_confined(i, label, profile) {
166 if (COMPLAIN_MODE(profile))
167 continue;
168 *effective = cap_intersect(*effective,
169 profile->caps.allow);
170 *permitted = cap_intersect(*permitted,
171 profile->caps.allow);
172 }
John Johansenb5e95b42010-07-29 14:48:07 -0700173 }
174 rcu_read_unlock();
John Johansen637f6882017-06-09 08:14:28 -0700175 aa_put_label(label);
John Johansenb5e95b42010-07-29 14:48:07 -0700176
177 return 0;
178}
179
Eric Paris6a9de492012-01-03 12:25:14 -0500180static int apparmor_capable(const struct cred *cred, struct user_namespace *ns,
Micah Mortonc1a85a02019-01-07 16:10:53 -0800181 int cap, unsigned int opts)
John Johansenb5e95b42010-07-29 14:48:07 -0700182{
John Johansen637f6882017-06-09 08:14:28 -0700183 struct aa_label *label;
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -0700184 int error = 0;
185
John Johansen637f6882017-06-09 08:14:28 -0700186 label = aa_get_newest_cred_label(cred);
187 if (!unconfined(label))
Micah Mortonc1a85a02019-01-07 16:10:53 -0800188 error = aa_capable(label, cap, opts);
John Johansen637f6882017-06-09 08:14:28 -0700189 aa_put_label(label);
John Johansencf797c02017-06-09 02:08:28 -0700190
John Johansenb5e95b42010-07-29 14:48:07 -0700191 return error;
192}
193
194/**
195 * common_perm - basic common permission check wrapper fn for paths
196 * @op: operation being checked
197 * @path: path to check permission of (NOT NULL)
198 * @mask: requested permissions mask
199 * @cond: conditional info for the permission request (NOT NULL)
200 *
201 * Returns: %0 else error code if error or permission denied
202 */
John Johansen47f6e5c2017-01-16 00:43:01 -0800203static int common_perm(const char *op, const struct path *path, u32 mask,
John Johansenb5e95b42010-07-29 14:48:07 -0700204 struct path_cond *cond)
205{
John Johansen637f6882017-06-09 08:14:28 -0700206 struct aa_label *label;
John Johansenb5e95b42010-07-29 14:48:07 -0700207 int error = 0;
208
John Johansen637f6882017-06-09 08:14:28 -0700209 label = __begin_current_label_crit_section();
210 if (!unconfined(label))
John Johansenaebd8732017-06-09 16:02:25 -0700211 error = aa_path_perm(op, label, path, 0, mask, cond);
John Johansen637f6882017-06-09 08:14:28 -0700212 __end_current_label_crit_section(label);
John Johansenb5e95b42010-07-29 14:48:07 -0700213
214 return error;
215}
216
217/**
John Johansen31f75bf2017-01-16 00:43:07 -0800218 * common_perm_cond - common permission wrapper around inode cond
219 * @op: operation being checked
220 * @path: location to check (NOT NULL)
221 * @mask: requested permissions mask
222 *
223 * Returns: %0 else error code if error or permission denied
224 */
225static int common_perm_cond(const char *op, const struct path *path, u32 mask)
226{
227 struct path_cond cond = { d_backing_inode(path->dentry)->i_uid,
228 d_backing_inode(path->dentry)->i_mode
229 };
230
231 if (!path_mediated_fs(path->dentry))
232 return 0;
233
234 return common_perm(op, path, mask, &cond);
235}
236
237/**
John Johansenb5e95b42010-07-29 14:48:07 -0700238 * common_perm_dir_dentry - common permission wrapper when path is dir, dentry
239 * @op: operation being checked
240 * @dir: directory of the dentry (NOT NULL)
241 * @dentry: dentry to check (NOT NULL)
242 * @mask: requested permissions mask
243 * @cond: conditional info for the permission request (NOT NULL)
244 *
245 * Returns: %0 else error code if error or permission denied
246 */
John Johansen47f6e5c2017-01-16 00:43:01 -0800247static int common_perm_dir_dentry(const char *op, const struct path *dir,
John Johansenb5e95b42010-07-29 14:48:07 -0700248 struct dentry *dentry, u32 mask,
249 struct path_cond *cond)
250{
Kees Cook8486adf2016-12-16 17:04:13 -0800251 struct path path = { .mnt = dir->mnt, .dentry = dentry };
John Johansenb5e95b42010-07-29 14:48:07 -0700252
253 return common_perm(op, &path, mask, cond);
254}
255
256/**
John Johansenb5e95b42010-07-29 14:48:07 -0700257 * common_perm_rm - common permission wrapper for operations doing rm
258 * @op: operation being checked
259 * @dir: directory that the dentry is in (NOT NULL)
260 * @dentry: dentry being rm'd (NOT NULL)
261 * @mask: requested permission mask
262 *
263 * Returns: %0 else error code if error or permission denied
264 */
John Johansen47f6e5c2017-01-16 00:43:01 -0800265static int common_perm_rm(const char *op, const struct path *dir,
John Johansenb5e95b42010-07-29 14:48:07 -0700266 struct dentry *dentry, u32 mask)
267{
David Howellsc6f493d2015-03-17 22:26:22 +0000268 struct inode *inode = d_backing_inode(dentry);
John Johansenb5e95b42010-07-29 14:48:07 -0700269 struct path_cond cond = { };
270
John Johansenefeee832017-01-16 00:42:28 -0800271 if (!inode || !path_mediated_fs(dentry))
John Johansenb5e95b42010-07-29 14:48:07 -0700272 return 0;
273
274 cond.uid = inode->i_uid;
275 cond.mode = inode->i_mode;
276
277 return common_perm_dir_dentry(op, dir, dentry, mask, &cond);
278}
279
280/**
281 * common_perm_create - common permission wrapper for operations doing create
282 * @op: operation being checked
283 * @dir: directory that dentry will be created in (NOT NULL)
284 * @dentry: dentry to create (NOT NULL)
285 * @mask: request permission mask
286 * @mode: created file mode
287 *
288 * Returns: %0 else error code if error or permission denied
289 */
John Johansen47f6e5c2017-01-16 00:43:01 -0800290static int common_perm_create(const char *op, const struct path *dir,
Al Virod6b49f72016-03-25 15:10:04 -0400291 struct dentry *dentry, u32 mask, umode_t mode)
John Johansenb5e95b42010-07-29 14:48:07 -0700292{
293 struct path_cond cond = { current_fsuid(), mode };
294
John Johansenefeee832017-01-16 00:42:28 -0800295 if (!path_mediated_fs(dir->dentry))
John Johansenb5e95b42010-07-29 14:48:07 -0700296 return 0;
297
298 return common_perm_dir_dentry(op, dir, dentry, mask, &cond);
299}
300
Al Viro989f74e2016-03-25 15:13:39 -0400301static int apparmor_path_unlink(const struct path *dir, struct dentry *dentry)
John Johansenb5e95b42010-07-29 14:48:07 -0700302{
303 return common_perm_rm(OP_UNLINK, dir, dentry, AA_MAY_DELETE);
304}
305
Al Virod3607752016-03-25 15:21:09 -0400306static int apparmor_path_mkdir(const struct path *dir, struct dentry *dentry,
Al Viro4572bef2011-11-21 14:56:21 -0500307 umode_t mode)
John Johansenb5e95b42010-07-29 14:48:07 -0700308{
309 return common_perm_create(OP_MKDIR, dir, dentry, AA_MAY_CREATE,
310 S_IFDIR);
311}
312
Al Viro989f74e2016-03-25 15:13:39 -0400313static int apparmor_path_rmdir(const struct path *dir, struct dentry *dentry)
John Johansenb5e95b42010-07-29 14:48:07 -0700314{
315 return common_perm_rm(OP_RMDIR, dir, dentry, AA_MAY_DELETE);
316}
317
Al Virod3607752016-03-25 15:21:09 -0400318static int apparmor_path_mknod(const struct path *dir, struct dentry *dentry,
Al Viro04fc66e2011-11-21 14:58:38 -0500319 umode_t mode, unsigned int dev)
John Johansenb5e95b42010-07-29 14:48:07 -0700320{
321 return common_perm_create(OP_MKNOD, dir, dentry, AA_MAY_CREATE, mode);
322}
323
Al Viro81f4c502016-03-25 14:22:01 -0400324static int apparmor_path_truncate(const struct path *path)
John Johansenb5e95b42010-07-29 14:48:07 -0700325{
John Johansene53cfe62017-05-26 15:07:22 -0700326 return common_perm_cond(OP_TRUNC, path, MAY_WRITE | AA_MAY_SETATTR);
John Johansenb5e95b42010-07-29 14:48:07 -0700327}
328
Al Virod3607752016-03-25 15:21:09 -0400329static int apparmor_path_symlink(const struct path *dir, struct dentry *dentry,
John Johansenb5e95b42010-07-29 14:48:07 -0700330 const char *old_name)
331{
332 return common_perm_create(OP_SYMLINK, dir, dentry, AA_MAY_CREATE,
333 S_IFLNK);
334}
335
Al Viro3ccee462016-03-25 15:27:45 -0400336static int apparmor_path_link(struct dentry *old_dentry, const struct path *new_dir,
John Johansenb5e95b42010-07-29 14:48:07 -0700337 struct dentry *new_dentry)
338{
John Johansen637f6882017-06-09 08:14:28 -0700339 struct aa_label *label;
John Johansenb5e95b42010-07-29 14:48:07 -0700340 int error = 0;
341
John Johansenefeee832017-01-16 00:42:28 -0800342 if (!path_mediated_fs(old_dentry))
John Johansenb5e95b42010-07-29 14:48:07 -0700343 return 0;
344
John Johansen637f6882017-06-09 08:14:28 -0700345 label = begin_current_label_crit_section();
346 if (!unconfined(label))
John Johansen80143702017-06-09 16:06:21 -0700347 error = aa_path_link(label, old_dentry, new_dir, new_dentry);
John Johansen637f6882017-06-09 08:14:28 -0700348 end_current_label_crit_section(label);
John Johansencf797c02017-06-09 02:08:28 -0700349
John Johansenb5e95b42010-07-29 14:48:07 -0700350 return error;
351}
352
Al Viro3ccee462016-03-25 15:27:45 -0400353static int apparmor_path_rename(const struct path *old_dir, struct dentry *old_dentry,
354 const struct path *new_dir, struct dentry *new_dentry)
John Johansenb5e95b42010-07-29 14:48:07 -0700355{
John Johansen637f6882017-06-09 08:14:28 -0700356 struct aa_label *label;
John Johansenb5e95b42010-07-29 14:48:07 -0700357 int error = 0;
358
John Johansenefeee832017-01-16 00:42:28 -0800359 if (!path_mediated_fs(old_dentry))
John Johansenb5e95b42010-07-29 14:48:07 -0700360 return 0;
361
John Johansen637f6882017-06-09 08:14:28 -0700362 label = begin_current_label_crit_section();
363 if (!unconfined(label)) {
Kees Cook8486adf2016-12-16 17:04:13 -0800364 struct path old_path = { .mnt = old_dir->mnt,
365 .dentry = old_dentry };
366 struct path new_path = { .mnt = new_dir->mnt,
367 .dentry = new_dentry };
David Howellsc6f493d2015-03-17 22:26:22 +0000368 struct path_cond cond = { d_backing_inode(old_dentry)->i_uid,
369 d_backing_inode(old_dentry)->i_mode
John Johansenb5e95b42010-07-29 14:48:07 -0700370 };
371
John Johansenaebd8732017-06-09 16:02:25 -0700372 error = aa_path_perm(OP_RENAME_SRC, label, &old_path, 0,
John Johansene53cfe62017-05-26 15:07:22 -0700373 MAY_READ | AA_MAY_GETATTR | MAY_WRITE |
374 AA_MAY_SETATTR | AA_MAY_DELETE,
John Johansenb5e95b42010-07-29 14:48:07 -0700375 &cond);
376 if (!error)
John Johansenaebd8732017-06-09 16:02:25 -0700377 error = aa_path_perm(OP_RENAME_DEST, label, &new_path,
John Johansene53cfe62017-05-26 15:07:22 -0700378 0, MAY_WRITE | AA_MAY_SETATTR |
John Johansenb5e95b42010-07-29 14:48:07 -0700379 AA_MAY_CREATE, &cond);
380
381 }
John Johansen637f6882017-06-09 08:14:28 -0700382 end_current_label_crit_section(label);
John Johansencf797c02017-06-09 02:08:28 -0700383
John Johansenb5e95b42010-07-29 14:48:07 -0700384 return error;
385}
386
Al Virobe01f9f2016-03-25 14:56:23 -0400387static int apparmor_path_chmod(const struct path *path, umode_t mode)
John Johansenb5e95b42010-07-29 14:48:07 -0700388{
John Johansen31f75bf2017-01-16 00:43:07 -0800389 return common_perm_cond(OP_CHMOD, path, AA_MAY_CHMOD);
John Johansenb5e95b42010-07-29 14:48:07 -0700390}
391
Al Viro7fd25da2016-03-25 14:44:41 -0400392static int apparmor_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
John Johansenb5e95b42010-07-29 14:48:07 -0700393{
John Johansen31f75bf2017-01-16 00:43:07 -0800394 return common_perm_cond(OP_CHOWN, path, AA_MAY_CHOWN);
John Johansenb5e95b42010-07-29 14:48:07 -0700395}
396
Al Viro3f7036a2015-03-08 19:28:30 -0400397static int apparmor_inode_getattr(const struct path *path)
John Johansenb5e95b42010-07-29 14:48:07 -0700398{
John Johansene53cfe62017-05-26 15:07:22 -0700399 return common_perm_cond(OP_GETATTR, path, AA_MAY_GETATTR);
John Johansenb5e95b42010-07-29 14:48:07 -0700400}
401
Al Viro94817692018-07-10 14:13:18 -0400402static int apparmor_file_open(struct file *file)
John Johansenb5e95b42010-07-29 14:48:07 -0700403{
John Johansen637f6882017-06-09 08:14:28 -0700404 struct aa_file_ctx *fctx = file_ctx(file);
405 struct aa_label *label;
John Johansenb5e95b42010-07-29 14:48:07 -0700406 int error = 0;
407
John Johansenefeee832017-01-16 00:42:28 -0800408 if (!path_mediated_fs(file->f_path.dentry))
John Johansenb5e95b42010-07-29 14:48:07 -0700409 return 0;
410
411 /* If in exec, permission is handled by bprm hooks.
412 * Cache permissions granted by the previous exec check, with
413 * implicit read and executable mmap which are required to
414 * actually execute the image.
415 */
416 if (current->in_execve) {
John Johansen55a26eb2017-01-16 00:43:00 -0800417 fctx->allow = MAY_EXEC | MAY_READ | AA_EXEC_MMAP;
John Johansenb5e95b42010-07-29 14:48:07 -0700418 return 0;
419 }
420
Al Viro94817692018-07-10 14:13:18 -0400421 label = aa_get_newest_cred_label(file->f_cred);
John Johansen637f6882017-06-09 08:14:28 -0700422 if (!unconfined(label)) {
Al Viro496ad9a2013-01-23 17:07:38 -0500423 struct inode *inode = file_inode(file);
John Johansenb5e95b42010-07-29 14:48:07 -0700424 struct path_cond cond = { inode->i_uid, inode->i_mode };
425
John Johansenaebd8732017-06-09 16:02:25 -0700426 error = aa_path_perm(OP_OPEN, label, &file->f_path, 0,
John Johansenb5e95b42010-07-29 14:48:07 -0700427 aa_map_file_to_perms(file), &cond);
428 /* todo cache full allowed permissions set and state */
John Johansen55a26eb2017-01-16 00:43:00 -0800429 fctx->allow = aa_map_file_to_perms(file);
John Johansenb5e95b42010-07-29 14:48:07 -0700430 }
John Johansen637f6882017-06-09 08:14:28 -0700431 aa_put_label(label);
John Johansenb5e95b42010-07-29 14:48:07 -0700432
433 return error;
434}
435
436static int apparmor_file_alloc_security(struct file *file)
437{
Casey Schaufler33bf60c2018-11-12 12:02:49 -0800438 struct aa_file_ctx *ctx = file_ctx(file);
John Johansen637f6882017-06-09 08:14:28 -0700439 struct aa_label *label = begin_current_label_crit_section();
John Johansenb5e95b42010-07-29 14:48:07 -0700440
Casey Schaufler33bf60c2018-11-12 12:02:49 -0800441 spin_lock_init(&ctx->lock);
442 rcu_assign_pointer(ctx->label, aa_get_label(label));
443 end_current_label_crit_section(label);
444 return 0;
John Johansenb5e95b42010-07-29 14:48:07 -0700445}
446
447static void apparmor_file_free_security(struct file *file)
448{
Casey Schaufler33bf60c2018-11-12 12:02:49 -0800449 struct aa_file_ctx *ctx = file_ctx(file);
450
451 if (ctx)
452 aa_put_label(rcu_access_pointer(ctx->label));
John Johansenb5e95b42010-07-29 14:48:07 -0700453}
454
John Johansen47f6e5c2017-01-16 00:43:01 -0800455static int common_file_perm(const char *op, struct file *file, u32 mask)
John Johansenb5e95b42010-07-29 14:48:07 -0700456{
John Johansen190a9512017-06-09 14:59:51 -0700457 struct aa_label *label;
John Johansenb5e95b42010-07-29 14:48:07 -0700458 int error = 0;
459
John Johansen192ca6b2017-06-09 11:58:42 -0700460 /* don't reaudit files closed during inheritance */
461 if (file->f_path.dentry == aa_null.dentry)
462 return -EACCES;
463
John Johansen637f6882017-06-09 08:14:28 -0700464 label = __begin_current_label_crit_section();
John Johansen190a9512017-06-09 14:59:51 -0700465 error = aa_file_perm(op, label, file, mask);
John Johansen637f6882017-06-09 08:14:28 -0700466 __end_current_label_crit_section(label);
John Johansenb5e95b42010-07-29 14:48:07 -0700467
468 return error;
469}
470
John Johansen064dc942017-06-09 17:15:56 -0700471static int apparmor_file_receive(struct file *file)
472{
473 return common_file_perm(OP_FRECEIVE, file, aa_map_file_to_perms(file));
474}
475
John Johansenb5e95b42010-07-29 14:48:07 -0700476static int apparmor_file_permission(struct file *file, int mask)
477{
478 return common_file_perm(OP_FPERM, file, mask);
479}
480
481static int apparmor_file_lock(struct file *file, unsigned int cmd)
482{
483 u32 mask = AA_MAY_LOCK;
484
485 if (cmd == F_WRLCK)
486 mask |= MAY_WRITE;
487
488 return common_file_perm(OP_FLOCK, file, mask);
489}
490
John Johansen47f6e5c2017-01-16 00:43:01 -0800491static int common_mmap(const char *op, struct file *file, unsigned long prot,
John Johansenb5e95b42010-07-29 14:48:07 -0700492 unsigned long flags)
493{
John Johansenb5e95b42010-07-29 14:48:07 -0700494 int mask = 0;
495
John Johansen637f6882017-06-09 08:14:28 -0700496 if (!file || !file_ctx(file))
John Johansenb5e95b42010-07-29 14:48:07 -0700497 return 0;
498
499 if (prot & PROT_READ)
500 mask |= MAY_READ;
501 /*
502 * Private mappings don't require write perms since they don't
503 * write back to the files
504 */
505 if ((prot & PROT_WRITE) && !(flags & MAP_PRIVATE))
506 mask |= MAY_WRITE;
507 if (prot & PROT_EXEC)
508 mask |= AA_EXEC_MMAP;
509
John Johansenb5e95b42010-07-29 14:48:07 -0700510 return common_file_perm(op, file, mask);
511}
512
Al Viroe5467852012-05-30 13:30:51 -0400513static int apparmor_mmap_file(struct file *file, unsigned long reqprot,
514 unsigned long prot, unsigned long flags)
John Johansenb5e95b42010-07-29 14:48:07 -0700515{
John Johansenb5e95b42010-07-29 14:48:07 -0700516 return common_mmap(OP_FMMAP, file, prot, flags);
517}
518
519static int apparmor_file_mprotect(struct vm_area_struct *vma,
520 unsigned long reqprot, unsigned long prot)
521{
522 return common_mmap(OP_FMPROT, vma->vm_file, prot,
523 !(vma->vm_flags & VM_SHARED) ? MAP_PRIVATE : 0);
524}
525
John Johansen2ea3ffb2017-07-18 23:04:47 -0700526static int apparmor_sb_mount(const char *dev_name, const struct path *path,
527 const char *type, unsigned long flags, void *data)
528{
529 struct aa_label *label;
530 int error = 0;
531
532 /* Discard magic */
533 if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
534 flags &= ~MS_MGC_MSK;
535
536 flags &= ~AA_MS_IGNORE_MASK;
537
538 label = __begin_current_label_crit_section();
539 if (!unconfined(label)) {
540 if (flags & MS_REMOUNT)
541 error = aa_remount(label, path, flags, data);
542 else if (flags & MS_BIND)
543 error = aa_bind_mount(label, path, dev_name, flags);
544 else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE |
545 MS_UNBINDABLE))
546 error = aa_mount_change_type(label, path, flags);
547 else if (flags & MS_MOVE)
548 error = aa_move_mount(label, path, dev_name);
549 else
550 error = aa_new_mount(label, dev_name, path, type,
551 flags, data);
552 }
553 __end_current_label_crit_section(label);
554
555 return error;
556}
557
558static int apparmor_sb_umount(struct vfsmount *mnt, int flags)
559{
560 struct aa_label *label;
561 int error = 0;
562
563 label = __begin_current_label_crit_section();
564 if (!unconfined(label))
565 error = aa_umount(label, mnt, flags);
566 __end_current_label_crit_section(label);
567
568 return error;
569}
570
571static int apparmor_sb_pivotroot(const struct path *old_path,
572 const struct path *new_path)
573{
574 struct aa_label *label;
575 int error = 0;
576
577 label = aa_get_current_label();
578 if (!unconfined(label))
579 error = aa_pivotroot(label, old_path, new_path);
580 aa_put_label(label);
581
582 return error;
583}
584
John Johansenb5e95b42010-07-29 14:48:07 -0700585static int apparmor_getprocattr(struct task_struct *task, char *name,
586 char **value)
587{
588 int error = -ENOENT;
John Johansenb5e95b42010-07-29 14:48:07 -0700589 /* released below */
590 const struct cred *cred = get_task_cred(task);
John Johansende62de52017-10-08 00:43:02 -0700591 struct aa_task_ctx *ctx = task_ctx(current);
John Johansen637f6882017-06-09 08:14:28 -0700592 struct aa_label *label = NULL;
John Johansenb5e95b42010-07-29 14:48:07 -0700593
594 if (strcmp(name, "current") == 0)
John Johansend9087c42017-01-27 03:53:53 -0800595 label = aa_get_newest_label(cred_label(cred));
John Johansen55a26eb2017-01-16 00:43:00 -0800596 else if (strcmp(name, "prev") == 0 && ctx->previous)
John Johansen637f6882017-06-09 08:14:28 -0700597 label = aa_get_newest_label(ctx->previous);
John Johansen55a26eb2017-01-16 00:43:00 -0800598 else if (strcmp(name, "exec") == 0 && ctx->onexec)
John Johansen637f6882017-06-09 08:14:28 -0700599 label = aa_get_newest_label(ctx->onexec);
John Johansenb5e95b42010-07-29 14:48:07 -0700600 else
601 error = -EINVAL;
602
John Johansen637f6882017-06-09 08:14:28 -0700603 if (label)
John Johansen76a1d262017-06-09 12:47:17 -0700604 error = aa_getprocattr(label, value);
John Johansen77b071b2013-07-10 21:07:43 -0700605
John Johansen637f6882017-06-09 08:14:28 -0700606 aa_put_label(label);
John Johansenb5e95b42010-07-29 14:48:07 -0700607 put_cred(cred);
608
609 return error;
610}
611
Stephen Smalleyb21507e2017-01-09 10:07:31 -0500612static int apparmor_setprocattr(const char *name, void *value,
613 size_t size)
John Johansenb5e95b42010-07-29 14:48:07 -0700614{
Vegard Nossume89b8082016-07-07 13:41:11 -0700615 char *command, *largs = NULL, *args = value;
John Johansenb5e95b42010-07-29 14:48:07 -0700616 size_t arg_size;
617 int error;
John Johansenef88a7a2017-01-16 00:43:02 -0800618 DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, OP_SETPROCATTR);
John Johansenb5e95b42010-07-29 14:48:07 -0700619
620 if (size == 0)
621 return -EINVAL;
John Johansenb5e95b42010-07-29 14:48:07 -0700622
Vegard Nossume89b8082016-07-07 13:41:11 -0700623 /* AppArmor requires that the buffer must be null terminated atm */
624 if (args[size - 1] != '\0') {
625 /* null terminate */
626 largs = args = kmalloc(size + 1, GFP_KERNEL);
627 if (!args)
628 return -ENOMEM;
629 memcpy(args, value, size);
630 args[size] = '\0';
631 }
632
633 error = -EINVAL;
John Johansenb5e95b42010-07-29 14:48:07 -0700634 args = strim(args);
635 command = strsep(&args, " ");
636 if (!args)
Vegard Nossume89b8082016-07-07 13:41:11 -0700637 goto out;
John Johansenb5e95b42010-07-29 14:48:07 -0700638 args = skip_spaces(args);
639 if (!*args)
Vegard Nossume89b8082016-07-07 13:41:11 -0700640 goto out;
John Johansenb5e95b42010-07-29 14:48:07 -0700641
John Johansend4d03f72016-07-09 23:46:33 -0700642 arg_size = size - (args - (largs ? largs : (char *) value));
John Johansenb5e95b42010-07-29 14:48:07 -0700643 if (strcmp(name, "current") == 0) {
644 if (strcmp(command, "changehat") == 0) {
645 error = aa_setprocattr_changehat(args, arg_size,
John Johansendf8073c2017-06-09 11:36:48 -0700646 AA_CHANGE_NOFLAGS);
John Johansenb5e95b42010-07-29 14:48:07 -0700647 } else if (strcmp(command, "permhat") == 0) {
648 error = aa_setprocattr_changehat(args, arg_size,
John Johansendf8073c2017-06-09 11:36:48 -0700649 AA_CHANGE_TEST);
John Johansenb5e95b42010-07-29 14:48:07 -0700650 } else if (strcmp(command, "changeprofile") == 0) {
John Johansendf8073c2017-06-09 11:36:48 -0700651 error = aa_change_profile(args, AA_CHANGE_NOFLAGS);
John Johansenb5e95b42010-07-29 14:48:07 -0700652 } else if (strcmp(command, "permprofile") == 0) {
John Johansendf8073c2017-06-09 11:36:48 -0700653 error = aa_change_profile(args, AA_CHANGE_TEST);
John Johansen6c5fc8f2017-06-09 17:22:50 -0700654 } else if (strcmp(command, "stack") == 0) {
655 error = aa_change_profile(args, AA_CHANGE_STACK);
John Johansen3eea57c2013-02-27 03:44:40 -0800656 } else
657 goto fail;
John Johansenb5e95b42010-07-29 14:48:07 -0700658 } else if (strcmp(name, "exec") == 0) {
John Johansen3eea57c2013-02-27 03:44:40 -0800659 if (strcmp(command, "exec") == 0)
John Johansendf8073c2017-06-09 11:36:48 -0700660 error = aa_change_profile(args, AA_CHANGE_ONEXEC);
John Johansen6c5fc8f2017-06-09 17:22:50 -0700661 else if (strcmp(command, "stack") == 0)
662 error = aa_change_profile(args, (AA_CHANGE_ONEXEC |
663 AA_CHANGE_STACK));
John Johansen3eea57c2013-02-27 03:44:40 -0800664 else
665 goto fail;
666 } else
John Johansenb5e95b42010-07-29 14:48:07 -0700667 /* only support the "current" and "exec" process attributes */
Vegard Nossume89b8082016-07-07 13:41:11 -0700668 goto fail;
John Johansen3eea57c2013-02-27 03:44:40 -0800669
John Johansenb5e95b42010-07-29 14:48:07 -0700670 if (!error)
671 error = size;
Vegard Nossume89b8082016-07-07 13:41:11 -0700672out:
673 kfree(largs);
John Johansenb5e95b42010-07-29 14:48:07 -0700674 return error;
John Johansen3eea57c2013-02-27 03:44:40 -0800675
676fail:
John Johansen637f6882017-06-09 08:14:28 -0700677 aad(&sa)->label = begin_current_label_crit_section();
John Johansenef88a7a2017-01-16 00:43:02 -0800678 aad(&sa)->info = name;
679 aad(&sa)->error = error = -EINVAL;
John Johansen3eea57c2013-02-27 03:44:40 -0800680 aa_audit_msg(AUDIT_APPARMOR_DENIED, &sa, NULL);
John Johansen637f6882017-06-09 08:14:28 -0700681 end_current_label_crit_section(aad(&sa)->label);
Vegard Nossume89b8082016-07-07 13:41:11 -0700682 goto out;
John Johansenb5e95b42010-07-29 14:48:07 -0700683}
684
John Johansenfe864822017-06-09 05:27:50 -0700685/**
686 * apparmor_bprm_committing_creds - do task cleanup on committing new creds
687 * @bprm: binprm for the exec (NOT NULL)
688 */
689static void apparmor_bprm_committing_creds(struct linux_binprm *bprm)
690{
John Johansen637f6882017-06-09 08:14:28 -0700691 struct aa_label *label = aa_current_raw_label();
John Johansend9087c42017-01-27 03:53:53 -0800692 struct aa_label *new_label = cred_label(bprm->cred);
John Johansenfe864822017-06-09 05:27:50 -0700693
694 /* bail out if unconfined or not changing profile */
John Johansend9087c42017-01-27 03:53:53 -0800695 if ((new_label->proxy == label->proxy) ||
696 (unconfined(new_label)))
John Johansenfe864822017-06-09 05:27:50 -0700697 return;
698
John Johansen192ca6b2017-06-09 11:58:42 -0700699 aa_inherit_files(bprm->cred, current->files);
700
John Johansenfe864822017-06-09 05:27:50 -0700701 current->pdeath_signal = 0;
702
John Johansen637f6882017-06-09 08:14:28 -0700703 /* reset soft limits and set hard limits for the new label */
John Johansend9087c42017-01-27 03:53:53 -0800704 __aa_transition_rlimits(label, new_label);
John Johansenfe864822017-06-09 05:27:50 -0700705}
706
707/**
708 * apparmor_bprm_committed_cred - do cleanup after new creds committed
709 * @bprm: binprm for the exec (NOT NULL)
710 */
711static void apparmor_bprm_committed_creds(struct linux_binprm *bprm)
712{
John Johansen3b529a72017-01-20 01:59:25 -0800713 /* clear out temporary/transitional state from the context */
John Johansende62de52017-10-08 00:43:02 -0700714 aa_clear_task_ctx_trans(task_ctx(current));
John Johansen3b529a72017-01-20 01:59:25 -0800715
John Johansenfe864822017-06-09 05:27:50 -0700716 return;
717}
718
John Johansena7ae3642017-09-11 11:29:53 -0700719static void apparmor_task_getsecid(struct task_struct *p, u32 *secid)
720{
721 struct aa_label *label = aa_get_task_label(p);
722 *secid = label->secid;
723 aa_put_label(label);
724}
725
Jiri Slaby7cb4dc92010-08-11 11:28:02 +0200726static int apparmor_task_setrlimit(struct task_struct *task,
727 unsigned int resource, struct rlimit *new_rlim)
John Johansenb5e95b42010-07-29 14:48:07 -0700728{
John Johansen637f6882017-06-09 08:14:28 -0700729 struct aa_label *label = __begin_current_label_crit_section();
John Johansenb5e95b42010-07-29 14:48:07 -0700730 int error = 0;
731
John Johansen637f6882017-06-09 08:14:28 -0700732 if (!unconfined(label))
John Johansen86b92cb2017-06-09 14:15:20 -0700733 error = aa_task_setrlimit(label, task, resource, new_rlim);
John Johansen637f6882017-06-09 08:14:28 -0700734 __end_current_label_crit_section(label);
John Johansenb5e95b42010-07-29 14:48:07 -0700735
736 return error;
737}
738
Eric W. Biedermanae7795b2018-09-25 11:27:20 +0200739static int apparmor_task_kill(struct task_struct *target, struct kernel_siginfo *info,
Stephen Smalley6b4f3d02017-09-08 12:40:01 -0400740 int sig, const struct cred *cred)
John Johansencd1dbf72017-07-18 22:56:22 -0700741{
742 struct aa_label *cl, *tl;
743 int error;
744
Stephen Smalley6b4f3d02017-09-08 12:40:01 -0400745 if (cred) {
746 /*
747 * Dealing with USB IO specific behavior
John Johansencd1dbf72017-07-18 22:56:22 -0700748 */
Stephen Smalley6b4f3d02017-09-08 12:40:01 -0400749 cl = aa_get_newest_cred_label(cred);
750 tl = aa_get_task_label(target);
751 error = aa_may_signal(cl, tl, sig);
752 aa_put_label(cl);
753 aa_put_label(tl);
754 return error;
755 }
756
John Johansencd1dbf72017-07-18 22:56:22 -0700757 cl = __begin_current_label_crit_section();
758 tl = aa_get_task_label(target);
759 error = aa_may_signal(cl, tl, sig);
760 aa_put_label(tl);
761 __end_current_label_crit_section(cl);
762
763 return error;
764}
765
John Johansen56974a62017-07-18 23:18:33 -0700766/**
767 * apparmor_sk_alloc_security - allocate and attach the sk_security field
768 */
769static int apparmor_sk_alloc_security(struct sock *sk, int family, gfp_t flags)
770{
771 struct aa_sk_ctx *ctx;
772
773 ctx = kzalloc(sizeof(*ctx), flags);
774 if (!ctx)
775 return -ENOMEM;
776
777 SK_CTX(sk) = ctx;
778
779 return 0;
780}
781
782/**
783 * apparmor_sk_free_security - free the sk_security field
784 */
785static void apparmor_sk_free_security(struct sock *sk)
786{
787 struct aa_sk_ctx *ctx = SK_CTX(sk);
788
789 SK_CTX(sk) = NULL;
790 aa_put_label(ctx->label);
791 aa_put_label(ctx->peer);
792 kfree(ctx);
793}
794
795/**
796 * apparmor_clone_security - clone the sk_security field
797 */
798static void apparmor_sk_clone_security(const struct sock *sk,
799 struct sock *newsk)
800{
801 struct aa_sk_ctx *ctx = SK_CTX(sk);
802 struct aa_sk_ctx *new = SK_CTX(newsk);
803
804 new->label = aa_get_label(ctx->label);
805 new->peer = aa_get_label(ctx->peer);
806}
807
808/**
809 * apparmor_socket_create - check perms before creating a new socket
810 */
811static int apparmor_socket_create(int family, int type, int protocol, int kern)
812{
813 struct aa_label *label;
814 int error = 0;
815
816 AA_BUG(in_interrupt());
817
818 label = begin_current_label_crit_section();
819 if (!(kern || unconfined(label)))
820 error = af_select(family,
821 create_perm(label, family, type, protocol),
822 aa_af_perm(label, OP_CREATE, AA_MAY_CREATE,
823 family, type, protocol));
824 end_current_label_crit_section(label);
825
826 return error;
827}
828
829/**
830 * apparmor_socket_post_create - setup the per-socket security struct
831 *
832 * Note:
833 * - kernel sockets currently labeled unconfined but we may want to
834 * move to a special kernel label
835 * - socket may not have sk here if created with sock_create_lite or
836 * sock_alloc. These should be accept cases which will be handled in
837 * sock_graft.
838 */
839static int apparmor_socket_post_create(struct socket *sock, int family,
840 int type, int protocol, int kern)
841{
842 struct aa_label *label;
843
844 if (kern) {
845 struct aa_ns *ns = aa_get_current_ns();
846
847 label = aa_get_label(ns_unconfined(ns));
848 aa_put_ns(ns);
849 } else
850 label = aa_get_current_label();
851
852 if (sock->sk) {
853 struct aa_sk_ctx *ctx = SK_CTX(sock->sk);
854
855 aa_put_label(ctx->label);
856 ctx->label = aa_get_label(label);
857 }
858 aa_put_label(label);
859
860 return 0;
861}
862
863/**
864 * apparmor_socket_bind - check perms before bind addr to socket
865 */
866static int apparmor_socket_bind(struct socket *sock,
867 struct sockaddr *address, int addrlen)
868{
869 AA_BUG(!sock);
870 AA_BUG(!sock->sk);
871 AA_BUG(!address);
872 AA_BUG(in_interrupt());
873
874 return af_select(sock->sk->sk_family,
875 bind_perm(sock, address, addrlen),
876 aa_sk_perm(OP_BIND, AA_MAY_BIND, sock->sk));
877}
878
879/**
880 * apparmor_socket_connect - check perms before connecting @sock to @address
881 */
882static int apparmor_socket_connect(struct socket *sock,
883 struct sockaddr *address, int addrlen)
884{
885 AA_BUG(!sock);
886 AA_BUG(!sock->sk);
887 AA_BUG(!address);
888 AA_BUG(in_interrupt());
889
890 return af_select(sock->sk->sk_family,
891 connect_perm(sock, address, addrlen),
892 aa_sk_perm(OP_CONNECT, AA_MAY_CONNECT, sock->sk));
893}
894
895/**
896 * apparmor_socket_list - check perms before allowing listen
897 */
898static int apparmor_socket_listen(struct socket *sock, int backlog)
899{
900 AA_BUG(!sock);
901 AA_BUG(!sock->sk);
902 AA_BUG(in_interrupt());
903
904 return af_select(sock->sk->sk_family,
905 listen_perm(sock, backlog),
906 aa_sk_perm(OP_LISTEN, AA_MAY_LISTEN, sock->sk));
907}
908
909/**
910 * apparmor_socket_accept - check perms before accepting a new connection.
911 *
912 * Note: while @newsock is created and has some information, the accept
913 * has not been done.
914 */
915static int apparmor_socket_accept(struct socket *sock, struct socket *newsock)
916{
917 AA_BUG(!sock);
918 AA_BUG(!sock->sk);
919 AA_BUG(!newsock);
920 AA_BUG(in_interrupt());
921
922 return af_select(sock->sk->sk_family,
923 accept_perm(sock, newsock),
924 aa_sk_perm(OP_ACCEPT, AA_MAY_ACCEPT, sock->sk));
925}
926
927static int aa_sock_msg_perm(const char *op, u32 request, struct socket *sock,
928 struct msghdr *msg, int size)
929{
930 AA_BUG(!sock);
931 AA_BUG(!sock->sk);
932 AA_BUG(!msg);
933 AA_BUG(in_interrupt());
934
935 return af_select(sock->sk->sk_family,
936 msg_perm(op, request, sock, msg, size),
937 aa_sk_perm(op, request, sock->sk));
938}
939
940/**
941 * apparmor_socket_sendmsg - check perms before sending msg to another socket
942 */
943static int apparmor_socket_sendmsg(struct socket *sock,
944 struct msghdr *msg, int size)
945{
946 return aa_sock_msg_perm(OP_SENDMSG, AA_MAY_SEND, sock, msg, size);
947}
948
949/**
950 * apparmor_socket_recvmsg - check perms before receiving a message
951 */
952static int apparmor_socket_recvmsg(struct socket *sock,
953 struct msghdr *msg, int size, int flags)
954{
955 return aa_sock_msg_perm(OP_RECVMSG, AA_MAY_RECEIVE, sock, msg, size);
956}
957
958/* revaliation, get/set attr, shutdown */
959static int aa_sock_perm(const char *op, u32 request, struct socket *sock)
960{
961 AA_BUG(!sock);
962 AA_BUG(!sock->sk);
963 AA_BUG(in_interrupt());
964
965 return af_select(sock->sk->sk_family,
966 sock_perm(op, request, sock),
967 aa_sk_perm(op, request, sock->sk));
968}
969
970/**
971 * apparmor_socket_getsockname - check perms before getting the local address
972 */
973static int apparmor_socket_getsockname(struct socket *sock)
974{
975 return aa_sock_perm(OP_GETSOCKNAME, AA_MAY_GETATTR, sock);
976}
977
978/**
979 * apparmor_socket_getpeername - check perms before getting remote address
980 */
981static int apparmor_socket_getpeername(struct socket *sock)
982{
983 return aa_sock_perm(OP_GETPEERNAME, AA_MAY_GETATTR, sock);
984}
985
986/* revaliation, get/set attr, opt */
987static int aa_sock_opt_perm(const char *op, u32 request, struct socket *sock,
988 int level, int optname)
989{
990 AA_BUG(!sock);
991 AA_BUG(!sock->sk);
992 AA_BUG(in_interrupt());
993
994 return af_select(sock->sk->sk_family,
995 opt_perm(op, request, sock, level, optname),
996 aa_sk_perm(op, request, sock->sk));
997}
998
999/**
1000 * apparmor_getsockopt - check perms before getting socket options
1001 */
1002static int apparmor_socket_getsockopt(struct socket *sock, int level,
1003 int optname)
1004{
1005 return aa_sock_opt_perm(OP_GETSOCKOPT, AA_MAY_GETOPT, sock,
1006 level, optname);
1007}
1008
1009/**
1010 * apparmor_setsockopt - check perms before setting socket options
1011 */
1012static int apparmor_socket_setsockopt(struct socket *sock, int level,
1013 int optname)
1014{
1015 return aa_sock_opt_perm(OP_SETSOCKOPT, AA_MAY_SETOPT, sock,
1016 level, optname);
1017}
1018
1019/**
1020 * apparmor_socket_shutdown - check perms before shutting down @sock conn
1021 */
1022static int apparmor_socket_shutdown(struct socket *sock, int how)
1023{
1024 return aa_sock_perm(OP_SHUTDOWN, AA_MAY_SHUTDOWN, sock);
1025}
1026
Arnd Bergmanne1af4772018-10-05 18:11:47 +02001027#ifdef CONFIG_NETWORK_SECMARK
John Johansen56974a62017-07-18 23:18:33 -07001028/**
1029 * apparmor_socket_sock_recv_skb - check perms before associating skb to sk
1030 *
1031 * Note: can not sleep may be called with locks held
1032 *
1033 * dont want protocol specific in __skb_recv_datagram()
1034 * to deny an incoming connection socket_sock_rcv_skb()
1035 */
1036static int apparmor_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
1037{
Matthew Garrettab9f2112018-05-24 13:27:47 -07001038 struct aa_sk_ctx *ctx = SK_CTX(sk);
1039
1040 if (!skb->secmark)
1041 return 0;
1042
1043 return apparmor_secmark_check(ctx->label, OP_RECVMSG, AA_MAY_RECEIVE,
1044 skb->secmark, sk);
John Johansen56974a62017-07-18 23:18:33 -07001045}
Arnd Bergmanne1af4772018-10-05 18:11:47 +02001046#endif
John Johansen56974a62017-07-18 23:18:33 -07001047
1048
1049static struct aa_label *sk_peer_label(struct sock *sk)
1050{
1051 struct aa_sk_ctx *ctx = SK_CTX(sk);
1052
1053 if (ctx->peer)
1054 return ctx->peer;
1055
1056 return ERR_PTR(-ENOPROTOOPT);
1057}
1058
1059/**
1060 * apparmor_socket_getpeersec_stream - get security context of peer
1061 *
1062 * Note: for tcp only valid if using ipsec or cipso on lan
1063 */
1064static int apparmor_socket_getpeersec_stream(struct socket *sock,
1065 char __user *optval,
1066 int __user *optlen,
1067 unsigned int len)
1068{
1069 char *name;
1070 int slen, error = 0;
1071 struct aa_label *label;
1072 struct aa_label *peer;
1073
1074 label = begin_current_label_crit_section();
1075 peer = sk_peer_label(sock->sk);
1076 if (IS_ERR(peer)) {
1077 error = PTR_ERR(peer);
1078 goto done;
1079 }
1080 slen = aa_label_asxprint(&name, labels_ns(label), peer,
1081 FLAG_SHOW_MODE | FLAG_VIEW_SUBNS |
1082 FLAG_HIDDEN_UNCONFINED, GFP_KERNEL);
1083 /* don't include terminating \0 in slen, it breaks some apps */
1084 if (slen < 0) {
1085 error = -ENOMEM;
1086 } else {
1087 if (slen > len) {
1088 error = -ERANGE;
1089 } else if (copy_to_user(optval, name, slen)) {
1090 error = -EFAULT;
1091 goto out;
1092 }
1093 if (put_user(slen, optlen))
1094 error = -EFAULT;
1095out:
1096 kfree(name);
1097
1098 }
1099
1100done:
1101 end_current_label_crit_section(label);
1102
1103 return error;
1104}
1105
1106/**
1107 * apparmor_socket_getpeersec_dgram - get security label of packet
1108 * @sock: the peer socket
1109 * @skb: packet data
1110 * @secid: pointer to where to put the secid of the packet
1111 *
1112 * Sets the netlabel socket state on sk from parent
1113 */
1114static int apparmor_socket_getpeersec_dgram(struct socket *sock,
1115 struct sk_buff *skb, u32 *secid)
1116
1117{
1118 /* TODO: requires secid support */
1119 return -ENOPROTOOPT;
1120}
1121
1122/**
1123 * apparmor_sock_graft - Initialize newly created socket
1124 * @sk: child sock
1125 * @parent: parent socket
1126 *
1127 * Note: could set off of SOCK_CTX(parent) but need to track inode and we can
1128 * just set sk security information off of current creating process label
1129 * Labeling of sk for accept case - probably should be sock based
1130 * instead of task, because of the case where an implicitly labeled
1131 * socket is shared by different tasks.
1132 */
1133static void apparmor_sock_graft(struct sock *sk, struct socket *parent)
1134{
1135 struct aa_sk_ctx *ctx = SK_CTX(sk);
1136
1137 if (!ctx->label)
1138 ctx->label = aa_get_current_label();
1139}
1140
Arnd Bergmanne1af4772018-10-05 18:11:47 +02001141#ifdef CONFIG_NETWORK_SECMARK
Matthew Garrettab9f2112018-05-24 13:27:47 -07001142static int apparmor_inet_conn_request(struct sock *sk, struct sk_buff *skb,
1143 struct request_sock *req)
1144{
1145 struct aa_sk_ctx *ctx = SK_CTX(sk);
1146
1147 if (!skb->secmark)
1148 return 0;
1149
1150 return apparmor_secmark_check(ctx->label, OP_CONNECT, AA_MAY_CONNECT,
1151 skb->secmark, sk);
1152}
Arnd Bergmanne1af4772018-10-05 18:11:47 +02001153#endif
Matthew Garrettab9f2112018-05-24 13:27:47 -07001154
Casey Schauflerbbd36622018-11-12 09:30:56 -08001155/*
1156 * The cred blob is a pointer to, not an instance of, an aa_task_ctx.
1157 */
1158struct lsm_blob_sizes apparmor_blob_sizes __lsm_ro_after_init = {
1159 .lbs_cred = sizeof(struct aa_task_ctx *),
Casey Schaufler33bf60c2018-11-12 12:02:49 -08001160 .lbs_file = sizeof(struct aa_file_ctx),
Casey Schauflerf4ad8f22018-09-21 17:19:37 -07001161 .lbs_task = sizeof(struct aa_task_ctx),
Casey Schauflerbbd36622018-11-12 09:30:56 -08001162};
1163
James Morrisca97d932017-02-15 00:18:51 +11001164static struct security_hook_list apparmor_hooks[] __lsm_ro_after_init = {
Casey Schauflere20b0432015-05-02 15:11:36 -07001165 LSM_HOOK_INIT(ptrace_access_check, apparmor_ptrace_access_check),
1166 LSM_HOOK_INIT(ptrace_traceme, apparmor_ptrace_traceme),
1167 LSM_HOOK_INIT(capget, apparmor_capget),
1168 LSM_HOOK_INIT(capable, apparmor_capable),
John Johansenb5e95b42010-07-29 14:48:07 -07001169
John Johansen2ea3ffb2017-07-18 23:04:47 -07001170 LSM_HOOK_INIT(sb_mount, apparmor_sb_mount),
1171 LSM_HOOK_INIT(sb_umount, apparmor_sb_umount),
1172 LSM_HOOK_INIT(sb_pivotroot, apparmor_sb_pivotroot),
1173
Casey Schauflere20b0432015-05-02 15:11:36 -07001174 LSM_HOOK_INIT(path_link, apparmor_path_link),
1175 LSM_HOOK_INIT(path_unlink, apparmor_path_unlink),
1176 LSM_HOOK_INIT(path_symlink, apparmor_path_symlink),
1177 LSM_HOOK_INIT(path_mkdir, apparmor_path_mkdir),
1178 LSM_HOOK_INIT(path_rmdir, apparmor_path_rmdir),
1179 LSM_HOOK_INIT(path_mknod, apparmor_path_mknod),
1180 LSM_HOOK_INIT(path_rename, apparmor_path_rename),
1181 LSM_HOOK_INIT(path_chmod, apparmor_path_chmod),
1182 LSM_HOOK_INIT(path_chown, apparmor_path_chown),
1183 LSM_HOOK_INIT(path_truncate, apparmor_path_truncate),
1184 LSM_HOOK_INIT(inode_getattr, apparmor_inode_getattr),
John Johansenb5e95b42010-07-29 14:48:07 -07001185
Casey Schauflere20b0432015-05-02 15:11:36 -07001186 LSM_HOOK_INIT(file_open, apparmor_file_open),
John Johansen064dc942017-06-09 17:15:56 -07001187 LSM_HOOK_INIT(file_receive, apparmor_file_receive),
Casey Schauflere20b0432015-05-02 15:11:36 -07001188 LSM_HOOK_INIT(file_permission, apparmor_file_permission),
1189 LSM_HOOK_INIT(file_alloc_security, apparmor_file_alloc_security),
1190 LSM_HOOK_INIT(file_free_security, apparmor_file_free_security),
1191 LSM_HOOK_INIT(mmap_file, apparmor_mmap_file),
Casey Schauflere20b0432015-05-02 15:11:36 -07001192 LSM_HOOK_INIT(file_mprotect, apparmor_file_mprotect),
1193 LSM_HOOK_INIT(file_lock, apparmor_file_lock),
John Johansenb5e95b42010-07-29 14:48:07 -07001194
Casey Schauflere20b0432015-05-02 15:11:36 -07001195 LSM_HOOK_INIT(getprocattr, apparmor_getprocattr),
1196 LSM_HOOK_INIT(setprocattr, apparmor_setprocattr),
John Johansenb5e95b42010-07-29 14:48:07 -07001197
John Johansen56974a62017-07-18 23:18:33 -07001198 LSM_HOOK_INIT(sk_alloc_security, apparmor_sk_alloc_security),
1199 LSM_HOOK_INIT(sk_free_security, apparmor_sk_free_security),
1200 LSM_HOOK_INIT(sk_clone_security, apparmor_sk_clone_security),
1201
1202 LSM_HOOK_INIT(socket_create, apparmor_socket_create),
1203 LSM_HOOK_INIT(socket_post_create, apparmor_socket_post_create),
1204 LSM_HOOK_INIT(socket_bind, apparmor_socket_bind),
1205 LSM_HOOK_INIT(socket_connect, apparmor_socket_connect),
1206 LSM_HOOK_INIT(socket_listen, apparmor_socket_listen),
1207 LSM_HOOK_INIT(socket_accept, apparmor_socket_accept),
1208 LSM_HOOK_INIT(socket_sendmsg, apparmor_socket_sendmsg),
1209 LSM_HOOK_INIT(socket_recvmsg, apparmor_socket_recvmsg),
1210 LSM_HOOK_INIT(socket_getsockname, apparmor_socket_getsockname),
1211 LSM_HOOK_INIT(socket_getpeername, apparmor_socket_getpeername),
1212 LSM_HOOK_INIT(socket_getsockopt, apparmor_socket_getsockopt),
1213 LSM_HOOK_INIT(socket_setsockopt, apparmor_socket_setsockopt),
1214 LSM_HOOK_INIT(socket_shutdown, apparmor_socket_shutdown),
Arnd Bergmanne1af4772018-10-05 18:11:47 +02001215#ifdef CONFIG_NETWORK_SECMARK
John Johansen56974a62017-07-18 23:18:33 -07001216 LSM_HOOK_INIT(socket_sock_rcv_skb, apparmor_socket_sock_rcv_skb),
Arnd Bergmanne1af4772018-10-05 18:11:47 +02001217#endif
John Johansen56974a62017-07-18 23:18:33 -07001218 LSM_HOOK_INIT(socket_getpeersec_stream,
1219 apparmor_socket_getpeersec_stream),
1220 LSM_HOOK_INIT(socket_getpeersec_dgram,
1221 apparmor_socket_getpeersec_dgram),
1222 LSM_HOOK_INIT(sock_graft, apparmor_sock_graft),
Arnd Bergmanne1af4772018-10-05 18:11:47 +02001223#ifdef CONFIG_NETWORK_SECMARK
Matthew Garrettab9f2112018-05-24 13:27:47 -07001224 LSM_HOOK_INIT(inet_conn_request, apparmor_inet_conn_request),
Arnd Bergmanne1af4772018-10-05 18:11:47 +02001225#endif
John Johansen56974a62017-07-18 23:18:33 -07001226
Casey Schauflere20b0432015-05-02 15:11:36 -07001227 LSM_HOOK_INIT(cred_alloc_blank, apparmor_cred_alloc_blank),
1228 LSM_HOOK_INIT(cred_free, apparmor_cred_free),
1229 LSM_HOOK_INIT(cred_prepare, apparmor_cred_prepare),
1230 LSM_HOOK_INIT(cred_transfer, apparmor_cred_transfer),
John Johansenb5e95b42010-07-29 14:48:07 -07001231
Casey Schauflere20b0432015-05-02 15:11:36 -07001232 LSM_HOOK_INIT(bprm_set_creds, apparmor_bprm_set_creds),
1233 LSM_HOOK_INIT(bprm_committing_creds, apparmor_bprm_committing_creds),
1234 LSM_HOOK_INIT(bprm_committed_creds, apparmor_bprm_committed_creds),
John Johansenb5e95b42010-07-29 14:48:07 -07001235
John Johansen3b529a72017-01-20 01:59:25 -08001236 LSM_HOOK_INIT(task_free, apparmor_task_free),
1237 LSM_HOOK_INIT(task_alloc, apparmor_task_alloc),
John Johansena7ae3642017-09-11 11:29:53 -07001238 LSM_HOOK_INIT(task_getsecid, apparmor_task_getsecid),
Casey Schauflere20b0432015-05-02 15:11:36 -07001239 LSM_HOOK_INIT(task_setrlimit, apparmor_task_setrlimit),
John Johansencd1dbf72017-07-18 22:56:22 -07001240 LSM_HOOK_INIT(task_kill, apparmor_task_kill),
John Johansenc0929212017-07-31 17:36:45 -07001241
Matthew Garrette79c26d2018-04-16 11:23:58 -07001242#ifdef CONFIG_AUDIT
1243 LSM_HOOK_INIT(audit_rule_init, aa_audit_rule_init),
1244 LSM_HOOK_INIT(audit_rule_known, aa_audit_rule_known),
1245 LSM_HOOK_INIT(audit_rule_match, aa_audit_rule_match),
1246 LSM_HOOK_INIT(audit_rule_free, aa_audit_rule_free),
1247#endif
1248
John Johansenc0929212017-07-31 17:36:45 -07001249 LSM_HOOK_INIT(secid_to_secctx, apparmor_secid_to_secctx),
1250 LSM_HOOK_INIT(secctx_to_secid, apparmor_secctx_to_secid),
1251 LSM_HOOK_INIT(release_secctx, apparmor_release_secctx),
John Johansenb5e95b42010-07-29 14:48:07 -07001252};
1253
1254/*
1255 * AppArmor sysfs module parameters
1256 */
1257
Stephen Rothwell101d6c82010-08-02 12:00:43 +10001258static int param_set_aabool(const char *val, const struct kernel_param *kp);
1259static int param_get_aabool(char *buffer, const struct kernel_param *kp);
Rusty Russellb8aa09f2011-12-15 13:41:32 +10301260#define param_check_aabool param_check_bool
Luis R. Rodriguez9c278472015-05-27 11:09:38 +09301261static const struct kernel_param_ops param_ops_aabool = {
Jani Nikula6a4c2642014-08-27 06:21:23 +09301262 .flags = KERNEL_PARAM_OPS_FL_NOARG,
Stephen Rothwell101d6c82010-08-02 12:00:43 +10001263 .set = param_set_aabool,
1264 .get = param_get_aabool
1265};
John Johansenb5e95b42010-07-29 14:48:07 -07001266
Stephen Rothwell101d6c82010-08-02 12:00:43 +10001267static int param_set_aauint(const char *val, const struct kernel_param *kp);
1268static int param_get_aauint(char *buffer, const struct kernel_param *kp);
Rusty Russellb8aa09f2011-12-15 13:41:32 +10301269#define param_check_aauint param_check_uint
Luis R. Rodriguez9c278472015-05-27 11:09:38 +09301270static const struct kernel_param_ops param_ops_aauint = {
Stephen Rothwell101d6c82010-08-02 12:00:43 +10001271 .set = param_set_aauint,
1272 .get = param_get_aauint
1273};
John Johansenb5e95b42010-07-29 14:48:07 -07001274
Chris Coulson63c16c32019-01-23 19:17:09 +00001275static int param_set_aacompressionlevel(const char *val,
1276 const struct kernel_param *kp);
1277static int param_get_aacompressionlevel(char *buffer,
1278 const struct kernel_param *kp);
1279#define param_check_aacompressionlevel param_check_int
1280static const struct kernel_param_ops param_ops_aacompressionlevel = {
1281 .set = param_set_aacompressionlevel,
1282 .get = param_get_aacompressionlevel
1283};
1284
Stephen Rothwell101d6c82010-08-02 12:00:43 +10001285static int param_set_aalockpolicy(const char *val, const struct kernel_param *kp);
1286static int param_get_aalockpolicy(char *buffer, const struct kernel_param *kp);
Rusty Russellb8aa09f2011-12-15 13:41:32 +10301287#define param_check_aalockpolicy param_check_bool
Luis R. Rodriguez9c278472015-05-27 11:09:38 +09301288static const struct kernel_param_ops param_ops_aalockpolicy = {
Jani Nikula6a4c2642014-08-27 06:21:23 +09301289 .flags = KERNEL_PARAM_OPS_FL_NOARG,
Stephen Rothwell101d6c82010-08-02 12:00:43 +10001290 .set = param_set_aalockpolicy,
1291 .get = param_get_aalockpolicy
1292};
John Johansenb5e95b42010-07-29 14:48:07 -07001293
Kees Cooke4dca7b2017-10-17 19:04:42 -07001294static int param_set_audit(const char *val, const struct kernel_param *kp);
1295static int param_get_audit(char *buffer, const struct kernel_param *kp);
John Johansenb5e95b42010-07-29 14:48:07 -07001296
Kees Cooke4dca7b2017-10-17 19:04:42 -07001297static int param_set_mode(const char *val, const struct kernel_param *kp);
1298static int param_get_mode(char *buffer, const struct kernel_param *kp);
John Johansenb5e95b42010-07-29 14:48:07 -07001299
1300/* Flag values, also controllable via /sys/module/apparmor/parameters
1301 * We define special types as we want to do additional mediation.
1302 */
1303
1304/* AppArmor global enforcement switch - complain, enforce, kill */
1305enum profile_mode aa_g_profile_mode = APPARMOR_ENFORCE;
1306module_param_call(mode, param_set_mode, param_get_mode,
1307 &aa_g_profile_mode, S_IRUSR | S_IWUSR);
1308
John Johansen6059f712014-10-24 09:16:14 -07001309/* whether policy verification hashing is enabled */
Arnd Bergmann7616ac72016-07-25 10:59:07 -07001310bool aa_g_hash_policy = IS_ENABLED(CONFIG_SECURITY_APPARMOR_HASH_DEFAULT);
John Johansen3ccb76c2017-01-16 13:21:27 -08001311#ifdef CONFIG_SECURITY_APPARMOR_HASH
John Johansen6059f712014-10-24 09:16:14 -07001312module_param_named(hash_policy, aa_g_hash_policy, aabool, S_IRUSR | S_IWUSR);
Arnd Bergmann7616ac72016-07-25 10:59:07 -07001313#endif
John Johansen6059f712014-10-24 09:16:14 -07001314
Chris Coulson63c16c32019-01-23 19:17:09 +00001315/* policy loaddata compression level */
1316int aa_g_rawdata_compression_level = Z_DEFAULT_COMPRESSION;
1317module_param_named(rawdata_compression_level, aa_g_rawdata_compression_level,
1318 aacompressionlevel, 0400);
1319
John Johansenb5e95b42010-07-29 14:48:07 -07001320/* Debug mode */
Valentin Rothbergeea7a052017-04-06 06:55:20 -07001321bool aa_g_debug = IS_ENABLED(CONFIG_SECURITY_APPARMOR_DEBUG_MESSAGES);
John Johansenb5e95b42010-07-29 14:48:07 -07001322module_param_named(debug, aa_g_debug, aabool, S_IRUSR | S_IWUSR);
1323
1324/* Audit mode */
1325enum audit_mode aa_g_audit;
1326module_param_call(audit, param_set_audit, param_get_audit,
1327 &aa_g_audit, S_IRUSR | S_IWUSR);
1328
1329/* Determines if audit header is included in audited messages. This
1330 * provides more context if the audit daemon is not running
1331 */
Thomas Meyer954317f2017-10-07 16:02:21 +02001332bool aa_g_audit_header = true;
John Johansenb5e95b42010-07-29 14:48:07 -07001333module_param_named(audit_header, aa_g_audit_header, aabool,
1334 S_IRUSR | S_IWUSR);
1335
1336/* lock out loading/removal of policy
1337 * TODO: add in at boot loading of policy, which is the only way to
1338 * load policy, if lock_policy is set
1339 */
Rusty Russell90ab5ee2012-01-13 09:32:20 +10301340bool aa_g_lock_policy;
John Johansenb5e95b42010-07-29 14:48:07 -07001341module_param_named(lock_policy, aa_g_lock_policy, aalockpolicy,
1342 S_IRUSR | S_IWUSR);
1343
1344/* Syscall logging mode */
Rusty Russell90ab5ee2012-01-13 09:32:20 +10301345bool aa_g_logsyscall;
John Johansenb5e95b42010-07-29 14:48:07 -07001346module_param_named(logsyscall, aa_g_logsyscall, aabool, S_IRUSR | S_IWUSR);
1347
1348/* Maximum pathname length before accesses will start getting rejected */
1349unsigned int aa_g_path_max = 2 * PATH_MAX;
John Johansen622f6e32017-04-06 06:55:24 -07001350module_param_named(path_max, aa_g_path_max, aauint, S_IRUSR);
John Johansenb5e95b42010-07-29 14:48:07 -07001351
1352/* Determines how paranoid loading of policy is and how much verification
1353 * on the loaded policy is done.
John Johansenabbf8732017-01-16 00:42:37 -08001354 * DEPRECATED: read only as strict checking of load is always done now
1355 * that none root users (user namespaces) can load policy.
John Johansenb5e95b42010-07-29 14:48:07 -07001356 */
Thomas Meyer954317f2017-10-07 16:02:21 +02001357bool aa_g_paranoid_load = true;
John Johansenabbf8732017-01-16 00:42:37 -08001358module_param_named(paranoid_load, aa_g_paranoid_load, aabool, S_IRUGO);
John Johansenb5e95b42010-07-29 14:48:07 -07001359
Kees Cooke33c1b92019-04-08 09:07:06 -07001360static int param_get_aaintbool(char *buffer, const struct kernel_param *kp);
1361static int param_set_aaintbool(const char *val, const struct kernel_param *kp);
1362#define param_check_aaintbool param_check_int
1363static const struct kernel_param_ops param_ops_aaintbool = {
1364 .set = param_set_aaintbool,
1365 .get = param_get_aaintbool
1366};
John Johansenb5e95b42010-07-29 14:48:07 -07001367/* Boot time disable flag */
Kees Cook0102fb82018-10-01 17:08:57 -07001368static int apparmor_enabled __lsm_ro_after_init = 1;
Kees Cooke33c1b92019-04-08 09:07:06 -07001369module_param_named(enabled, apparmor_enabled, aaintbool, 0444);
John Johansenb5e95b42010-07-29 14:48:07 -07001370
1371static int __init apparmor_enabled_setup(char *str)
1372{
1373 unsigned long enabled;
Jingoo Han29707b22014-02-05 15:13:14 +09001374 int error = kstrtoul(str, 0, &enabled);
John Johansenb5e95b42010-07-29 14:48:07 -07001375 if (!error)
1376 apparmor_enabled = enabled ? 1 : 0;
1377 return 1;
1378}
1379
1380__setup("apparmor=", apparmor_enabled_setup);
1381
1382/* set global flag turning off the ability to load policy */
Stephen Rothwell101d6c82010-08-02 12:00:43 +10001383static int param_set_aalockpolicy(const char *val, const struct kernel_param *kp)
John Johansenb5e95b42010-07-29 14:48:07 -07001384{
John Johansen545de8f2017-04-06 06:55:23 -07001385 if (!apparmor_enabled)
1386 return -EINVAL;
1387 if (apparmor_initialized && !policy_admin_capable(NULL))
John Johansenb5e95b42010-07-29 14:48:07 -07001388 return -EPERM;
John Johansenb5e95b42010-07-29 14:48:07 -07001389 return param_set_bool(val, kp);
1390}
1391
Stephen Rothwell101d6c82010-08-02 12:00:43 +10001392static int param_get_aalockpolicy(char *buffer, const struct kernel_param *kp)
John Johansenb5e95b42010-07-29 14:48:07 -07001393{
John Johansenca4bd5a2017-01-16 00:43:11 -08001394 if (!apparmor_enabled)
1395 return -EINVAL;
John Johansen545de8f2017-04-06 06:55:23 -07001396 if (apparmor_initialized && !policy_view_capable(NULL))
1397 return -EPERM;
John Johansenb5e95b42010-07-29 14:48:07 -07001398 return param_get_bool(buffer, kp);
1399}
1400
Stephen Rothwell101d6c82010-08-02 12:00:43 +10001401static int param_set_aabool(const char *val, const struct kernel_param *kp)
John Johansenb5e95b42010-07-29 14:48:07 -07001402{
John Johansenca4bd5a2017-01-16 00:43:11 -08001403 if (!apparmor_enabled)
1404 return -EINVAL;
John Johansen545de8f2017-04-06 06:55:23 -07001405 if (apparmor_initialized && !policy_admin_capable(NULL))
1406 return -EPERM;
John Johansenb5e95b42010-07-29 14:48:07 -07001407 return param_set_bool(val, kp);
1408}
1409
Stephen Rothwell101d6c82010-08-02 12:00:43 +10001410static int param_get_aabool(char *buffer, const struct kernel_param *kp)
John Johansenb5e95b42010-07-29 14:48:07 -07001411{
John Johansenca4bd5a2017-01-16 00:43:11 -08001412 if (!apparmor_enabled)
1413 return -EINVAL;
John Johansen545de8f2017-04-06 06:55:23 -07001414 if (apparmor_initialized && !policy_view_capable(NULL))
1415 return -EPERM;
John Johansenb5e95b42010-07-29 14:48:07 -07001416 return param_get_bool(buffer, kp);
1417}
1418
Stephen Rothwell101d6c82010-08-02 12:00:43 +10001419static int param_set_aauint(const char *val, const struct kernel_param *kp)
John Johansenb5e95b42010-07-29 14:48:07 -07001420{
John Johansen39d84822017-03-30 05:25:23 -07001421 int error;
1422
John Johansenca4bd5a2017-01-16 00:43:11 -08001423 if (!apparmor_enabled)
1424 return -EINVAL;
John Johansen39d84822017-03-30 05:25:23 -07001425 /* file is ro but enforce 2nd line check */
1426 if (apparmor_initialized)
John Johansen545de8f2017-04-06 06:55:23 -07001427 return -EPERM;
John Johansen39d84822017-03-30 05:25:23 -07001428
1429 error = param_set_uint(val, kp);
Sebastian Andrzej Siewiordf323332019-05-03 16:12:21 +02001430 aa_g_path_max = max_t(uint32_t, aa_g_path_max, sizeof(union aa_buffer));
John Johansen39d84822017-03-30 05:25:23 -07001431 pr_info("AppArmor: buffer size set to %d bytes\n", aa_g_path_max);
1432
1433 return error;
John Johansenb5e95b42010-07-29 14:48:07 -07001434}
1435
Stephen Rothwell101d6c82010-08-02 12:00:43 +10001436static int param_get_aauint(char *buffer, const struct kernel_param *kp)
John Johansenb5e95b42010-07-29 14:48:07 -07001437{
John Johansenca4bd5a2017-01-16 00:43:11 -08001438 if (!apparmor_enabled)
1439 return -EINVAL;
John Johansen545de8f2017-04-06 06:55:23 -07001440 if (apparmor_initialized && !policy_view_capable(NULL))
1441 return -EPERM;
John Johansenb5e95b42010-07-29 14:48:07 -07001442 return param_get_uint(buffer, kp);
1443}
1444
Kees Cooke33c1b92019-04-08 09:07:06 -07001445/* Can only be set before AppArmor is initialized (i.e. on boot cmdline). */
1446static int param_set_aaintbool(const char *val, const struct kernel_param *kp)
1447{
1448 struct kernel_param kp_local;
1449 bool value;
1450 int error;
1451
1452 if (apparmor_initialized)
1453 return -EPERM;
1454
1455 /* Create local copy, with arg pointing to bool type. */
1456 value = !!*((int *)kp->arg);
1457 memcpy(&kp_local, kp, sizeof(kp_local));
1458 kp_local.arg = &value;
1459
1460 error = param_set_bool(val, &kp_local);
1461 if (!error)
1462 *((int *)kp->arg) = *((bool *)kp_local.arg);
1463 return error;
1464}
1465
1466/*
1467 * To avoid changing /sys/module/apparmor/parameters/enabled from Y/N to
1468 * 1/0, this converts the "int that is actually bool" back to bool for
1469 * display in the /sys filesystem, while keeping it "int" for the LSM
1470 * infrastructure.
1471 */
1472static int param_get_aaintbool(char *buffer, const struct kernel_param *kp)
1473{
1474 struct kernel_param kp_local;
1475 bool value;
1476
1477 /* Create local copy, with arg pointing to bool type. */
1478 value = !!*((int *)kp->arg);
1479 memcpy(&kp_local, kp, sizeof(kp_local));
1480 kp_local.arg = &value;
1481
1482 return param_get_bool(buffer, &kp_local);
1483}
1484
Chris Coulson63c16c32019-01-23 19:17:09 +00001485static int param_set_aacompressionlevel(const char *val,
1486 const struct kernel_param *kp)
1487{
1488 int error;
1489
1490 if (!apparmor_enabled)
1491 return -EINVAL;
1492 if (apparmor_initialized)
1493 return -EPERM;
1494
1495 error = param_set_int(val, kp);
1496
1497 aa_g_rawdata_compression_level = clamp(aa_g_rawdata_compression_level,
1498 Z_NO_COMPRESSION,
1499 Z_BEST_COMPRESSION);
1500 pr_info("AppArmor: policy rawdata compression level set to %u\n",
1501 aa_g_rawdata_compression_level);
1502
1503 return error;
1504}
1505
1506static int param_get_aacompressionlevel(char *buffer,
1507 const struct kernel_param *kp)
1508{
1509 if (!apparmor_enabled)
1510 return -EINVAL;
1511 if (apparmor_initialized && !policy_view_capable(NULL))
1512 return -EPERM;
1513 return param_get_int(buffer, kp);
1514}
1515
Kees Cooke4dca7b2017-10-17 19:04:42 -07001516static int param_get_audit(char *buffer, const struct kernel_param *kp)
John Johansenb5e95b42010-07-29 14:48:07 -07001517{
John Johansenb5e95b42010-07-29 14:48:07 -07001518 if (!apparmor_enabled)
1519 return -EINVAL;
John Johansen545de8f2017-04-06 06:55:23 -07001520 if (apparmor_initialized && !policy_view_capable(NULL))
1521 return -EPERM;
John Johansenb5e95b42010-07-29 14:48:07 -07001522 return sprintf(buffer, "%s", audit_mode_names[aa_g_audit]);
1523}
1524
Kees Cooke4dca7b2017-10-17 19:04:42 -07001525static int param_set_audit(const char *val, const struct kernel_param *kp)
John Johansenb5e95b42010-07-29 14:48:07 -07001526{
1527 int i;
John Johansenb5e95b42010-07-29 14:48:07 -07001528
1529 if (!apparmor_enabled)
1530 return -EINVAL;
John Johansenb5e95b42010-07-29 14:48:07 -07001531 if (!val)
1532 return -EINVAL;
John Johansen545de8f2017-04-06 06:55:23 -07001533 if (apparmor_initialized && !policy_admin_capable(NULL))
1534 return -EPERM;
John Johansenb5e95b42010-07-29 14:48:07 -07001535
Andy Shevchenko5d8779a2018-05-07 16:39:03 +03001536 i = match_string(audit_mode_names, AUDIT_MAX_INDEX, val);
1537 if (i < 0)
1538 return -EINVAL;
John Johansenb5e95b42010-07-29 14:48:07 -07001539
Andy Shevchenko5d8779a2018-05-07 16:39:03 +03001540 aa_g_audit = i;
1541 return 0;
John Johansenb5e95b42010-07-29 14:48:07 -07001542}
1543
Kees Cooke4dca7b2017-10-17 19:04:42 -07001544static int param_get_mode(char *buffer, const struct kernel_param *kp)
John Johansenb5e95b42010-07-29 14:48:07 -07001545{
John Johansenb5e95b42010-07-29 14:48:07 -07001546 if (!apparmor_enabled)
1547 return -EINVAL;
John Johansen545de8f2017-04-06 06:55:23 -07001548 if (apparmor_initialized && !policy_view_capable(NULL))
1549 return -EPERM;
John Johansenb5e95b42010-07-29 14:48:07 -07001550
John Johansen0d259f02013-07-10 21:13:43 -07001551 return sprintf(buffer, "%s", aa_profile_mode_names[aa_g_profile_mode]);
John Johansenb5e95b42010-07-29 14:48:07 -07001552}
1553
Kees Cooke4dca7b2017-10-17 19:04:42 -07001554static int param_set_mode(const char *val, const struct kernel_param *kp)
John Johansenb5e95b42010-07-29 14:48:07 -07001555{
1556 int i;
John Johansenb5e95b42010-07-29 14:48:07 -07001557
1558 if (!apparmor_enabled)
1559 return -EINVAL;
John Johansenb5e95b42010-07-29 14:48:07 -07001560 if (!val)
1561 return -EINVAL;
John Johansen545de8f2017-04-06 06:55:23 -07001562 if (apparmor_initialized && !policy_admin_capable(NULL))
1563 return -EPERM;
John Johansenb5e95b42010-07-29 14:48:07 -07001564
Andy Shevchenko5d8779a2018-05-07 16:39:03 +03001565 i = match_string(aa_profile_mode_names, APPARMOR_MODE_NAMES_MAX_INDEX,
1566 val);
1567 if (i < 0)
1568 return -EINVAL;
John Johansenb5e95b42010-07-29 14:48:07 -07001569
Andy Shevchenko5d8779a2018-05-07 16:39:03 +03001570 aa_g_profile_mode = i;
1571 return 0;
John Johansenb5e95b42010-07-29 14:48:07 -07001572}
1573
Sebastian Andrzej Siewiordf323332019-05-03 16:12:21 +02001574char *aa_get_buffer(void)
1575{
1576 union aa_buffer *aa_buf;
1577 bool try_again = true;
1578
1579retry:
1580 spin_lock(&aa_buffers_lock);
1581 if (!list_empty(&aa_global_buffers)) {
1582 aa_buf = list_first_entry(&aa_global_buffers, union aa_buffer,
1583 list);
1584 list_del(&aa_buf->list);
1585 spin_unlock(&aa_buffers_lock);
1586 return &aa_buf->buffer[0];
1587 }
1588 spin_unlock(&aa_buffers_lock);
1589
1590 aa_buf = kmalloc(aa_g_path_max, GFP_KERNEL | __GFP_RETRY_MAYFAIL |
1591 __GFP_NOWARN);
1592 if (!aa_buf) {
1593 if (try_again) {
1594 try_again = false;
1595 goto retry;
1596 }
1597 pr_warn_once("AppArmor: Failed to allocate a memory buffer.\n");
1598 return NULL;
1599 }
1600 return &aa_buf->buffer[0];
1601}
1602
1603void aa_put_buffer(char *buf)
1604{
1605 union aa_buffer *aa_buf;
1606
1607 if (!buf)
1608 return;
1609 aa_buf = container_of(buf, union aa_buffer, buffer[0]);
1610
1611 spin_lock(&aa_buffers_lock);
1612 list_add(&aa_buf->list, &aa_global_buffers);
1613 spin_unlock(&aa_buffers_lock);
1614}
1615
John Johansenb5e95b42010-07-29 14:48:07 -07001616/*
1617 * AppArmor init functions
1618 */
1619
1620/**
John Johansen55a26eb2017-01-16 00:43:00 -08001621 * set_init_ctx - set a task context and profile on the first task.
John Johansenb5e95b42010-07-29 14:48:07 -07001622 *
1623 * TODO: allow setting an alternate profile than unconfined
1624 */
John Johansen55a26eb2017-01-16 00:43:00 -08001625static int __init set_init_ctx(void)
John Johansenb5e95b42010-07-29 14:48:07 -07001626{
Bharath Vedarthambf1d2ee2019-04-23 22:23:00 +05301627 struct cred *cred = (__force struct cred *)current->real_cred;
John Johansenb5e95b42010-07-29 14:48:07 -07001628
Casey Schaufler69b5a442018-09-21 17:17:59 -07001629 set_cred_label(cred, aa_get_label(ns_unconfined(root_ns)));
John Johansenb5e95b42010-07-29 14:48:07 -07001630
1631 return 0;
1632}
1633
John Johansend4669f02017-01-16 00:43:10 -08001634static void destroy_buffers(void)
1635{
Sebastian Andrzej Siewiordf323332019-05-03 16:12:21 +02001636 union aa_buffer *aa_buf;
John Johansend4669f02017-01-16 00:43:10 -08001637
Sebastian Andrzej Siewiordf323332019-05-03 16:12:21 +02001638 spin_lock(&aa_buffers_lock);
1639 while (!list_empty(&aa_global_buffers)) {
1640 aa_buf = list_first_entry(&aa_global_buffers, union aa_buffer,
1641 list);
1642 list_del(&aa_buf->list);
1643 spin_unlock(&aa_buffers_lock);
1644 kfree(aa_buf);
1645 spin_lock(&aa_buffers_lock);
John Johansend4669f02017-01-16 00:43:10 -08001646 }
Sebastian Andrzej Siewiordf323332019-05-03 16:12:21 +02001647 spin_unlock(&aa_buffers_lock);
John Johansend4669f02017-01-16 00:43:10 -08001648}
1649
1650static int __init alloc_buffers(void)
1651{
Sebastian Andrzej Siewiordf323332019-05-03 16:12:21 +02001652 union aa_buffer *aa_buf;
1653 int i, num;
John Johansend4669f02017-01-16 00:43:10 -08001654
Sebastian Andrzej Siewiordf323332019-05-03 16:12:21 +02001655 /*
1656 * A function may require two buffers at once. Usually the buffers are
1657 * used for a short period of time and are shared. On UP kernel buffers
1658 * two should be enough, with more CPUs it is possible that more
1659 * buffers will be used simultaneously. The preallocated pool may grow.
1660 * This preallocation has also the side-effect that AppArmor will be
1661 * disabled early at boot if aa_g_path_max is extremly high.
1662 */
1663 if (num_online_cpus() > 1)
1664 num = 4;
1665 else
1666 num = 2;
John Johansend4669f02017-01-16 00:43:10 -08001667
Sebastian Andrzej Siewiordf323332019-05-03 16:12:21 +02001668 for (i = 0; i < num; i++) {
1669
1670 aa_buf = kmalloc(aa_g_path_max, GFP_KERNEL |
1671 __GFP_RETRY_MAYFAIL | __GFP_NOWARN);
1672 if (!aa_buf) {
1673 destroy_buffers();
1674 return -ENOMEM;
John Johansend4669f02017-01-16 00:43:10 -08001675 }
Sebastian Andrzej Siewiordf323332019-05-03 16:12:21 +02001676 aa_put_buffer(&aa_buf->buffer[0]);
John Johansend4669f02017-01-16 00:43:10 -08001677 }
John Johansend4669f02017-01-16 00:43:10 -08001678 return 0;
1679}
1680
Tyler Hickse3ea1ca2016-03-16 19:19:10 -05001681#ifdef CONFIG_SYSCTL
1682static int apparmor_dointvec(struct ctl_table *table, int write,
1683 void __user *buffer, size_t *lenp, loff_t *ppos)
1684{
1685 if (!policy_admin_capable(NULL))
1686 return -EPERM;
1687 if (!apparmor_enabled)
1688 return -EINVAL;
1689
1690 return proc_dointvec(table, write, buffer, lenp, ppos);
1691}
1692
1693static struct ctl_path apparmor_sysctl_path[] = {
1694 { .procname = "kernel", },
1695 { }
1696};
1697
1698static struct ctl_table apparmor_sysctl_table[] = {
1699 {
1700 .procname = "unprivileged_userns_apparmor_policy",
1701 .data = &unprivileged_userns_apparmor_policy,
1702 .maxlen = sizeof(int),
1703 .mode = 0600,
1704 .proc_handler = apparmor_dointvec,
1705 },
1706 { }
1707};
1708
1709static int __init apparmor_init_sysctl(void)
1710{
1711 return register_sysctl_paths(apparmor_sysctl_path,
1712 apparmor_sysctl_table) ? 0 : -ENOMEM;
1713}
1714#else
1715static inline int apparmor_init_sysctl(void)
1716{
1717 return 0;
1718}
1719#endif /* CONFIG_SYSCTL */
1720
Arnd Bergmanne1af4772018-10-05 18:11:47 +02001721#if defined(CONFIG_NETFILTER) && defined(CONFIG_NETWORK_SECMARK)
Matthew Garrettab9f2112018-05-24 13:27:47 -07001722static unsigned int apparmor_ip_postroute(void *priv,
1723 struct sk_buff *skb,
1724 const struct nf_hook_state *state)
1725{
1726 struct aa_sk_ctx *ctx;
1727 struct sock *sk;
1728
1729 if (!skb->secmark)
1730 return NF_ACCEPT;
1731
1732 sk = skb_to_full_sk(skb);
1733 if (sk == NULL)
1734 return NF_ACCEPT;
1735
1736 ctx = SK_CTX(sk);
1737 if (!apparmor_secmark_check(ctx->label, OP_SENDMSG, AA_MAY_SEND,
1738 skb->secmark, sk))
1739 return NF_ACCEPT;
1740
1741 return NF_DROP_ERR(-ECONNREFUSED);
1742
1743}
1744
1745static unsigned int apparmor_ipv4_postroute(void *priv,
1746 struct sk_buff *skb,
1747 const struct nf_hook_state *state)
1748{
1749 return apparmor_ip_postroute(priv, skb, state);
1750}
1751
Petr Vorela1a02062018-11-12 11:59:12 +01001752#if IS_ENABLED(CONFIG_IPV6)
Matthew Garrettab9f2112018-05-24 13:27:47 -07001753static unsigned int apparmor_ipv6_postroute(void *priv,
1754 struct sk_buff *skb,
1755 const struct nf_hook_state *state)
1756{
1757 return apparmor_ip_postroute(priv, skb, state);
1758}
Petr Vorela1a02062018-11-12 11:59:12 +01001759#endif
Matthew Garrettab9f2112018-05-24 13:27:47 -07001760
1761static const struct nf_hook_ops apparmor_nf_ops[] = {
1762 {
1763 .hook = apparmor_ipv4_postroute,
1764 .pf = NFPROTO_IPV4,
1765 .hooknum = NF_INET_POST_ROUTING,
1766 .priority = NF_IP_PRI_SELINUX_FIRST,
1767 },
1768#if IS_ENABLED(CONFIG_IPV6)
1769 {
1770 .hook = apparmor_ipv6_postroute,
1771 .pf = NFPROTO_IPV6,
1772 .hooknum = NF_INET_POST_ROUTING,
1773 .priority = NF_IP6_PRI_SELINUX_FIRST,
1774 },
1775#endif
1776};
1777
1778static int __net_init apparmor_nf_register(struct net *net)
1779{
1780 int ret;
1781
1782 ret = nf_register_net_hooks(net, apparmor_nf_ops,
1783 ARRAY_SIZE(apparmor_nf_ops));
1784 return ret;
1785}
1786
1787static void __net_exit apparmor_nf_unregister(struct net *net)
1788{
1789 nf_unregister_net_hooks(net, apparmor_nf_ops,
1790 ARRAY_SIZE(apparmor_nf_ops));
1791}
1792
1793static struct pernet_operations apparmor_net_ops = {
1794 .init = apparmor_nf_register,
1795 .exit = apparmor_nf_unregister,
1796};
1797
1798static int __init apparmor_nf_ip_init(void)
1799{
1800 int err;
1801
1802 if (!apparmor_enabled)
1803 return 0;
1804
1805 err = register_pernet_subsys(&apparmor_net_ops);
1806 if (err)
1807 panic("Apparmor: register_pernet_subsys: error %d\n", err);
1808
1809 return 0;
1810}
1811__initcall(apparmor_nf_ip_init);
Arnd Bergmanne1af4772018-10-05 18:11:47 +02001812#endif
Matthew Garrettab9f2112018-05-24 13:27:47 -07001813
John Johansenb5e95b42010-07-29 14:48:07 -07001814static int __init apparmor_init(void)
1815{
1816 int error;
1817
John Johansena4c3f892018-06-04 19:44:59 -07001818 aa_secids_init();
1819
John Johansen11c236b2017-01-16 00:42:42 -08001820 error = aa_setup_dfa_engine();
1821 if (error) {
1822 AA_ERROR("Unable to setup dfa engine\n");
1823 goto alloc_out;
1824 }
1825
John Johansenb5e95b42010-07-29 14:48:07 -07001826 error = aa_alloc_root_ns();
1827 if (error) {
1828 AA_ERROR("Unable to allocate default profile namespace\n");
1829 goto alloc_out;
1830 }
1831
Tyler Hickse3ea1ca2016-03-16 19:19:10 -05001832 error = apparmor_init_sysctl();
1833 if (error) {
1834 AA_ERROR("Unable to register sysctls\n");
1835 goto alloc_out;
1836
1837 }
1838
John Johansend4669f02017-01-16 00:43:10 -08001839 error = alloc_buffers();
1840 if (error) {
1841 AA_ERROR("Unable to allocate work buffers\n");
Sebastian Andrzej Siewiordf323332019-05-03 16:12:21 +02001842 goto alloc_out;
John Johansend4669f02017-01-16 00:43:10 -08001843 }
1844
John Johansen55a26eb2017-01-16 00:43:00 -08001845 error = set_init_ctx();
John Johansenb5e95b42010-07-29 14:48:07 -07001846 if (error) {
1847 AA_ERROR("Failed to set context on init task\n");
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07001848 aa_free_root_ns();
John Johansend4669f02017-01-16 00:43:10 -08001849 goto buffers_out;
John Johansenb5e95b42010-07-29 14:48:07 -07001850 }
Casey Schauflerd69dece52017-01-18 17:09:05 -08001851 security_add_hooks(apparmor_hooks, ARRAY_SIZE(apparmor_hooks),
1852 "apparmor");
John Johansenb5e95b42010-07-29 14:48:07 -07001853
1854 /* Report that AppArmor successfully initialized */
1855 apparmor_initialized = 1;
1856 if (aa_g_profile_mode == APPARMOR_COMPLAIN)
1857 aa_info_message("AppArmor initialized: complain mode enabled");
1858 else if (aa_g_profile_mode == APPARMOR_KILL)
1859 aa_info_message("AppArmor initialized: kill mode enabled");
1860 else
1861 aa_info_message("AppArmor initialized");
1862
1863 return error;
1864
John Johansend4669f02017-01-16 00:43:10 -08001865buffers_out:
1866 destroy_buffers();
John Johansenb5e95b42010-07-29 14:48:07 -07001867alloc_out:
1868 aa_destroy_aafs();
John Johansen11c236b2017-01-16 00:42:42 -08001869 aa_teardown_dfa_engine();
John Johansenb5e95b42010-07-29 14:48:07 -07001870
Thomas Meyer954317f2017-10-07 16:02:21 +02001871 apparmor_enabled = false;
John Johansenb5e95b42010-07-29 14:48:07 -07001872 return error;
John Johansenb5e95b42010-07-29 14:48:07 -07001873}
1874
Kees Cook3d6e5f62018-10-10 17:18:23 -07001875DEFINE_LSM(apparmor) = {
Kees Cook07aed2f2018-10-10 17:18:24 -07001876 .name = "apparmor",
Kees Cook14bd99c2018-09-19 19:57:06 -07001877 .flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
Kees Cookc5459b82018-09-13 22:28:48 -07001878 .enabled = &apparmor_enabled,
Casey Schauflerbbd36622018-11-12 09:30:56 -08001879 .blobs = &apparmor_blob_sizes,
Kees Cook3d6e5f62018-10-10 17:18:23 -07001880 .init = apparmor_init,
1881};