|
38 | 38 | #include "include/policy.h" |
39 | 39 | #include "include/policy_ns.h" |
40 | 40 | #include "include/procattr.h" |
| 41 | +#include "include/mount.h" |
41 | 42 |
|
42 | 43 | /* Flag indicating whether initialization completed */ |
43 | 44 | int apparmor_initialized; |
@@ -511,6 +512,65 @@ static int apparmor_file_mprotect(struct vm_area_struct *vma, |
511 | 512 | !(vma->vm_flags & VM_SHARED) ? MAP_PRIVATE : 0); |
512 | 513 | } |
513 | 514 |
|
| 515 | +static int apparmor_sb_mount(const char *dev_name, const struct path *path, |
| 516 | + const char *type, unsigned long flags, void *data) |
| 517 | +{ |
| 518 | + struct aa_label *label; |
| 519 | + int error = 0; |
| 520 | + |
| 521 | + /* Discard magic */ |
| 522 | + if ((flags & MS_MGC_MSK) == MS_MGC_VAL) |
| 523 | + flags &= ~MS_MGC_MSK; |
| 524 | + |
| 525 | + flags &= ~AA_MS_IGNORE_MASK; |
| 526 | + |
| 527 | + label = __begin_current_label_crit_section(); |
| 528 | + if (!unconfined(label)) { |
| 529 | + if (flags & MS_REMOUNT) |
| 530 | + error = aa_remount(label, path, flags, data); |
| 531 | + else if (flags & MS_BIND) |
| 532 | + error = aa_bind_mount(label, path, dev_name, flags); |
| 533 | + else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | |
| 534 | + MS_UNBINDABLE)) |
| 535 | + error = aa_mount_change_type(label, path, flags); |
| 536 | + else if (flags & MS_MOVE) |
| 537 | + error = aa_move_mount(label, path, dev_name); |
| 538 | + else |
| 539 | + error = aa_new_mount(label, dev_name, path, type, |
| 540 | + flags, data); |
| 541 | + } |
| 542 | + __end_current_label_crit_section(label); |
| 543 | + |
| 544 | + return error; |
| 545 | +} |
| 546 | + |
| 547 | +static int apparmor_sb_umount(struct vfsmount *mnt, int flags) |
| 548 | +{ |
| 549 | + struct aa_label *label; |
| 550 | + int error = 0; |
| 551 | + |
| 552 | + label = __begin_current_label_crit_section(); |
| 553 | + if (!unconfined(label)) |
| 554 | + error = aa_umount(label, mnt, flags); |
| 555 | + __end_current_label_crit_section(label); |
| 556 | + |
| 557 | + return error; |
| 558 | +} |
| 559 | + |
| 560 | +static int apparmor_sb_pivotroot(const struct path *old_path, |
| 561 | + const struct path *new_path) |
| 562 | +{ |
| 563 | + struct aa_label *label; |
| 564 | + int error = 0; |
| 565 | + |
| 566 | + label = aa_get_current_label(); |
| 567 | + if (!unconfined(label)) |
| 568 | + error = aa_pivotroot(label, old_path, new_path); |
| 569 | + aa_put_label(label); |
| 570 | + |
| 571 | + return error; |
| 572 | +} |
| 573 | + |
514 | 574 | static int apparmor_getprocattr(struct task_struct *task, char *name, |
515 | 575 | char **value) |
516 | 576 | { |
@@ -682,6 +742,10 @@ static struct security_hook_list apparmor_hooks[] __lsm_ro_after_init = { |
682 | 742 | LSM_HOOK_INIT(capget, apparmor_capget), |
683 | 743 | LSM_HOOK_INIT(capable, apparmor_capable), |
684 | 744 |
|
| 745 | + LSM_HOOK_INIT(sb_mount, apparmor_sb_mount), |
| 746 | + LSM_HOOK_INIT(sb_umount, apparmor_sb_umount), |
| 747 | + LSM_HOOK_INIT(sb_pivotroot, apparmor_sb_pivotroot), |
| 748 | + |
685 | 749 | LSM_HOOK_INIT(path_link, apparmor_path_link), |
686 | 750 | LSM_HOOK_INIT(path_unlink, apparmor_path_unlink), |
687 | 751 | LSM_HOOK_INIT(path_symlink, apparmor_path_symlink), |
|
0 commit comments