]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - security/apparmor/mount.c
apparmor: push path lookup into mediation loop
[mirror_ubuntu-zesty-kernel.git] / security / apparmor / mount.c
CommitLineData
80594fc2
JJ
1/*
2 * AppArmor security module
3 *
4 * This file contains AppArmor mediation of files
5 *
6 * Copyright (C) 1998-2008 Novell/SUSE
7 * Copyright 2009-2012 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
15#include <linux/fs.h>
16#include <linux/mount.h>
17#include <linux/namei.h>
18
19#include "include/apparmor.h"
20#include "include/audit.h"
21#include "include/context.h"
22#include "include/domain.h"
23#include "include/file.h"
24#include "include/match.h"
25#include "include/mount.h"
26#include "include/path.h"
27#include "include/policy.h"
28
29
30static void audit_mnt_flags(struct audit_buffer *ab, unsigned long flags)
31{
32 if (flags & MS_RDONLY)
33 audit_log_format(ab, "ro");
34 else
35 audit_log_format(ab, "rw");
36 if (flags & MS_NOSUID)
37 audit_log_format(ab, ", nosuid");
38 if (flags & MS_NODEV)
39 audit_log_format(ab, ", nodev");
40 if (flags & MS_NOEXEC)
41 audit_log_format(ab, ", noexec");
42 if (flags & MS_SYNCHRONOUS)
43 audit_log_format(ab, ", sync");
44 if (flags & MS_REMOUNT)
45 audit_log_format(ab, ", remount");
46 if (flags & MS_MANDLOCK)
47 audit_log_format(ab, ", mand");
48 if (flags & MS_DIRSYNC)
49 audit_log_format(ab, ", dirsync");
50 if (flags & MS_NOATIME)
51 audit_log_format(ab, ", noatime");
52 if (flags & MS_NODIRATIME)
53 audit_log_format(ab, ", nodiratime");
54 if (flags & MS_BIND)
55 audit_log_format(ab, flags & MS_REC ? ", rbind" : ", bind");
56 if (flags & MS_MOVE)
57 audit_log_format(ab, ", move");
58 if (flags & MS_SILENT)
59 audit_log_format(ab, ", silent");
60 if (flags & MS_POSIXACL)
61 audit_log_format(ab, ", acl");
62 if (flags & MS_UNBINDABLE)
63 audit_log_format(ab, flags & MS_REC ? ", runbindable" :
64 ", unbindable");
65 if (flags & MS_PRIVATE)
66 audit_log_format(ab, flags & MS_REC ? ", rprivate" :
67 ", private");
68 if (flags & MS_SLAVE)
69 audit_log_format(ab, flags & MS_REC ? ", rslave" :
70 ", slave");
71 if (flags & MS_SHARED)
72 audit_log_format(ab, flags & MS_REC ? ", rshared" :
73 ", shared");
74 if (flags & MS_RELATIME)
75 audit_log_format(ab, ", relatime");
76 if (flags & MS_I_VERSION)
77 audit_log_format(ab, ", iversion");
78 if (flags & MS_STRICTATIME)
79 audit_log_format(ab, ", strictatime");
80 if (flags & MS_NOUSER)
81 audit_log_format(ab, ", nouser");
82}
83
84/**
85 * audit_cb - call back for mount specific audit fields
86 * @ab: audit_buffer (NOT NULL)
87 * @va: audit struct to audit values of (NOT NULL)
88 */
89static void audit_cb(struct audit_buffer *ab, void *va)
90{
91 struct common_audit_data *sa = va;
92
93 if (aad(sa)->mnt.type) {
94 audit_log_format(ab, " fstype=");
95 audit_log_untrustedstring(ab, aad(sa)->mnt.type);
96 }
97 if (aad(sa)->mnt.src_name) {
98 audit_log_format(ab, " srcname=");
99 audit_log_untrustedstring(ab, aad(sa)->mnt.src_name);
100 }
101 if (aad(sa)->mnt.trans) {
102 audit_log_format(ab, " trans=");
103 audit_log_untrustedstring(ab, aad(sa)->mnt.trans);
104 }
105 if (aad(sa)->mnt.flags) {
106 audit_log_format(ab, " flags=\"");
107 audit_mnt_flags(ab, aad(sa)->mnt.flags);
108 audit_log_format(ab, "\"");
109 }
110 if (aad(sa)->mnt.data) {
111 audit_log_format(ab, " options=");
112 audit_log_untrustedstring(ab, aad(sa)->mnt.data);
113 }
114}
115
116/**
117 * audit_mount - handle the auditing of mount operations
118 * @profile: the profile being enforced (NOT NULL)
119 * @op: operation being mediated (NOT NULL)
120 * @name: name of object being mediated (MAYBE NULL)
121 * @src_name: src_name of object being mediated (MAYBE_NULL)
122 * @type: type of filesystem (MAYBE_NULL)
123 * @trans: name of trans (MAYBE NULL)
124 * @flags: filesystem idependent mount flags
125 * @data: filesystem mount flags
126 * @request: permissions requested
127 * @perms: the permissions computed for the request (NOT NULL)
128 * @info: extra information message (MAYBE NULL)
129 * @error: 0 if operation allowed else failure error code
130 *
131 * Returns: %0 or error on failure
132 */
133static int audit_mount(struct aa_profile *profile, const char *op, const char *name,
134 const char *src_name, const char *type,
135 const char *trans, unsigned long flags,
136 const void *data, u32 request, struct aa_perms *perms,
137 const char *info, int error)
138{
139 int audit_type = AUDIT_APPARMOR_AUTO;
140 DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, op);
141
142 if (likely(!error)) {
143 u32 mask = perms->audit;
144
145 if (unlikely(AUDIT_MODE(profile) == AUDIT_ALL))
146 mask = 0xffff;
147
148 /* mask off perms that are not being force audited */
149 request &= mask;
150
151 if (likely(!request))
152 return 0;
153 audit_type = AUDIT_APPARMOR_AUDIT;
154 } else {
155 /* only report permissions that were denied */
156 request = request & ~perms->allow;
157
158 if (request & perms->kill)
159 audit_type = AUDIT_APPARMOR_KILL;
160
161 /* quiet known rejects, assumes quiet and kill do not overlap */
162 if ((request & perms->quiet) &&
163 AUDIT_MODE(profile) != AUDIT_NOQUIET &&
164 AUDIT_MODE(profile) != AUDIT_ALL)
165 request &= ~perms->quiet;
166
167 if (!request)
168 return error;
169 }
170
171 aad(&sa)->name = name;
172 aad(&sa)->mnt.src_name = src_name;
173 aad(&sa)->mnt.type = type;
174 aad(&sa)->mnt.trans = trans;
175 aad(&sa)->mnt.flags = flags;
176 if (data && (perms->audit & AA_AUDIT_DATA))
177 aad(&sa)->mnt.data = data;
178 aad(&sa)->info = info;
179 aad(&sa)->error = error;
180
181 return aa_audit(audit_type, profile, &sa, audit_cb);
182}
183
184/**
185 * match_mnt_flags - Do an ordered match on mount flags
186 * @dfa: dfa to match against
187 * @state: state to start in
188 * @flags: mount flags to match against
189 *
190 * Mount flags are encoded as an ordered match. This is done instead of
191 * checking against a simple bitmask, to allow for logical operations
192 * on the flags.
193 *
194 * Returns: next state after flags match
195 */
196static unsigned int match_mnt_flags(struct aa_dfa *dfa, unsigned int state,
197 unsigned long flags)
198{
199 unsigned int i;
200
201 for (i = 0; i <= 31 ; ++i) {
202 if ((1 << i) & flags)
203 state = aa_dfa_next(dfa, state, i + 1);
204 }
205
206 return state;
207}
208
209/**
210 * compute_mnt_perms - compute mount permission associated with @state
211 * @dfa: dfa to match against (NOT NULL)
212 * @state: state match finished in
213 *
214 * Returns: mount permissions
215 */
216static struct aa_perms compute_mnt_perms(struct aa_dfa *dfa,
217 unsigned int state)
218{
219 struct aa_perms perms;
220
221 perms.kill = 0;
222 perms.allow = dfa_user_allow(dfa, state);
223 perms.audit = dfa_user_audit(dfa, state);
224 perms.quiet = dfa_user_quiet(dfa, state);
225 perms.xindex = dfa_user_xindex(dfa, state);
226
227 return perms;
228}
229
230static const char *mnt_info_table[] = {
231 "match succeeded",
232 "failed mntpnt match",
233 "failed srcname match",
234 "failed type match",
235 "failed flags match",
236 "failed data match"
237};
238
239/*
240 * Returns 0 on success else element that match failed in, this is the
241 * index into the mnt_info_table above
242 */
243static int do_match_mnt(struct aa_dfa *dfa, unsigned int start,
244 const char *mntpnt, const char *devname,
245 const char *type, unsigned long flags,
246 void *data, bool binary, struct aa_perms *perms)
247{
248 unsigned int state;
249
250 AA_BUG(!dfa);
251 AA_BUG(!perms);
252
253 state = aa_dfa_match(dfa, start, mntpnt);
254 state = aa_dfa_null_transition(dfa, state);
255 if (!state)
256 return 1;
257
258 if (devname)
259 state = aa_dfa_match(dfa, state, devname);
260 state = aa_dfa_null_transition(dfa, state);
261 if (!state)
262 return 2;
263
264 if (type)
265 state = aa_dfa_match(dfa, state, type);
266 state = aa_dfa_null_transition(dfa, state);
267 if (!state)
268 return 3;
269
270 state = match_mnt_flags(dfa, state, flags);
271 if (!state)
272 return 4;
273 *perms = compute_mnt_perms(dfa, state);
274 if (perms->allow & AA_MAY_MOUNT)
275 return 0;
276
277 /* only match data if not binary and the DFA flags data is expected */
278 if (data && !binary && (perms->allow & AA_MNT_CONT_MATCH)) {
279 state = aa_dfa_null_transition(dfa, state);
280 if (!state)
281 return 4;
282
283 state = aa_dfa_match(dfa, state, data);
284 if (!state)
285 return 5;
286 *perms = compute_mnt_perms(dfa, state);
287 if (perms->allow & AA_MAY_MOUNT)
288 return 0;
289 }
290
291 /* failed at end of flags match */
292 return 4;
293}
294
89faea0e
JJ
295
296static int path_flags(struct aa_profile *profile, const struct path *path)
297{
298 AA_BUG(!profile);
299 AA_BUG(!path);
300
301 return profile->path_flags |
302 (S_ISDIR(path->dentry->d_inode->i_mode) ? PATH_IS_DIR : 0);
303}
304
80594fc2 305/**
89faea0e 306 * match_mnt_path_str - handle path matching for mount
80594fc2 307 * @profile: the confining profile
89faea0e
JJ
308 * @mntpath: for the mntpnt (NOT NULL)
309 * @buffer: buffer to be used to lookup mntpath
310 * @devnme: string for the devname/src_name (MAY BE NULL OR ERRPTR)
80594fc2
JJ
311 * @type: string for the dev type (MAYBE NULL)
312 * @flags: mount flags to match
313 * @data: fs mount data (MAYBE NULL)
314 * @binary: whether @data is binary
89faea0e 315 * @devinfo: error str if (IS_ERR(@devname))
80594fc2
JJ
316 *
317 * Returns: 0 on success else error
318 */
89faea0e
JJ
319static int match_mnt_path_str(struct aa_profile *profile, const struct path *mntpath,
320 char *buffer, const char *devname,
321 const char *type, unsigned long flags,
322 void *data, bool binary, const char *devinfo)
80594fc2
JJ
323{
324 struct aa_perms perms = { };
89faea0e
JJ
325 const char *mntpnt = NULL, *info = NULL;
326 int pos, error;
80594fc2
JJ
327
328 AA_BUG(!profile);
89faea0e
JJ
329 AA_BUG(!mntpath);
330 AA_BUG(!buffer);
331
332 error = aa_path_name(mntpath, path_flags(profile, mntpath), buffer,
333 &mntpnt, &info, profile->disconnected);
334 if (error)
335 goto audit;
336 if (IS_ERR(devname)) {
337 error = PTR_ERR(devname);
338 info = devinfo;
339 goto audit;
340 }
80594fc2 341
89faea0e 342 error = -EACCES;
80594fc2
JJ
343 pos = do_match_mnt(profile->policy.dfa,
344 profile->policy.start[AA_CLASS_MOUNT],
345 mntpnt, devname, type, flags, data, binary, &perms);
346 if (pos) {
347 info = mnt_info_table[pos];
348 goto audit;
349 }
350 error = 0;
351
352audit:
353 return audit_mount(profile, OP_MOUNT, mntpnt, devname, type, NULL,
354 flags, data, AA_MAY_MOUNT, &perms, info, error);
355}
356
89faea0e
JJ
357/**
358 * match_mnt - handle path matching for mount
359 * @profile: the confining profile
360 * @mntpath: for the mntpnt (NOT NULL)
361 * @buffer: buffer to be used to lookup mntpath
362 * @devpath: path devname/src_name (MAYBE NULL)
363 * @devbuffer: buffer to be used to lookup devname/src_name
364 * @type: string for the dev type (MAYBE NULL)
365 * @flags: mount flags to match
366 * @data: fs mount data (MAYBE NULL)
367 * @binary: whether @data is binary
368 *
369 * Returns: 0 on success else error
370 */
371static int match_mnt(struct aa_profile *profile, const struct path *path,
372 char *buffer, struct path *devpath, char *devbuffer,
373 const char *type, unsigned long flags, void *data,
374 bool binary)
80594fc2 375{
89faea0e
JJ
376 const char *devname = NULL, *info = NULL;
377 int error = -EACCES;
378
80594fc2 379 AA_BUG(!profile);
89faea0e 380 AA_BUG(devpath && !devbuffer);
80594fc2 381
89faea0e
JJ
382 if (devpath) {
383 error = aa_path_name(devpath, path_flags(profile, devpath),
384 devbuffer, &devname, &info,
385 profile->disconnected);
386 if (error)
387 devname = ERR_PTR(error);
388 }
389
390 return match_mnt_path_str(profile, path, buffer, devname, type, flags,
391 data, binary, info);
80594fc2
JJ
392}
393
394int aa_remount(struct aa_label *label, const struct path *path,
395 unsigned long flags, void *data)
396{
397 struct aa_profile *profile;
80594fc2
JJ
398 char *buffer = NULL;
399 bool binary;
400 int error;
401
402 AA_BUG(!label);
403 AA_BUG(!path);
404
405 binary = path->dentry->d_sb->s_type->fs_flags & FS_BINARY_MOUNTDATA;
406
407 get_buffers(buffer);
80594fc2 408 error = fn_for_each_confined(label, profile,
89faea0e
JJ
409 match_mnt(profile, path, buffer, NULL, NULL, NULL,
410 flags, data, binary));
80594fc2
JJ
411 put_buffers(buffer);
412
413 return error;
414}
415
416int aa_bind_mount(struct aa_label *label, const struct path *path,
417 const char *dev_name, unsigned long flags)
418{
419 struct aa_profile *profile;
420 char *buffer = NULL, *old_buffer = NULL;
80594fc2
JJ
421 struct path old_path;
422 int error;
423
424 AA_BUG(!label);
425 AA_BUG(!path);
426
427 if (!dev_name || !*dev_name)
428 return -EINVAL;
429
430 flags &= MS_REC | MS_BIND;
431
432 error = kern_path(dev_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
433 if (error)
434 return error;
435
436 get_buffers(buffer, old_buffer);
80594fc2 437 error = fn_for_each_confined(label, profile,
89faea0e
JJ
438 match_mnt(profile, path, buffer, &old_path, old_buffer,
439 NULL, flags, NULL, false));
80594fc2 440 put_buffers(buffer, old_buffer);
89faea0e 441 path_put(&old_path);
80594fc2
JJ
442
443 return error;
80594fc2
JJ
444}
445
446int aa_mount_change_type(struct aa_label *label, const struct path *path,
447 unsigned long flags)
448{
449 struct aa_profile *profile;
450 char *buffer = NULL;
80594fc2
JJ
451 int error;
452
453 AA_BUG(!label);
454 AA_BUG(!path);
455
456 /* These are the flags allowed by do_change_type() */
457 flags &= (MS_REC | MS_SILENT | MS_SHARED | MS_PRIVATE | MS_SLAVE |
458 MS_UNBINDABLE);
459
460 get_buffers(buffer);
80594fc2 461 error = fn_for_each_confined(label, profile,
89faea0e
JJ
462 match_mnt(profile, path, buffer, NULL, NULL, NULL,
463 flags, NULL, false));
80594fc2
JJ
464 put_buffers(buffer);
465
466 return error;
467}
468
469int aa_move_mount(struct aa_label *label, const struct path *path,
470 const char *orig_name)
471{
472 struct aa_profile *profile;
473 char *buffer = NULL, *old_buffer = NULL;
80594fc2
JJ
474 struct path old_path;
475 int error;
476
477 AA_BUG(!label);
478 AA_BUG(!path);
479
480 if (!orig_name || !*orig_name)
481 return -EINVAL;
482
483 error = kern_path(orig_name, LOOKUP_FOLLOW, &old_path);
484 if (error)
485 return error;
486
487 get_buffers(buffer, old_buffer);
80594fc2 488 error = fn_for_each_confined(label, profile,
89faea0e
JJ
489 match_mnt(profile, path, buffer, &old_path, old_buffer,
490 NULL, MS_MOVE, NULL, false));
80594fc2 491 put_buffers(buffer, old_buffer);
89faea0e 492 path_put(&old_path);
80594fc2
JJ
493
494 return error;
80594fc2
JJ
495}
496
89faea0e 497int aa_new_mount(struct aa_label *label, const char *dev_name,
80594fc2
JJ
498 const struct path *path, const char *type, unsigned long flags,
499 void *data)
500{
501 struct aa_profile *profile;
502 char *buffer = NULL, *dev_buffer = NULL;
80594fc2
JJ
503 bool binary = true;
504 int error;
505 int requires_dev = 0;
89faea0e 506 struct path tmp_path, *dev_path = NULL;
80594fc2
JJ
507
508 AA_BUG(!label);
509 AA_BUG(!path);
510
80594fc2
JJ
511 if (type) {
512 struct file_system_type *fstype;
513 fstype = get_fs_type(type);
514 if (!fstype)
515 return -ENODEV;
516 binary = fstype->fs_flags & FS_BINARY_MOUNTDATA;
517 requires_dev = fstype->fs_flags & FS_REQUIRES_DEV;
518 put_filesystem(fstype);
519
520 if (requires_dev) {
521 if (!dev_name || !*dev_name)
522 return -ENOENT;
523
89faea0e 524 error = kern_path(dev_name, LOOKUP_FOLLOW, &tmp_path);
80594fc2
JJ
525 if (error)
526 return error;
89faea0e 527 dev_path = &tmp_path;
80594fc2
JJ
528 }
529 }
530
531 get_buffers(buffer, dev_buffer);
89faea0e
JJ
532 if (dev_path) {
533 error = fn_for_each_confined(label, profile,
534 match_mnt(profile, path, buffer, dev_path, dev_buffer,
535 type, flags, data, binary));
536 } else {
537 error = fn_for_each_confined(label, profile,
538 match_mnt_path_str(profile, path, buffer, dev_name,
539 type, flags, data, binary, NULL));
80594fc2 540 }
80594fc2 541 put_buffers(buffer, dev_buffer);
89faea0e
JJ
542 if (dev_path)
543 path_put(dev_path);
80594fc2
JJ
544
545 return error;
80594fc2
JJ
546}
547
89faea0e
JJ
548static int profile_umount(struct aa_profile *profile, struct path *path,
549 char *buffer)
80594fc2
JJ
550{
551 struct aa_perms perms = { };
89faea0e 552 const char *name = NULL, *info = NULL;
80594fc2 553 unsigned int state;
89faea0e 554 int error;
80594fc2
JJ
555
556 AA_BUG(!profile);
89faea0e
JJ
557 AA_BUG(!path);
558
559 error = aa_path_name(path, path_flags(profile, path), buffer, &name,
560 &info, profile->disconnected);
561 if (error)
562 goto audit;
80594fc2
JJ
563
564 state = aa_dfa_match(profile->policy.dfa,
565 profile->policy.start[AA_CLASS_MOUNT],
566 name);
567 perms = compute_mnt_perms(profile->policy.dfa, state);
568 if (AA_MAY_UMOUNT & ~perms.allow)
89faea0e 569 error = -EACCES;
80594fc2 570
89faea0e 571audit:
80594fc2 572 return audit_mount(profile, OP_UMOUNT, name, NULL, NULL, NULL, 0, NULL,
89faea0e 573 AA_MAY_UMOUNT, &perms, info, error);
80594fc2
JJ
574}
575
576int aa_umount(struct aa_label *label, struct vfsmount *mnt, int flags)
577{
578 struct aa_profile *profile;
579 char *buffer = NULL;
80594fc2
JJ
580 int error;
581 struct path path = { mnt, mnt->mnt_root };
582
583 AA_BUG(!label);
584 AA_BUG(!mnt);
585
586 get_buffers(buffer);
80594fc2 587 error = fn_for_each_confined(label, profile,
89faea0e 588 profile_umount(profile, &path, buffer));
80594fc2
JJ
589 put_buffers(buffer);
590
591 return error;
592}
593
8871ecee
JJ
594/* helper fn for transition on pivotroot
595 *
596 * Returns: label for transition or ERR_PTR. Does not return NULL
597 */
598static struct aa_label *build_pivotroot(struct aa_profile *profile,
89faea0e
JJ
599 struct path *new_path,
600 char *new_buffer,
601 struct path *old_path,
602 char *old_buffer)
80594fc2 603{
89faea0e 604 const char *old_name, *new_name = NULL, *info = NULL;
80594fc2 605 const char *trans_name = NULL;
89faea0e 606 struct aa_label *target = NULL;
80594fc2 607 struct aa_perms perms = { };
80594fc2 608 unsigned int state;
89faea0e 609 int error;
80594fc2
JJ
610
611 AA_BUG(!profile);
89faea0e
JJ
612 AA_BUG(!new_path);
613 AA_BUG(!old_path);
614
615 error = aa_path_name(old_path, path_flags(profile, old_path),
616 old_buffer, &old_name, &info,
617 profile->disconnected);
618 if (error)
619 goto audit;
620 error = aa_path_name(new_path, path_flags(profile, new_path),
621 new_buffer, &new_name, &info,
622 profile->disconnected);
623 if (error)
624 goto audit;
80594fc2 625
89faea0e 626 error = -EACCES;
80594fc2
JJ
627 state = aa_dfa_match(profile->policy.dfa,
628 profile->policy.start[AA_CLASS_MOUNT],
629 new_name);
630 state = aa_dfa_null_transition(profile->policy.dfa, state);
631 state = aa_dfa_match(profile->policy.dfa, state, old_name);
632 perms = compute_mnt_perms(profile->policy.dfa, state);
633
634 if (AA_MAY_PIVOTROOT & perms.allow) {
8871ecee 635 error = 0;
80594fc2
JJ
636 if ((perms.xindex & AA_X_TYPE_MASK) == AA_X_TABLE) {
637 target = x_table_lookup(profile, perms.xindex,
638 &trans_name);
639 if (!target)
640 error = -ENOENT;
8871ecee 641 }
80594fc2
JJ
642 }
643
89faea0e 644audit:
80594fc2
JJ
645 error = audit_mount(profile, OP_PIVOTROOT, new_name, old_name,
646 NULL, trans_name, 0, NULL, AA_MAY_PIVOTROOT,
647 &perms, info, error);
8871ecee 648 if (error) {
80594fc2 649 aa_put_label(target);
8871ecee
JJ
650 return ERR_PTR(error);
651 } else if (target)
652 return target;
80594fc2 653
8871ecee 654 return aa_get_label(&profile->label);
80594fc2
JJ
655}
656
657int aa_pivotroot(struct aa_label *label, const struct path *old_path,
658 const struct path *new_path)
659{
660 struct aa_profile *profile;
661 struct aa_label *target = NULL;
89faea0e 662 char *old_buffer = NULL, *new_buffer = NULL, *info = NULL;
80594fc2
JJ
663 int error;
664
665 AA_BUG(!label);
666 AA_BUG(!old_path);
667 AA_BUG(!new_path);
668
669 get_buffers(old_buffer, new_buffer);
8871ecee 670 target = fn_label_build(label, profile, GFP_ATOMIC,
89faea0e
JJ
671 build_pivotroot(profile, new_path, new_buffer,
672 old_path, old_buffer));
8871ecee
JJ
673 if (!target) {
674 info = "label build failed";
675 error = -ENOMEM;
676 goto fail;
677 } else if (!IS_ERR(target)) {
678 error = aa_replace_current_label(target);
679 if (error) {
680 /* TODO: audit target */
681 aa_put_label(target);
682 goto out;
683 }
684 } else
685 /* already audited error */
686 error = PTR_ERR(target);
80594fc2
JJ
687out:
688 put_buffers(old_buffer, new_buffer);
689
80594fc2
JJ
690 return error;
691
8871ecee 692fail:
89faea0e 693 /* TODO: add back in auditing of new_name and old_name */
80594fc2 694 error = fn_for_each(label, profile,
89faea0e
JJ
695 audit_mount(profile, OP_PIVOTROOT, NULL /*new_name */,
696 NULL /* old_name */,
80594fc2
JJ
697 NULL, NULL,
698 0, NULL, AA_MAY_PIVOTROOT, &nullperms, info,
699 error));
700 goto out;
701}